| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | require_once('../lib/simpletest/unit_tester.php'); |
|---|
| 4 | require_once('../lib/simpletest/reporter.php'); |
|---|
| 5 | require_once('../inc/Dojo.php'); |
|---|
| 6 | require_once('../inc/DojoPackage.php'); |
|---|
| 7 | |
|---|
| 8 | class SubDojoPackage extends DojoPackage |
|---|
| 9 | { |
|---|
| 10 | public function __construct($source, $second_line = false) { |
|---|
| 11 | parent::__construct(new Dojo('../'), ''); |
|---|
| 12 | $this->source = array($source); |
|---|
| 13 | if ($second_line) { |
|---|
| 14 | $this->source[] = $second_line; |
|---|
| 15 | } |
|---|
| 16 | } |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | class TestPackage extends UnitTestCase |
|---|
| 20 | { |
|---|
| 21 | function testGetSource() |
|---|
| 22 | { |
|---|
| 23 | $package = new SubDojoPackage('var rePkg = /(__package__|dojo)\.js([\?\.]|$)/i;'); |
|---|
| 24 | $code = $package->getCode(); |
|---|
| 25 | $this->assertEqual($code[0], 'var rePkg = / /i;'); |
|---|
| 26 | |
|---|
| 27 | $package = new SubDojoPackage('var url = "http://site.com";'); |
|---|
| 28 | $code = $package->getCode(); |
|---|
| 29 | $this->assertEqual($code[0], 'var url = " ";'); |
|---|
| 30 | |
|---|
| 31 | $package = new SubDojoPackage('var regex = /(")/; // Check for double quote (")'); |
|---|
| 32 | $code = $package->getCode(); |
|---|
| 33 | $this->assertEqual($code[0], 'var regex = / /; '); |
|---|
| 34 | |
|---|
| 35 | $package = new SubDojoPackage('if((typeof this["load"] == "function")&&((typeof this["Packages"] == "function")||(typeof this["Packages"] == "object"))){'); |
|---|
| 36 | $code = $package->getCode(); |
|---|
| 37 | $this->assertEqual($code[0], 'if((typeof this[" "] == " ")&&((typeof this[" "] == " ")||(typeof this[" "] == " "))){'); |
|---|
| 38 | |
|---|
| 39 | $package = new SubDojoPackage( '/* Test', ' multiline */'); |
|---|
| 40 | $code = $package->getCode(); |
|---|
| 41 | $this->assertEqual(implode("\n", $code), " \n "); |
|---|
| 42 | |
|---|
| 43 | $package = new SubDojoPackage('return "["+this.widgetType+" ID:"+this.widgetId+"]"'); |
|---|
| 44 | $code = $package->getCode(); |
|---|
| 45 | $this->assertEqual($code[0], 'return " "+this.widgetType+" "+this.widgetId+" "'); |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | $test = &new TestPackage(); |
|---|
| 50 | $test->run(new HtmlReporter()); |
|---|
| 51 | |
|---|
| 52 | ?> |
|---|