Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

Commit

Permalink
Adding unit tests for opt:selector.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxist committed Oct 8, 2010
1 parent 68d69ff commit 53043df
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 56 deletions.
4 changes: 2 additions & 2 deletions tests/Package/Instruction/AllTests.php
Expand Up @@ -31,7 +31,7 @@
require_once('RepeatTest.php');
//require_once('RootTest.php');
require_once('SectionTest.php');
//require_once('SelectorTest.php');
require_once('SelectorTest.php');
//require_once('ShowTest.php');
//require_once('SingleTest.php');
require_once('SnippetTest.php');
Expand Down Expand Up @@ -73,7 +73,7 @@ public static function suite()
$suite->addTestSuite('Package_Instruction_RepeatTest');
//$suite->addTestSuite('Package_Instruction_RootTest');
$suite->addTestSuite('Package_Instruction_SectionTest');
//$suite->addTestSuite('Package_Instruction_SelectorTest');
$suite->addTestSuite('Package_Instruction_SelectorTest');
//$suite->addTestSuite('Package_Instruction_ShowTest');
//$suite->addTestSuite('Package_Instruction_SingleTest');
$suite->addTestSuite('Package_Instruction_SnippetTest');
Expand Down
61 changes: 61 additions & 0 deletions tests/Package/Instruction/SelectorTest.php
@@ -0,0 +1,61 @@
<?php
/**
* The tests for opt:selector instruction.
*
* @author Tomasz "Zyx" Jędrzejewski
* @copyright Copyright (c) 2010 Invenzzia Group
* @license http://www.invenzzia.org/license/new-bsd New BSD License
*/

require_once('./Extra/TestFS.php');
require_once('./Extra/TestFSBase.php');

/**
* @covers Opt_Compiler_Class
* @covers Opt_Compiler_Format
* @covers Opt_Compiler_Processor
* @covers Opt_Instruction_Section_Abstract
* @covers Opt_Instruction_Selector
* @runTestsInSeparateProcesses
*/
class Package_Instruction_SelectorTest extends Extra_TestFSBase
{

/**
* Configuration method.
* @param Opt_Class $tpl
*/
public function configure(Opt_Class $tpl)
{
$tpl->parser = 'Opt_Parser_Xml';
$tpl->register(Opt_Class::OPT_COMPONENT, 'opt:myComponent', 'Extra_Mock_Component');
$tpl->register(Opt_Class::OPT_BLOCK, 'opt:myBlock', 'Extra_Mock_Block');
} // end configure();

/**
* Provides the list of test cases.
* @return array
*/
public static function dataProvider()
{
return array(0 =>
array('Selector/selector_basic.txt'),
array('Selector/selector_test.txt'),
array('Selector/selector_show.txt'),
array('Selector/selector_show_test.txt'),
array('Selector/selector_else.txt'),
array('Selector/selector_multiple_else.txt'),
array('Selector/selector_separator.txt'),
array('Selector/selector_attribute.txt'),
);
} // end dataProvider();

/**
* @dataProvider dataProvider
* @runInSeparateProcess
*/
public function testInstructions($testCase)
{
return $this->_checkTest(dirname(__FILE__).'/Tests/'.$testCase);
} // end testInstructions();
} // end Package_Instruction_SelectorTest;
19 changes: 0 additions & 19 deletions tests/Package/Instruction/Tests/Selector/selector_6.txt

This file was deleted.

15 changes: 0 additions & 15 deletions tests/Package/Instruction/Tests/Selector/selector_7.txt

This file was deleted.

Expand Up @@ -2,10 +2,10 @@ The test checks the opt:selector attribute.

>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<opt:root>
<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<div opt:selector="sect">
<opt:foo>FOO: {$sect.val1},{$sect.val2}</opt:foo>
<opt:bar>BAR: {$sect.val1},{$sect.val2}</opt:bar>
<opt:equals value="foo">FOO: {$sect.val1},{$sect.val2}</opt:equals>
<opt:equals value="bar">BAR: {$sect.val1},{$sect.val2}</opt:equals>
</div>
</opt:root>

Expand Down
Expand Up @@ -2,10 +2,10 @@ The test checks the opt:selector instruction.

