-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tools/Tests/Unit/TestsGenerator/Generator.php
- Loading branch information
Showing
14 changed files
with
375 additions
and
1 deletion.
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
27 changes: 27 additions & 0 deletions
27
Tools/Tests/Unit/TestsGenerator/Generator/AddAndGetTests.xml
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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<tests name="Test name" template="test.tpl.xslt" templatingType="smarty"> | ||
<files> | ||
<file id="one">one.xml</file> | ||
<file id="two">two.xml</file> | ||
<file id="three">three.xml</file> | ||
<generated id="genOne" generator="easy" output="genOne.xml"> | ||
<setting name="first">2</setting> | ||
<setting name="second">5</setting> | ||
</generated> | ||
<generated id="genTwo" generator="easy" output="genTwo.xml"> | ||
<setting name="element">20</setting> | ||
</generated> | ||
</files> | ||
<test name="First"> | ||
<file input="one" output="genOne" /> | ||
<file input="two" output="genTwo" /> | ||
<setting name="first seting">Lorem ipsum</setting> | ||
<setting name="second setting">123</setting> | ||
</test> | ||
<test name="Second"> | ||
<file input="one" output="genOne" /> | ||
<file input="two" output="genTwo" /> | ||
<file input="three" output="one" /> | ||
<setting name="setting">999</setting> | ||
</test> | ||
</tests> |
93 changes: 93 additions & 0 deletions
93
Tools/Tests/Unit/TestsGenerator/Generator/AddAndGetTestsTest.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,93 @@ | ||
<?php | ||
|
||
/** | ||
* XSLT Benchmarking | ||
* @link https://github.com/masicek/XSLT-Benchmarking | ||
* @author Viktor Mašíček <[email protected]> | ||
* @license "New" BSD License | ||
*/ | ||
|
||
namespace Tests\XSLTBenchmark\TestsGenerator\Generator; | ||
|
||
require_once ROOT . '/TestsGenerator/Generator.php'; | ||
require_once ROOT . '/TestsGenerator/Test.php'; | ||
|
||
use \Tests\XSLTBenchmark\TestCase; | ||
use \XSLTBenchmark\TestsGenerator\Generator; | ||
use \XSLTBenchmark\TestsGenerator\Test; | ||
|
||
/** | ||
* AddAndGetTestsTest | ||
* | ||
* @author Viktor Mašíček <[email protected]> | ||
* | ||
* @covers \XSLTBenchmark\TestsGenerator\Generator::addTests | ||
* @covers \XSLTBenchmark\TestsGenerator\Generator::getTests | ||
*/ | ||
class AddAndGetTestsTest extends TestCase | ||
{ | ||
|
||
|
||
public function test() | ||
{ | ||
$templates = $this->setDirSep(__DIR__ . '/A'); | ||
$templateXYZ = $this->setDirSep(__DIR__ . '/A/XYZ'); | ||
$tests = $this->setDirSep(__DIR__ . '/B'); | ||
$tmp = $this->setDirSep(__DIR__ . '/C'); | ||
|
||
mkdir($templates); | ||
mkdir($templateXYZ); | ||
mkdir($tests); | ||
mkdir($tmp); | ||
|
||
copy( | ||
$this->setDirSep(__DIR__ . '/AddAndGetTests.xml'), | ||
$this->setDirSep($templateXYZ . '/params.xml') | ||
); | ||
|
||
$generator = new Generator($templates, $tests, $tmp); | ||
$generator->addTests('XYZ', 'params.xml'); | ||
$addedTests = $generator->getTests(); | ||
|
||
// make expected tests | ||
$expectedTests = array(); | ||
|
||
// first test | ||
$test = new Test(''); | ||
$this->setPropertyValue($test, 'name', 'Test name - First'); | ||
$this->setPropertyValue($test, 'templatePath', $this->setDirSep($templateXYZ . '/test.tpl.xslt')); | ||
$this->setPropertyValue($test, 'templatingType', 'smarty'); | ||
$this->setPropertyValue($test, 'path', $this->setDirSep($tests . '/test-name-first')); | ||
$this->setPropertyValue($test, 'settings', array('first seting' => 'Lorem ipsum', 'second setting' => 123)); | ||
$this->setPropertyValue($test, 'filesPaths', array( | ||
$this->setDirSep($templateXYZ . '/one.xml') => $this->setDirSep($tmp . '/genOne.xml'), | ||
$this->setDirSep($templateXYZ . '/two.xml') => $this->setDirSep($tmp . '/genTwo.xml'), | ||
)); | ||
$expectedTests[] = $test; | ||
|
||
// second test | ||
$test = new Test(''); | ||
$this->setPropertyValue($test, 'name', 'Test name - Second'); | ||
$this->setPropertyValue($test, 'templatePath', $this->setDirSep($templateXYZ . '/test.tpl.xslt')); | ||
$this->setPropertyValue($test, 'templatingType', 'smarty'); | ||
$this->setPropertyValue($test, 'path', $this->setDirSep($tests . '/test-name-second')); | ||
$this->setPropertyValue($test, 'settings', array('setting' => 999)); | ||
$this->setPropertyValue($test, 'filesPaths', array( | ||
$this->setDirSep($templateXYZ . '/one.xml') => $this->setDirSep($tmp . '/genOne.xml'), | ||
$this->setDirSep($templateXYZ . '/two.xml') => $this->setDirSep($tmp . '/genTwo.xml'), | ||
$this->setDirSep($templateXYZ . '/three.xml') => $this->setDirSep($templateXYZ . '/one.xml'), | ||
)); | ||
$expectedTests[] = $test; | ||
|
||
$this->assertEquals($expectedTests, $addedTests); | ||
|
||
unlink($this->setDirSep($templateXYZ . '/params.xml')); | ||
rmdir($templateXYZ); | ||
rmdir($templates); | ||
rmdir($tests); | ||
unlink($this->setDirSep($tmp . '/genOne.xml')); | ||
unlink($this->setDirSep($tmp . '/genTwo.xml')); | ||
rmdir($tmp); | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
Tools/Tests/Unit/TestsGenerator/Generator/FixtureGenerateAll/expectedTemplate1.xslt
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,4 @@ | ||
My default text | ||
|
||
Lorem ipsum 1.1 | ||
Lorem ipsum 1.2 |
4 changes: 4 additions & 0 deletions
4
Tools/Tests/Unit/TestsGenerator/Generator/FixtureGenerateAll/expectedTemplate2.xslt
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,4 @@ | ||
My default text | ||
|
||
Lorem ipsum 2.1 | ||
Lorem ipsum 2.2 |
5 changes: 5 additions & 0 deletions
5
Tools/Tests/Unit/TestsGenerator/Generator/FixtureGenerateAll/expected__params1.xml
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,5 @@ | ||
<?xml version="1.0"?> | ||
<test template="template.xslt"> | ||
<couple input="one.xml" output="genOne.xml"/> | ||
<couple input="two.xml" output="genTwo.xml"/> | ||
</test> |
4 changes: 4 additions & 0 deletions
4
Tools/Tests/Unit/TestsGenerator/Generator/FixtureGenerateAll/expected__params2.xml
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,4 @@ | ||
<?xml version="1.0"?> | ||
<test template="template.xslt"> | ||
<couple input="one.xml" output="genOne.xml"/> | ||
</test> |
3 changes: 3 additions & 0 deletions
3
Tools/Tests/Unit/TestsGenerator/Generator/FixtureGenerateAll/genOne.xml
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<root> | ||
</root> |
3 changes: 3 additions & 0 deletions
3
Tools/Tests/Unit/TestsGenerator/Generator/FixtureGenerateAll/genTwo.xml
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<root> | ||
</root> |
3 changes: 3 additions & 0 deletions
3
Tools/Tests/Unit/TestsGenerator/Generator/FixtureGenerateAll/one.xml
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<root> | ||
</root> |
4 changes: 4 additions & 0 deletions
4
Tools/Tests/Unit/TestsGenerator/Generator/FixtureGenerateAll/template.tpl.xslt
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,4 @@ | ||
My default text | ||
|
||
{$testVariable1} | ||
{$testVariable2} |
3 changes: 3 additions & 0 deletions
3
Tools/Tests/Unit/TestsGenerator/Generator/FixtureGenerateAll/two.xml
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<root> | ||
</root> |
147 changes: 147 additions & 0 deletions
147
Tools/Tests/Unit/TestsGenerator/Generator/GenerateAllTest.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,147 @@ | ||
<?php | ||
|
||
/** | ||
* XSLT Benchmarking | ||
* @link https://github.com/masicek/XSLT-Benchmarking | ||
* @author Viktor Mašíček <[email protected]> | ||
* @license "New" BSD License | ||
*/ | ||
|
||
namespace Tests\XSLTBenchmark\TestsGenerator\Generator; | ||
|
||
require_once ROOT . '/TestsGenerator/Generator.php'; | ||
require_once ROOT . '/TestsGenerator/Test.php'; | ||
|
||
use \Tests\XSLTBenchmark\TestCase; | ||
use \XSLTBenchmark\TestsGenerator\Generator; | ||
use \XSLTBenchmark\TestsGenerator\Test; | ||
|
||
/** | ||
* AddAndGetTestsTest | ||
* | ||
* @author Viktor Mašíček <[email protected]> | ||
* | ||
* @covers \XSLTBenchmark\TestsGenerator\Generator::generateAll | ||
* @covers \XSLTBenchmark\TestsGenerator\Generator::generateTest | ||
* @covers \XSLTBenchmark\TestsGenerator\Generator::generateInputOutputCouples | ||
*/ | ||
class GenerateAllTest extends TestCase | ||
{ | ||
|
||
|
||
public function test() | ||
{ | ||
$fixture = $this->setDirSep(__DIR__ . '/FixtureGenerateAll'); | ||
$tests = $this->setDirSep(__DIR__ . '/tests'); | ||
mkdir($tests); | ||
|
||
$generator = new Generator(__DIR__, __DIR__, __DIR__); | ||
|
||
// make tests | ||
$testsList = array(); | ||
|
||
// first test | ||
$test = new Test(''); | ||
$this->setPropertyValue($test, 'name', 'Test name - First'); | ||
$this->setPropertyValue($test, 'templatePath', $this->setDirSep($fixture . '/template.tpl.xslt')); | ||
$this->setPropertyValue($test, 'templatingType', 'smarty'); | ||
$this->setPropertyValue($test, 'path', $this->setDirSep($tests . '/test-name-first')); | ||
$this->setPropertyValue($test, 'settings', array('testVariable1' => 'Lorem ipsum 1.1', 'testVariable2' => 'Lorem ipsum 1.2')); | ||
$this->setPropertyValue($test, 'filesPaths', array( | ||
$this->setDirSep($fixture . '/one.xml') => $this->setDirSep($fixture . '/genOne.xml'), | ||
$this->setDirSep($fixture . '/two.xml') => $this->setDirSep($fixture . '/genTwo.xml'), | ||
)); | ||
$testsList[] = $test; | ||
|
||
// second test | ||
$test = new Test(''); | ||
$this->setPropertyValue($test, 'name', 'Test name - Second'); | ||
$this->setPropertyValue($test, 'templatePath', $this->setDirSep($fixture . '/template.tpl.xslt')); | ||
$this->setPropertyValue($test, 'templatingType', 'smarty'); | ||
$this->setPropertyValue($test, 'path', $this->setDirSep($tests . '/test-name-second')); | ||
$this->setPropertyValue($test, 'settings', array('testVariable1' => 'Lorem ipsum 2.1', 'testVariable2' => 'Lorem ipsum 2.2')); | ||
$this->setPropertyValue($test, 'filesPaths', array( | ||
$this->setDirSep($fixture . '/one.xml') => $this->setDirSep($fixture . '/genOne.xml'), | ||
)); | ||
$testsList[] = $test; | ||
|
||
$this->setPropertyValue($generator, 'templates', $testsList); | ||
|
||
// fisrt test | ||
$this->assertFileNotExists($this->setDirSep($tests . '/test-name-first/template.xslt')); | ||
$this->assertFileNotExists($this->setDirSep($tests . '/test-name-first/one.xml')); | ||
$this->assertFileNotExists($this->setDirSep($tests . '/test-name-first/genOne.xml')); | ||
$this->assertFileNotExists($this->setDirSep($tests . '/test-name-first/two.xml')); | ||
$this->assertFileNotExists($this->setDirSep($tests . '/test-name-first/genTwo.xml')); | ||
$this->assertFileNotExists($this->setDirSep($tests . '/test-name-first/__params.xml')); | ||
// second test | ||
$this->assertFileNotExists($this->setDirSep($tests . '/test-name-second/template.xslt')); | ||
$this->assertFileNotExists($this->setDirSep($tests . '/test-name-second/one.xml')); | ||
$this->assertFileNotExists($this->setDirSep($tests . '/test-name-second/genOne.xml')); | ||
$this->assertFileNotExists($this->setDirSep($tests . '/test-name-second/__params.xml')); | ||
|
||
// generate all tests from template | ||
$generator->generateAll(); | ||
|
||
// fisrt test | ||
$this->assertFileExists($this->setDirSep($tests . '/test-name-first/template.xslt')); | ||
$this->assertFileExists($this->setDirSep($tests . '/test-name-first/one.xml')); | ||
$this->assertFileExists($this->setDirSep($tests . '/test-name-first/genOne.xml')); | ||
$this->assertFileExists($this->setDirSep($tests . '/test-name-first/two.xml')); | ||
$this->assertFileExists($this->setDirSep($tests . '/test-name-first/genTwo.xml')); | ||
$this->assertFileExists($this->setDirSep($tests . '/test-name-first/__params.xml')); | ||
// second test | ||
$this->assertFileExists($this->setDirSep($tests . '/test-name-second/template.xslt')); | ||
$this->assertFileExists($this->setDirSep($tests . '/test-name-second/one.xml')); | ||
$this->assertFileExists($this->setDirSep($tests . '/test-name-second/genOne.xml')); | ||
$this->assertFileExists($this->setDirSep($tests . '/test-name-second/__params.xml')); | ||
|
||
// content | ||
$this->assertFileEquals( | ||
$this->setDirSep($fixture . '/expectedTemplate1.xslt'), | ||
$this->setDirSep($tests . '/test-name-first/template.xslt') | ||
); | ||
$this->assertFileEquals( | ||
$this->setDirSep($fixture . '/expectedTemplate2.xslt'), | ||
$this->setDirSep($tests . '/test-name-second/template.xslt') | ||
); | ||
$this->assertXmlFileEqualsXmlFile( | ||
$this->setDirSep($fixture . '/expected__params1.xml'), | ||
$this->setDirSep($tests . '/test-name-first/__params.xml') | ||
); | ||
$this->assertXmlFileEqualsXmlFile( | ||
$this->setDirSep($fixture . '/expected__params2.xml'), | ||
$this->setDirSep($tests . '/test-name-second/__params.xml') | ||
); | ||
|
||
|
||
// remove all generated files and directories | ||
// fisrt test | ||
unlink($this->setDirSep($tests . '/test-name-first/template.xslt')); | ||
unlink($this->setDirSep($tests . '/test-name-first/one.xml')); | ||
unlink($this->setDirSep($tests . '/test-name-first/genOne.xml')); | ||
unlink($this->setDirSep($tests . '/test-name-first/two.xml')); | ||
unlink($this->setDirSep($tests . '/test-name-first/genTwo.xml')); | ||
unlink($this->setDirSep($tests . '/test-name-first/__params.xml')); | ||
rmdir($this->setDirSep($tests . '/test-name-first')); | ||
// second test | ||
unlink($this->setDirSep($tests . '/test-name-second/template.xslt')); | ||
unlink($this->setDirSep($tests . '/test-name-second/one.xml')); | ||
unlink($this->setDirSep($tests . '/test-name-second/genOne.xml')); | ||
unlink($this->setDirSep($tests . '/test-name-second/__params.xml')); | ||
rmdir($this->setDirSep($tests . '/test-name-second')); | ||
|
||
rmdir($tests); | ||
|
||
// remove temporary file | ||
$files = scandir(__DIR__); | ||
foreach ($files as $file) | ||
{ | ||
if (strpos($file, '.file.template.tpl.xslt.php') !== FALSE) | ||
{ | ||
unlink($this->setDirSep(__DIR__ . '/' . $file)); | ||
} | ||
} | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
Tools/Tests/Unit/TestsGenerator/Generator/GeneratorTest.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,74 @@ | ||
<?php | ||
|
||
/** | ||
* XSLT Benchmarking | ||
* @link https://github.com/masicek/XSLT-Benchmarking | ||
* @author Viktor Mašíček <[email protected]> | ||
* @license "New" BSD License | ||
*/ | ||
|
||
namespace Tests\XSLTBenchmark\TestsGenerator\Generator; | ||
|
||
require_once ROOT . '/TestsGenerator/Generator.php'; | ||
|
||
use \Tests\XSLTBenchmark\TestCase; | ||
use \XSLTBenchmark\TestsGenerator\Generator; | ||
|
||
/** | ||
* GeneratorTest | ||
* | ||
* @author Viktor Mašíček <[email protected]> | ||
* | ||
* @covers \XSLTBenchmark\TestsGenerator\Generator::__construct | ||
*/ | ||
class GeneratorTest extends TestCase | ||
{ | ||
|
||
|
||
public function testOk() | ||
{ | ||
$templates = $this->setDirSep(__DIR__ . '/A'); | ||
$tests = $this->setDirSep(__DIR__ . '/B'); | ||
$tmp = $this->setDirSep(__DIR__ . '/C'); | ||
|
||
mkdir($templates); | ||
mkdir($tests); | ||
mkdir($tmp); | ||
|
||
$generator = new Generator($templates, $tests, $tmp); | ||
|
||
$this->assertEquals($templates, $this->getPropertyValue($generator, 'templatesDirectory')); | ||
$this->assertEquals($tests, $this->getPropertyValue($generator, 'testsDirectory')); | ||
$this->assertEquals($tmp, $this->getPropertyValue($generator, 'tmpDirectory')); | ||
|
||
rmdir($templates); | ||
rmdir($tests); | ||
rmdir($tmp); | ||
} | ||
|
||
|
||
public function testBadTemplatedDir() | ||
{ | ||
$unknown = $this->setDirSep(__DIR__ . '/unknown'); | ||
$this->setExpectedException('\PhpPath\NotExistsPathException'); | ||
$generator = new Generator($unknown, __DIR__, __DIR__); | ||
} | ||
|
||
|
||
public function testBadTestsDir() | ||
{ | ||
$unknown = $this->setDirSep(__DIR__ . '/unknown'); | ||
$this->setExpectedException('\PhpPath\NotExistsPathException'); | ||
$generator = new Generator(__DIR__, $unknown, __DIR__); | ||
} | ||
|
||
|
||
public function testBadTmpDir() | ||
{ | ||
$unknown = $this->setDirSep(__DIR__ . '/unknown'); | ||
$this->setExpectedException('\PhpPath\NotExistsPathException'); | ||
$generator = new Generator(__DIR__, __DIR__, $unknown); | ||
} | ||
|
||
|
||
} |