]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/jssource/SugarJSMinTest.php
Merge pull request #126 from telematika/master
[Github/sugarcrm.git] / tests / jssource / SugarJSMinTest.php
1 <?php
2
3 class JSIterator implements Iterator {
4     private $data = array();
5     private $key = 0;
6     private $test_files = array();
7
8     public function __construct($directory, $expectFiles = TRUE) {
9         $root_dir = realpath('tests/jssource/'.$directory);
10         $test_dir = $root_dir.'/test/';
11         if($expectFiles) {
12             $expect_dir = $root_dir.'/expect/';
13         }
14
15         $test_contents = scandir($test_dir);
16         foreach($test_contents as $possible_file) {
17             $test_file = $test_dir.$possible_file;
18             if($expectFiles) {
19                 $expect_file = $expect_dir.$possible_file;
20                 if(is_file($test_file) && is_file($expect_file)) {
21                     $this->test_files[] = array($test_file, $expect_file);
22                 }
23             } else {
24                 if(is_file($test_file)) {
25                     $this->test_files[] = array($test_file);
26                 }
27             }
28         }
29     }
30
31     public function current() {
32         $ret = array();
33         foreach($this->test_files[$this->key] as $file) {
34             $ret[] = file_get_contents($file);
35         }
36         return $ret;
37     }
38
39     public function key() {
40         return $this->key;
41     }
42
43     public function rewind() {
44         reset($this->test_files);
45         $this->data = array();
46         $this->key = 0;
47     }
48
49     public function valid() {
50         return $this->key < count($this->test_files);
51     }
52
53     public function next() {
54         ++$this->key;
55     }
56 }
57
58 class SugarJSMinTest extends PHPUnit_Framework_TestCase {
59     /**
60      * @dataProvider minifyProvider
61      */
62     public function testMinify($unminified, $minified) {
63         require_once('jssource/jsmin.php');
64         $this->assertEquals(SugarMin::minify($unminified), $minified);
65     }
66
67     public function minifyProvider() {
68         return new JSIterator('minify');
69     }
70 }