>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<opt:root>
<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:selector name="sect">
<opt:foo>FOO: {$sect.val1},{$sect.val2}</opt:foo>
<opt:bar>BAR: {$sect.val1},{$sect.val2}</opt:bar>
<opt:equals value="foo">FOO: {$sect.val1},{$sect.val2}</opt:equals>
<opt:equals value="bar">BAR: {$sect.val1},{$sect.val2}</opt:equals>
</opt:selector>
</opt:root>

Expand Down
19 changes: 19 additions & 0 deletions tests/Package/Instruction/Tests/Selector/selector_else.txt
@@ -0,0 +1,19 @@
The test checks the opt:selector instruction with opt:else.

>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:selector name="sect">
<opt:equals value="foo">FOO: {$sect.val1},{$sect.val2}</opt:equals>
<opt:equals value="bar">BAR: {$sect.val1},{$sect.val2}</opt:equals>
<opt:else>NO DATA</opt:else>
</opt:selector>
</opt:root>

>>>>expected.txt
OUTPUT

>>>>result.txt
NO DATA

>>>>data.php
@@ -0,0 +1,15 @@
Multiple opt:else should be punished.

>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:selector name="sect">
<opt:equals value="foo">FOO: {$sect.val1},{$sect.val2}</opt:equals>
<opt:equals value="bar">BAR: {$sect.val1},{$sect.val2}</opt:equals>
<opt:else>NO DATA</opt:else>
<opt:else>NO DATA</opt:else>
</opt:selector>
</opt:root>

>>>>expected.txt
Opt_Instruction_Exception
Expand Up @@ -2,11 +2,11 @@ Test, whether the instruction works with separators given as tags.

>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<opt:root>
<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:selector name="sect">
<opt:separator>,</opt:separator>
<opt:foo>FOO: {$sect.val1},{$sect.val2}</opt:foo>
<opt:bar>BAR: {$sect.val1},{$sect.val2}</opt:bar>
<opt:equals value="foo">FOO: {$sect.val1},{$sect.val2}</opt:equals>
<opt:equals value="bar">BAR: {$sect.val1},{$sect.val2}</opt:equals>
</opt:selector>
</opt:root>

Expand Down
@@ -1,13 +1,13 @@
The same, as test selector_1, but together with OPT:SHOW
The same, as selector_basic, but together with OPT:SHOW

>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<opt:root>
<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:show name="sect">
START
<opt:selector>
<opt:foo>FOO: {$sect.val1},{$sect.val2}</opt:foo>
<opt:bar>BAR: {$sect.val1},{$sect.val2}</opt:bar>
<opt:equals value="foo">FOO: {$sect.val1},{$sect.val2}</opt:equals>
<opt:equals value="bar">BAR: {$sect.val1},{$sect.val2}</opt:equals>
</opt:selector>
END
</opt:show>
Expand Down
@@ -1,13 +1,13 @@
The same, as test selector_2, but together with OPT:SHOW
The same, as selector_test, but together with OPT:SHOW

>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<opt:root>
<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:show name="sect" test="ajtem">
START
<opt:selector>
<opt:foo>FOO: {$sect.val1},{$sect.val2}</opt:foo>
<opt:bar>BAR: {$sect.val1},{$sect.val2}</opt:bar>
<opt:equals value="foo">FOO: {$sect.val1},{$sect.val2}</opt:equals>
<opt:equals value="bar">BAR: {$sect.val1},{$sect.val2}</opt:equals>
</opt:selector>
END
</opt:show>
Expand Down
Expand Up @@ -2,10 +2,10 @@ The test checks the opt:selector instruction and custom item name field

>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<opt:root>
<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:selector name="sect" test="ajtem">
<opt:foo>FOO: {$sect.val1},{$sect.val2}</opt:foo>
<opt:bar>BAR: {$sect.val1},{$sect.val2}</opt:bar>
<opt:equals value="foo">FOO: {$sect.val1},{$sect.val2}</opt:equals>
<opt:equals value="bar">BAR: {$sect.val1},{$sect.val2}</opt:equals>
</opt:selector>
</opt:root>

Expand Down

0 comments on commit 53043df

Please sign in to comment.