Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
439 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
framework/JavascriptMinify/test/Horde/JavascriptMinify/AllTests.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
require_once 'Horde/Test/AllTests.php'; | ||
Horde_Test_AllTests::init(__FILE__)->run(); |
67 changes: 67 additions & 0 deletions
67
framework/JavascriptMinify/test/Horde/JavascriptMinify/ClosureTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Copyright 2017 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @category Horde | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package JavascriptMinify | ||
* @subpackage UnitTests | ||
*/ | ||
|
||
/** | ||
* Tests the Closure backend. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @category Horde | ||
* @copyright 2017 Horde LLC | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package JavascriptMinify | ||
* @subpackage UnitTests | ||
*/ | ||
class Horde_JavascriptMinify_ClosureTest | ||
extends Horde_JavascriptMinify_TestBase | ||
{ | ||
protected $_config; | ||
|
||
public function setUp() | ||
{ | ||
$this->_config = self::getConfig( | ||
'JAVASCRIPTMINIFY_CLOSURE_TEST_CONFIG', | ||
__DIR__ | ||
); | ||
if (!$this->_config || | ||
empty($this->_config['javascriptminify']['closure'])) { | ||
$this->markTestSkipped('Closure compressor not configured'); | ||
} | ||
} | ||
|
||
public function testMinify() | ||
{ | ||
$this->_minify(); | ||
} | ||
|
||
public function testSourcemap() | ||
{ | ||
$this->_sourcemap(); | ||
} | ||
|
||
public function testToString() | ||
{ | ||
$this->_toString(); | ||
} | ||
|
||
protected function _getMinifier($files = false) | ||
{ | ||
$opts = $this->_config['javascriptminify']['closure']; | ||
if ($files) { | ||
$opts['sourcemap'] = 'https://www.example.com/js/sourcemap'; | ||
} | ||
return new Horde_JavascriptMinify_Closure( | ||
$this->_getFixture($files), $opts | ||
); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
framework/JavascriptMinify/test/Horde/JavascriptMinify/NullTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Copyright 2017 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @category Horde | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package JavascriptMinify | ||
* @subpackage UnitTests | ||
*/ | ||
|
||
/** | ||
* Tests the Null backend. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @category Horde | ||
* @copyright 2017 Horde LLC | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package JavascriptMinify | ||
* @subpackage UnitTests | ||
*/ | ||
class Horde_JavascriptMinify_NullTest | ||
extends Horde_JavascriptMinify_TestBase | ||
{ | ||
public function testToString() | ||
{ | ||
$this->_toString(); | ||
} | ||
|
||
protected function _getMinifier() | ||
{ | ||
return new Horde_JavascriptMinify_Null($this->_getFixture()); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
framework/JavascriptMinify/test/Horde/JavascriptMinify/TestBase.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
/** | ||
* Copyright 2017 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @category Horde | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package JavascriptMinify | ||
* @subpackage UnitTests | ||
*/ | ||
|
||
/** | ||
* Base class for backend unit tests. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @category Horde | ||
* @copyright 2017 Horde LLC | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package JavascriptMinify | ||
* @subpackage UnitTests | ||
*/ | ||
abstract class Horde_JavascriptMinify_TestBase extends Horde_Test_Case | ||
{ | ||
public function setUp() | ||
{ | ||
} | ||
|
||
protected function _minify() | ||
{ | ||
$minifier = $this->_getMinifier(); | ||
$minified = $minifier->minify(); | ||
$this->assertNotEmpty($minified); | ||
$this->assertLessThan( | ||
strlen($this->_getFixture()), | ||
strlen($minified) | ||
); | ||
|
||
$minifier = $this->_getMinifier(true); | ||
$minified = $minifier->minify(); | ||
$this->assertNotEmpty($minified); | ||
$this->assertLessThan( | ||
strlen(implode('', array_map('file_get_contents', $this->_getFixture(true)))), | ||
strlen($minified) | ||
); | ||
} | ||
|
||
protected function _sourcemap() | ||
{ | ||
$minifier = $this->_getMinifier(true, true); | ||
$minifier->minify(); | ||
$sourcemap = $minifier->sourcemap(); | ||
$this->assertNotEmpty($sourcemap); | ||
$this->assertNotEmpty(json_decode($sourcemap)); | ||
} | ||
|
||
protected function _toString() | ||
{ | ||
$minifier = $this->_getMinifier(); | ||
$this->assertEquals($minifier->minify(), (string)$minifier); | ||
} | ||
|
||
abstract protected function _getMinifier(); | ||
|
||
protected function _getFixture($files = false) | ||
{ | ||
if ($files) { | ||
return array( | ||
'https://www.example.com/js/one.js' => __DIR__ . '/fixtures/one.js', | ||
'https://www.example.com/js/two.js' => __DIR__ . '/fixtures/two.js', | ||
); | ||
} | ||
|
||
return <<<JAVASCRIPT | ||
/** | ||
* Some example code. | ||
* | ||
*/ | ||
var Foo = { | ||
doit: function(foo) | ||
{ | ||
var test, xyz = 1; | ||
this.callme(); | ||
xyz++; | ||
test = 'Bar'; | ||
alert(test + foo); | ||
} | ||
}; | ||
Foo.doit("Boo"); | ||
JAVASCRIPT; | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
framework/JavascriptMinify/test/Horde/JavascriptMinify/UglifyjsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Copyright 2017 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @category Horde | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package JavascriptMinify | ||
* @subpackage UnitTests | ||
*/ | ||
|
||
/** | ||
* Tests the UglifyJS backend. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @category Horde | ||
* @copyright 2017 Horde LLC | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package JavascriptMinify | ||
* @subpackage UnitTests | ||
*/ | ||
class Horde_JavascriptMinify_UglifyjsTest | ||
extends Horde_JavascriptMinify_TestBase | ||
{ | ||
protected $_config; | ||
|
||
public function setUp() | ||
{ | ||
$this->_config = self::getConfig( | ||
'JAVASCRIPTMINIFY_UGLIFYJS_TEST_CONFIG', | ||
__DIR__ | ||
); | ||
if (!$this->_config || | ||
empty($this->_config['javascriptminify']['uglifyjs'])) { | ||
$this->markTestSkipped('UglifyJS compressor not configured'); | ||
} | ||
} | ||
|
||
public function testMinify() | ||
{ | ||
$this->_minify(); | ||
} | ||
|
||
public function testSourcemap() | ||
{ | ||
$this->_sourcemap(); | ||
} | ||
|
||
public function testToString() | ||
{ | ||
$this->_toString(); | ||
} | ||
|
||
protected function _getMinifier($files = false) | ||
{ | ||
$opts = $this->_config['javascriptminify']['uglifyjs']; | ||
if ($files) { | ||
$opts['sourcemap'] = 'https://www.example.com/js/sourcemap'; | ||
} | ||
return new Horde_JavascriptMinify_Uglifyjs( | ||
$this->_getFixture($files), $opts | ||
); | ||
} | ||
} |
Oops, something went wrong.