<commit_before><?php

namespace geotime\Test;

use geotime\Util;
use PHPUnit_Framework_TestCase;


class UtilTest extends \PHPUnit_Framework_TestCase {

    static $fixtures_dir_svg = "test/geotime/_fixtures/svg/";
    static $fixtures_dir_thumbnails = "test/geotime/_fixtures/thumbnails/";

    static $wikimediaLogoLocation = "http://upload.wikimedia.org/wikipedia/commons/8/81/Wikimedia-logo.svg";
    static $wikimediaLogoFileName = "logo.svg";

    static $simpleSvgFileName = "simple.svg";

    static function setUpBeforeClass() {
        Util::$log->info(__CLASS__." tests started");

        Util::$cache_dir_svg = "test/geotime/cache/svg/";
        Util::$cache_dir_thumbnails = "test/geotime/cache/thumbnails/";
        Util::$cache_dir_json = "test/geotime/cache/json/";

        self::cleanGeneratedFiles();
    }

    static function tearDownAfterClass()
    {
        self::cleanGeneratedFiles();
        Util::$log->info(__CLASS__ . " tests ended");
    }

    static function cleanGeneratedFiles() {
        @unlink(Util::$cache_dir_svg . self::$wikimediaLogoFileName);
        @unlink(Util::$cache_dir_thumbnails . self::$wikimediaLogoFileName . ".png");
        @unlink(Util::$cache_dir_svg . self::$simpleSvgFileName);
        @unlink(Util::$cache_dir_thumbnails . self::$simpleSvgFileName . ".png");
    }

    public function testFetchSvg() {
        $success = Util::fetchSvgWithThumbnail(self::$wikimediaLogoLocation, self::$wikimediaLogoFileName);
        $this->assertTrue($success);
    }

    public function testFetchSvgNullUrl() {
        $sucesss = Util::fetchSvgWithThumbnail(null, '');
        $this->assertFalse($sucesss);
    }

    public function testStoreThumbnailSvgSimple() {
        $this->assertFileNotExists(Util::$cache_dir_thumbnails . self::$simpleSvgFileName . ".png");

        file_put_contents(Util::$cache_dir_svg . self::$simpleSvgFileName, file_get_contents(self::$fixtures_dir_svg . self::$simpleSvgFileName));
        $success = Util::generateThumbnailFromSvg(self::$simpleSvgFileName);

        $this->assertTrue($success);
        $this->assertFileEquals(self::$fixtures_dir_thumbnails . self::$simpleSvgFileName . ".png", Util::$cache_dir_thumbnails . self::$simpleSvgFileName . ".png");
    }

    public function testFetchAndStoreSvgWikiLogo() {
        $this->assertFileNotExists(Util::$cache_dir_svg . self::$wikimediaLogoFileName);

        $success = Util::fetchSvgWithThumbnail(self::$wikimediaLogoLocation, self::$wikimediaLogoFileName, self::$wikimediaLogoFileName);

        $this->assertTrue($success);
        $this->assertFileEquals(self::$fixtures_dir_svg. self::$wikimediaLogoFileName, Util::$cache_dir_svg . self::$wikimediaLogoFileName);
        $this->assertFileEquals(self::$fixtures_dir_thumbnails . self::$wikimediaLogoFileName . ".png", Util::$cache_dir_thumbnails . self::$wikimediaLogoFileName . ".png");
    }

    public function testStoreSvgInvalidPath() {
        $svg = file_get_contents(self::$fixtures_dir_svg.'simple.svg');
        $thumbnail = file_get_contents(self::$fixtures_dir_thumbnails.'simple.svg.png');
        $success = Util::storeSvgWithThumbnail($svg, $thumbnail, 'lo/go.svg');

        $this->assertFalse($success);
    }
}
 <commit_msg>Fix test for SVG storage in invalid path<commit_after><?php

namespace geotime\Test;

use geotime\Util;
use PHPUnit_Framework_TestCase;


class UtilTest extends \PHPUnit_Framework_TestCase {

    static $fixtures_dir_svg = "test/geotime/_fixtures/svg/";
    static $fixtures_dir_thumbnails = "test/geotime/_fixtures/thumbnails/";

    static $wikimediaLogoLocation = "http://upload.wikimedia.org/wikipedia/commons/8/81/Wikimedia-logo.svg";
    static $wikimediaLogoFileName = "logo.svg";

    static $simpleSvgFileName = "simple.svg";

    static function setUpBeforeClass() {
        Util::$log->info(__CLASS__." tests started");

        Util::$cache_dir_svg = "test/geotime/cache/svg/";
        Util::$cache_dir_thumbnails = "test/geotime/cache/thumbnails/";
        Util::$cache_dir_json = "test/geotime/cache/json/";

        self::cleanGeneratedFiles();
    }

    static function tearDownAfterClass()
    {
        self::cleanGeneratedFiles();
        Util::$log->info(__CLASS__ . " tests ended");
    }

    static function cleanGeneratedFiles() {
        @unlink(Util::$cache_dir_svg . self::$wikimediaLogoFileName);
        @unlink(Util::$cache_dir_thumbnails . self::$wikimediaLogoFileName . ".png");
        @unlink(Util::$cache_dir_svg . self::$simpleSvgFileName);
        @unlink(Util::$cache_dir_thumbnails . self::$simpleSvgFileName . ".png");
    }

    public function testFetchSvg() {
        $success = Util::fetchSvgWithThumbnail(self::$wikimediaLogoLocation, self::$wikimediaLogoFileName);
        $this->assertTrue($success);
    }

    public function testFetchSvgNullUrl() {
        $sucesss = Util::fetchSvgWithThumbnail(null, '');
        $this->assertFalse($sucesss);
    }

    public function testStoreThumbnailSvgSimple() {
        $this->assertFileNotExists(Util::$cache_dir_thumbnails . self::$simpleSvgFileName . ".png");

        file_put_contents(Util::$cache_dir_svg . self::$simpleSvgFileName, file_get_contents(self::$fixtures_dir_svg . self::$simpleSvgFileName));
        $success = Util::generateThumbnailFromSvg(self::$simpleSvgFileName);

        $this->assertTrue($success);
        $this->assertFileEquals(self::$fixtures_dir_thumbnails . self::$simpleSvgFileName . ".png", Util::$cache_dir_thumbnails . self::$simpleSvgFileName . ".png");
    }

    public function testFetchAndStoreSvgWikiLogo() {
        $this->assertFileNotExists(Util::$cache_dir_svg . self::$wikimediaLogoFileName);

        $success = Util::fetchSvgWithThumbnail(self::$wikimediaLogoLocation, self::$wikimediaLogoFileName, self::$wikimediaLogoFileName);

        $this->assertTrue($success);
        $this->assertFileEquals(self::$fixtures_dir_svg. self::$wikimediaLogoFileName, Util::$cache_dir_svg . self::$wikimediaLogoFileName);
        $this->assertFileEquals(self::$fixtures_dir_thumbnails . self::$wikimediaLogoFileName . ".png", Util::$cache_dir_thumbnails . self::$wikimediaLogoFileName . ".png");
    }

    public function testStoreSvgInvalidPath() {
        $svg = file_get_contents(self::$fixtures_dir_svg.'simple.svg');
        $success = Util::storeSvgWithThumbnail($svg, 'lo/go.svg');

        $this->assertFalse($success);
    }
}
 
{'fraction_non_alphanumeric': 0.14274570982839313, 'fraction_numerical': 0.00093603744149766, 'mean_word_length': 4.311516155758078, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '88642', 'n_tokens_mistral': 1993, 'n_tokens_neox': 2040, 'n_words': 250}