<commit_before><?php

class AssetsManagerTest extends PHPUnit_Framework_TestCase
{
	protected $manager;

	protected function setUp()
	{
		$this->manager = new Stolz\Assets\Manager();
	}

	public function testConfigSetsDirs()
	{
		$config = array(
			'public_dir'   => __DIR__,
			'css_dir'      => uniqid('css'),
			'js_dir'       => uniqid('js'),
			'packages_dir' => uniqid('packages'),
			'pipeline_dir' => uniqid('pipe'),
		);

		$this->manager->config($config);

		foreach($config as $key => $value)
		{
			$this->assertEquals($value, PHPUnit_Framework_Assert::readAttribute($this->manager, $key));
		}
	}

	public function testRemoteLinkDetection()
	{
		$method = self::getMethod('isRemoteLink');

		$this->assertTrue($method->invokeArgs($this->manager, array('http://foo')));
		$this->assertTrue($method->invokeArgs($this->manager, array('https://foo')));
		$this->assertTrue($method->invokeArgs($this->manager, array('//foo')));

		$this->assertFalse($method->invokeArgs($this->manager, array('/')));
		$this->assertFalse($method->invokeArgs($this->manager, array('/foo')));
		$this->assertFalse($method->invokeArgs($this->manager, array('foo')));
	}


	public function testPackageAssetDetection()
	{
		$vendor = '_This-Is-Vendor.0';
		$name = '_This-Is-Package.9';
		$asset = 'local/asset.css';

		$method = self::getMethod('assetIsFromPackage');
		$package = $method->invokeArgs($this->manager, array("$vendor/$name:$asset"));

		$this->assertCount(3, $package);
		$this->assertEquals($vendor, $package[0]);
		$this->assertEquals($name, $package[1]);
		$this->assertEquals($asset, $package[2]);

		$this->assertFalse($method->invokeArgs($this->manager, array('foo')));
		$this->assertFalse($method->invokeArgs($this->manager, array('foo/bar')));
		$this->assertFalse($method->invokeArgs($this->manager, array('foo/bar/foo:bar')));
		$this->assertFalse($method->invokeArgs($this->manager, array('foo:bar')));
	}

	public function testAddOneCss()
	{
		$this->assertCount(0, $this->manager->getCss());

		$asset = uniqid('asset');
		$this->manager->addCss($asset);
		$assets = $this->manager->getCss();

		$this->assertCount(1, $assets);
		$this->assertStringEndsWith($asset, array_pop($assets));
		$this->assertCount(0, $assets);
	}

	public function testAddOneJs()
	{
		$this->assertCount(0, $this->manager->getJs());

		$asset = uniqid('asset');
		$this->manager->addJs($asset);
		$assets = $this->manager->getJs();

		$this->assertCount(1, $assets);
		$this->assertStringEndsWith($asset, array_pop($assets));
		$this->assertCount(0, $assets);
	}

	public function testAddMultipleCss()
	{
		$this->assertCount(0, $this->manager->getCss());

		$asset1 = uniqid('asset1');
		$asset2 = uniqid('asset2');
		$this->manager->addCss(array($asset1, $asset2));
		$assets = $this->manager->getCss();

		$this->assertCount(2, $assets);
		$this->assertStringEndsWith($asset2, array_pop($assets));
		$this->assertStringEndsWith($asset1, array_pop($assets));
		$this->assertCount(0, $assets);
	}

	public function testAddMultipleJs()
	{
		$this->assertCount(0, $this->manager->getJs());

		$asset1 = uniqid('asset1');
		$asset2 = uniqid('asset2');
		$this->manager->addJs(array($asset1, $asset2));
		$assets = $this->manager->getJs();

		$this->assertCount(2, $assets);
		$this->assertStringEndsWith($asset2, array_pop($assets));
		$this->assertStringEndsWith($asset1, array_pop($assets));
		$this->assertCount(0, $assets);
	}

