2014-10-12 22:27:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use MatthiasMullie\Minify;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests common functions of abstract Minify class by using JS implementation.
|
|
|
|
*/
|
|
|
|
class CommonTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function construct()
|
|
|
|
{
|
2015-03-06 13:17:33 +01:00
|
|
|
$path1 = __DIR__.'/sample/source/script1.js';
|
|
|
|
$path2 = __DIR__.'/sample/source/script2.js';
|
2014-10-12 22:27:51 +02:00
|
|
|
$content1 = file_get_contents($path1);
|
|
|
|
$content2 = file_get_contents($path2);
|
|
|
|
|
|
|
|
// 1 source in constructor
|
|
|
|
$minifier = new Minify\JS($content1);
|
|
|
|
$result = $minifier->minify();
|
|
|
|
|
|
|
|
$this->assertEquals($content1, $result);
|
|
|
|
|
|
|
|
// multiple sources in constructor
|
|
|
|
$minifier = new Minify\JS($content1, $content2);
|
|
|
|
$result = $minifier->minify();
|
|
|
|
|
2015-03-06 13:17:33 +01:00
|
|
|
$this->assertEquals($content1.';'.$content2, $result);
|
2014-10-12 22:27:51 +02:00
|
|
|
|
|
|
|
// file in constructor
|
|
|
|
$minifier = new Minify\JS($path1);
|
|
|
|
$result = $minifier->minify();
|
|
|
|
|
|
|
|
$this->assertEquals($content1, $result);
|
|
|
|
|
|
|
|
// multiple files in constructor
|
|
|
|
$minifier = new Minify\JS($path1, $path2);
|
|
|
|
$result = $minifier->minify();
|
|
|
|
|
2015-03-06 13:17:33 +01:00
|
|
|
$this->assertEquals($content1.';'.$content2, $result);
|
2014-10-12 22:27:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function add()
|
|
|
|
{
|
2015-03-06 13:17:33 +01:00
|
|
|
$path1 = __DIR__.'/sample/source/script1.js';
|
|
|
|
$path2 = __DIR__.'/sample/source/script2.js';
|
2014-10-12 22:27:51 +02:00
|
|
|
$content1 = file_get_contents($path1);
|
|
|
|
$content2 = file_get_contents($path2);
|
|
|
|
|
|
|
|
// 1 source in add
|
|
|
|
$minifier = new Minify\JS();
|
|
|
|
$minifier->add($content1);
|
|
|
|
$result = $minifier->minify();
|
|
|
|
|
|
|
|
$this->assertEquals($content1, $result);
|
|
|
|
|
|
|
|
// multiple sources in add
|
|
|
|
$minifier = new Minify\JS();
|
|
|
|
$minifier->add($content1);
|
|
|
|
$minifier->add($content2);
|
|
|
|
$result = $minifier->minify();
|
|
|
|
|
2015-03-06 13:17:33 +01:00
|
|
|
$this->assertEquals($content1.';'.$content2, $result);
|
2014-10-12 22:27:51 +02:00
|
|
|
|
|
|
|
// file in add
|
|
|
|
$minifier = new Minify\JS();
|
|
|
|
$minifier->add($path1);
|
|
|
|
$result = $minifier->minify();
|
|
|
|
|
|
|
|
$this->assertEquals($content1, $result);
|
|
|
|
|
|
|
|
// multiple files in add
|
|
|
|
$minifier = new Minify\JS();
|
|
|
|
$minifier->add($path1);
|
|
|
|
$minifier->add($path2);
|
|
|
|
$result = $minifier->minify();
|
|
|
|
|
2015-03-06 13:17:33 +01:00
|
|
|
$this->assertEquals($content1.';'.$content2, $result);
|
2014-10-12 22:27:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2015-02-12 13:34:48 +01:00
|
|
|
public function save()
|
|
|
|
{
|
2015-03-06 13:17:33 +01:00
|
|
|
$path1 = __DIR__.'/sample/source/script1.js';
|
2014-10-12 22:27:51 +02:00
|
|
|
$content1 = file_get_contents($path1);
|
2015-03-06 13:17:33 +01:00
|
|
|
$savePath = __DIR__.'/sample/target/script1.js';
|
2014-10-12 22:27:51 +02:00
|
|
|
|
|
|
|
$minifier = new Minify\JS($path1);
|
|
|
|
$minifier->minify($savePath);
|
|
|
|
|
|
|
|
$this->assertEquals(file_get_contents($savePath), $content1);
|
|
|
|
}
|
|
|
|
}
|