	public function testDetectAndAddCss()
	{
		$this->assertCount(0, $this->manager->getCss());
		$this->assertCount(0, $this->manager->getJs());

		$asset = 'foo.css';
		$this->manager->addCss($asset);

		$this->assertCount(1, $assets = $this->manager->getCss());
		$this->assertCount(0, $this->manager->getJs());
		$this->assertStringEndsWith($asset, array_pop($assets));
	}

	public function testDetectAndAddJs()
	{
		$this->assertCount(0, $this->manager->getCss());
		$this->assertCount(0, $this->manager->getJs());

		$asset = 'foo.js';
		$this->manager->addJs($asset);

		$this->assertCount(1, $assets = $this->manager->getJs());
		$this->assertCount(0, $this->manager->getCss());
		$this->assertStringEndsWith($asset, array_pop($assets));
	}

	public function testDetectAndAddCollection()
	{
		$asset1 = 'foo.js';
		$asset2 = 'foo.css';
		$collection = array($asset1, $asset2);
		$this->manager->config(array('collections' => array('collection' => $collection)));

		$this->assertCount(0, $this->manager->getCss());
		$this->assertCount(0, $this->manager->getJs());

		$this->manager->add('collection');

		$this->assertCount(1, $assets1 = $this->manager->getJs());
		$this->assertCount(1, $assets2 = $this->manager->getCss());

		$this->assertStringEndsWith($asset1, array_pop($assets1));
		$this->assertStringEndsWith($asset2, array_pop($assets2));
	}
<commit_msg>test exclude files from minification default Regexp<commit_after><?php

class AssetsManagerTest extends PHPUnit_Framework_TestCase
{
	protected $manager;

	protected function setUp()
	{
		$this->manager = new Stolz\Assets\Manager();
	}

	public function testConfigSetsDirs()
	{
		$config = array(
			'public_dir'   => __DIR__,
			'css_dir'      => uniqid('css'),
			'js_dir'       => uniqid('js'),
			'packages_dir' => uniqid('packages'),
			'pipeline_dir' => uniqid('pipe'),
		);

		$this->manager->config($config);

		foreach($config as $key => $value)
		{
			$this->assertEquals($value, PHPUnit_Framework_Assert::readAttribute($this->manager, $key));
		}
	}

	public function testRemoteLinkDetection()
	{
		$method = self::getMethod('isRemoteLink');

		$this->assertTrue($method->invokeArgs($this->manager, array('http://foo')));
		$this->assertTrue($method->invokeArgs($this->manager, array('https://foo')));
		$this->assertTrue($method->invokeArgs($this->manager, array('//foo')));

		$this->assertFalse($method->invokeArgs($this->manager, array('/')));
		$this->assertFalse($method->invokeArgs($this->manager, array('/foo')));
		$this->assertFalse($method->invokeArgs($this->manager, array('foo')));
	}


	public function testPackageAssetDetection()
	{
		$vendor = '_This-Is-Vendor.0';
		$name = '_This-Is-Package.9';
		$asset = 'local/asset.css';

		$method = self::getMethod('assetIsFromPackage');
		$package = $method->invokeArgs($this->manager, array("$vendor/$name:$asset"));

		$this->assertCount(3, $package);
		$this->assertEquals($vendor, $package[0]);
		$this->assertEquals($name, $package[1]);
		$this->assertEquals($asset, $package[2]);

		$this->assertFalse($method->invokeArgs($this->manager, array('foo')));
		$this->assertFalse($method->invokeArgs($this->manager, array('foo/bar')));
		$this->assertFalse($method->invokeArgs($this->manager, array('foo/bar/foo:bar')));
		$this->assertFalse($method->invokeArgs($this->manager, array('foo:bar')));
	}

	public function testAddOneCss()
	{
		$this->assertCount(0, $this->manager->getCss());

		$asset = uniqid('asset');
		$this->manager->addCss($asset);
		$assets = $this->manager->getCss();

		$this->assertCount(1, $assets);
		$this->assertStringEndsWith($asset, array_pop($assets));
		$this->assertCount(0, $assets);
	}

	public function testAddOneJs()
	{
		$this->assertCount(0, $this->manager->getJs());

		$asset = uniqid('asset');
		$this->manager->addJs($asset);
		$assets = $this->manager->getJs();

		$this->assertCount(1, $assets);
		$this->assertStringEndsWith($asset, array_pop($assets));
		$this->assertCount(0, $assets);
	}

	public function testAddMultipleCss()
	{
		$this->assertCount(0, $this->manager->getCss());

		$asset1 = uniqid('asset1');
		$asset2 = uniqid('asset2');
		$this->manager->addCss(array($asset1, $asset2));
		$assets = $this->manager->getCss();

		$this->assertCount(2, $assets);
		$this->assertStringEndsWith($asset2, array_pop($assets));
		$this->assertStringEndsWith($asset1, array_pop($assets));
		$this->assertCount(0, $assets);
	}

	public function testAddMultipleJs()
	{
		$this->assertCount(0, $this->manager->getJs());

		$asset1 = uniqid('asset1');
		$asset2 = uniqid('asset2');
		$this->manager->addJs(array($asset1, $asset2));
		$assets = $this->manager->getJs();

		$this->assertCount(2, $assets);
		$this->assertStringEndsWith($asset2, array_pop($assets));
		$this->assertStringEndsWith($asset1, array_pop($assets));
		$this->assertCount(0, $assets);
	}

	public function testDetectAndAddCss()
	{
		$this->assertCount(0, $this->manager->getCss());
		$this->assertCount(0, $this->manager->getJs());

		$asset = 'foo.css';
		$this->manager->addCss($asset);

		$this->assertCount(1, $assets = $this->manager->getCss());
		$this->assertCount(0, $this->manager->getJs());
		$this->assertStringEndsWith($asset, array_pop($assets));
	}

	public function testDetectAndAddJs()
	{
		$this->assertCount(0, $this->manager->getCss());
		$this->assertCount(0, $this->manager->getJs());

		$asset = 'foo.js';
		$this->manager->addJs($asset);

		$this->assertCount(1, $assets = $this->manager->getJs());
		$this->assertCount(0, $this->manager->getCss());
		$this->assertStringEndsWith($asset, array_pop($assets));
	}

	public function testDetectAndAddCollection()
	{
		$asset1 = 'foo.js';
		$asset2 = 'foo.css';
		$collection = array($asset1, $asset2);
		$this->manager->config(array('collections' => array('collection' => $collection)));

		$this->assertCount(0, $this->manager->getCss());
		$this->assertCount(0, $this->manager->getJs());

		$this->manager->add('collection');

		$this->assertCount(1, $assets1 = $this->manager->getJs());
		$this->assertCount(1, $assets2 = $this->manager->getCss());

		$this->assertStringEndsWith($asset1, array_pop($assets1));
		$this->assertStringEndsWith($asset2, array_pop($assets2));
	}

	public function testCanExcludeFilesFromMinificationDefaultRegexp(){

		$asset1 = 'foo.min.js';
		$asset2 = 'foo-min.js';
		$asset3 = 'foo.js';
		$asset4 = 'foo.css';

		//Test default Regexp
		$pattern = PHPUnit_Framework_Assert::readAttribute($this->manager, 'exclude_minification_regex');

		$this->assertEquals(1, preg_match($pattern,$asset1));
		$this->assertEquals(1, preg_match($pattern,$asset2));

		$this->assertEquals(0, preg_match($pattern,$asset3));
		$this->assertEquals(0, preg_match($pattern,$asset4));
	}

{'fraction_non_alphanumeric': 0.2186637761135199, 'fraction_numerical': 0.012219156484036263, 'mean_word_length': 5.811409395973154, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 286, 'https://': 2, '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': '1179583', 'n_tokens_mistral': 3740, 'n_tokens_neox': 3503, 'n_words': 469}