Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updating opt:grid to the OPT 2.1 specs.

  • Loading branch information...
commit d650527d92ef6dce27cff70c00369dd41fcbb4b1 1 parent c90085b
@zyxist zyxist authored
View
21 lib/Opt/Instruction/Grid.php
@@ -43,7 +43,8 @@ class Opt_Instruction_Grid extends Opt_Instruction_Section_Abstract
*/
public function configure()
{
- $this->_addInstructions(array('opt:grid', 'opt:gridelse', 'opt:item', 'opt:emptyItem'));
+ $this->_addInstructions(array('opt:grid', 'opt:item', 'opt:empty-item'));
+ $this->_addAmbiguous(array('opt:else' => 'opt:grid'));
} // end configure();
/**
@@ -67,21 +68,23 @@ protected function _processGrid(Opt_Xml_Node $node)
// Error checking
$itemNode = $node->getElementsExt('opt', 'item');
- $emptyItemNode = $node->getElementsExt('opt', 'emptyItem');
+ $emptyItemNode = $node->getElementsExt('opt', 'empty-item');
if(sizeof($itemNode) != 1)
{
- throw new Opt_InstructionTooManyItems_Exception('opt:item', 'opt:grid', 'One');
+ throw new Opt_Instruction_Exception('Too many opt:item elements within opt:grid: one required.');
}
if(sizeof($emptyItemNode) != 1)
{
- throw new Opt_InstructionTooManyItems_Exception('opt:emptyItem', 'opt:grid', 'One');
+ throw new Opt_Instruction_Exception('Too many opt:empty-item elements within opt:grid: one required.');
}
// Link those nodes to this section
$itemNode[0]->set('priv:section', $section);
$emptyItemNode[0]->set('priv:section', $section);
+ $emptyItemNode[0]->set('priv:valid', $section['format']->get('section:valid'));
+
// Code generation
$node->addAfter(Opt_Xml_Buffer::TAG_BEFORE, '$_'.$section['name'].'_rows = ceil('.$section['format']->get('section:count').' / '.$section['cols'].'); $_'.$section['name'].'_remain = ('.$section['cols'].
' - ('.$section['format']->get('section:count').' % '.$section['cols'].')) % '.$section['cols'].'; '.$section['format']->get('section:loopBefore').' '.$section['format']->get('section:reset').' '.
@@ -126,18 +129,18 @@ protected function _processItem(Opt_Xml_Node $node)
* @internal
* @param Opt_Xml_Element $node The recognized node.
*/
- protected function _processEmptyItem(Opt_Xml_Node $node)
+ protected function _processEmptyitem(Opt_Xml_Node $node)
{
if(is_null($node->get('priv:section')))
{
throw new Opt_InstructionInvalidLocation_Exception('opt:item', 'opt:grid');
}
$section = $node->get('priv:section');
- $node->addAfter(Opt_Xml_Buffer::TAG_BEFORE, ' if($_'.$section['name'].'_remain > 0 && !'.$section['format']->get('section:valid').') { for($_'.$section['name'].'_k = 0; $_'.$section['name'].'_k < $_'.$section['name'].'_remain; $_'.$section['name'].'_k++) { ');
+ $node->addAfter(Opt_Xml_Buffer::TAG_BEFORE, ' if($_'.$section['name'].'_remain > 0 && !'.$node->get('priv:valid').') { for($_'.$section['name'].'_k = 0; $_'.$section['name'].'_k < $_'.$section['name'].'_remain; $_'.$section['name'].'_k++) { ');
$node->addBefore(Opt_Xml_Buffer::TAG_AFTER, ' } } ');
$this->_process($node);
- } // end _processItem();
+ } // end _processEmptyitem();
/**
* Finishes the processing of the opt:grid tag.
@@ -177,7 +180,7 @@ protected function _postprocessItem(Opt_Xml_Element $node)
* @internal
* @param Opt_Xml_Element $node The recognized node.
*/
- protected function _processGridelse(Opt_Xml_Element $node)
+ protected function _processElse(Opt_Xml_Element $node)
{
$parent = $node->getParent();
if($parent instanceof Opt_Xml_Element && $parent->getXmlName() == 'opt:grid')
@@ -189,5 +192,5 @@ protected function _processGridelse(Opt_Xml_Element $node)
// $this->_deactivateSection($parent->get('sectionName'));
$this->_process($node);
}
- } // end _processGridelse();
+ } // end _processElse();
} // end Opt_Instruction_Grid;
View
4 tests/Package/Instruction/AllTests.php
@@ -18,7 +18,7 @@
require_once('ExtendTest.php');
require_once('ForTest.php');
//require_once('ForeachTest.php');
-//require_once('GridTest.php');
+require_once('GridTest.php');
require_once('IfTest.php');
require_once('IncludeTest.php');
//require_once('InsertTest.php');
@@ -60,7 +60,7 @@ public static function suite()
$suite->addTestSuite('Package_Instruction_ExtendTest');
$suite->addTestSuite('Package_Instruction_ForTest');
//$suite->addTestSuite('Package_Instruction_ForeachTest');
- //$suite->addTestSuite('Package_Instruction_GridTest');
+ $suite->addTestSuite('Package_Instruction_GridTest');
$suite->addTestSuite('Package_Instruction_IfTest');
$suite->addTestSuite('Package_Instruction_IncludeTest');
//$suite->addTestSuite('Package_Instruction_InsertTest');
View
61 tests/Package/Instruction/GridTest.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * The tests for opt:content instruction.
+ *
+ * @author Tomasz "Zyx" Jędrzejewski
+ * @copyright Copyright (c) 2009 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_Grid
+ * @runTestsInSeparateProcesses
+ */
+class Package_Instruction_GridTest 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('Grid/grid_basic.txt'),
+ array('Grid/grid_basic2.txt'),
+ array('Grid/grid_section_nested.txt'),
+ array('Grid/grid_section_nested2.txt'),
+ array('Grid/grid_section_nested3.txt'),
+ array('Grid/grid_snippets.txt'),
+ array('Grid/grid_snippets2.txt'),
+ array('Grid/grid_html.txt'),
+ array('Grid/grid_one_row.txt'),
+ );
+ } // end dataProvider();
+
+ /**
+ * @dataProvider dataProvider
+ * @runInSeparateProcess
+ */
+ public function testInstructions($testCase)
+ {
+ return $this->_checkTest(dirname(__FILE__).'/Tests/'.$testCase);
+ } // end testInstructions();
+} // end Package_Instruction_GridTest;
View
6 tests/Package/Instruction/Tests/Grid/grid_1.txt → tests/Package/Instruction/Tests/Grid/grid_basic.txt
@@ -2,15 +2,15 @@ The test checks the basic opt:grid functionality.
>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
-<opt:root>
+<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:grid name="items" cols="3">
:ROW START
<opt:item>
{$items.foo}
</opt:item>
-<opt:emptyItem>
+<opt:empty-item>
Empty
-</opt:emptyItem>
+</opt:empty-item>
:ROW END
</opt:grid>
</opt:root>
View
6 tests/Package/Instruction/Tests/Grid/grid_2.txt → tests/Package/Instruction/Tests/Grid/grid_basic2.txt
@@ -2,15 +2,15 @@ The test checks the basic opt:grid functionality.
>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
-<opt:root>
+<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:grid name="items" cols="3">
:ROW START
<opt:item>
{$items.foo}
</opt:item>
-<opt:emptyItem>
+<opt:empty-item>
Empty
-</opt:emptyItem>
+</opt:empty-item>
:ROW END
</opt:grid>
</opt:root>
View
4 tests/Package/Instruction/Tests/Grid/grid_8.txt → tests/Package/Instruction/Tests/Grid/grid_html.txt
@@ -2,14 +2,14 @@ The test checks the opt:grid cooperation with HTML tags.
>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
-<opt:root>
+<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<table>
<opt:grid name="items" cols="3">
<tr>
<opt:item>
<td>{$items.foo}</td>
</opt:item>
-<opt:emptyItem><td></td></opt:emptyItem>
+<opt:empty-item><td></td></opt:empty-item>
</tr>
</opt:grid>
</table>
View
6 tests/Package/Instruction/Tests/Grid/grid_9.txt → ...s/Package/Instruction/Tests/Grid/grid_one_row.txt
@@ -2,15 +2,15 @@ The test checks the basic opt:grid functionality with only one row.
>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
-<opt:root>
+<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:grid name="items" cols="3">
:ROW START
<opt:item>
{$items.foo}
</opt:item>
-<opt:emptyItem>
+<opt:empty-item>
Empty
-</opt:emptyItem>
+</opt:empty-item>
:ROW END
</opt:grid>
</opt:root>
View
8 tests/Package/Instruction/Tests/Grid/grid_3.txt → ...ge/Instruction/Tests/Grid/grid_section_nested.txt
@@ -2,7 +2,7 @@ Test whether the section is started in a valid place.
>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
-<opt:root>
+<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:grid name="items" cols="3">
:ROW START
<opt:section name="foo" parent="items">
@@ -10,9 +10,9 @@ Test whether the section is started in a valid place.
<opt:item>
{$items.foo}
</opt:item>
-<opt:emptyItem>
+<opt:empty-item>
Empty
-</opt:emptyItem>
+</opt:empty-item>
:ROW END
</opt:grid>
</opt:root>
@@ -31,4 +31,4 @@ $view->items = array(
);
>>>>expected.txt
-Opt_SectionNotFound_Exception
+Opt_Instruction_Section_Exception
View
8 tests/Package/Instruction/Tests/Grid/grid_4.txt → ...e/Instruction/Tests/Grid/grid_section_nested2.txt
@@ -2,17 +2,17 @@ Test whether the section is started in a valid place.
>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
-<opt:root>
+<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:grid name="items" cols="3">
:ROW START
<opt:item>
{$items.foo}
</opt:item>
-<opt:emptyItem>
+<opt:empty-item>
Empty
<opt:section name="foo" parent="items">
</opt:section>
-</opt:emptyItem>
+</opt:empty-item>
:ROW END
</opt:grid>
</opt:root>
@@ -31,4 +31,4 @@ $view->items = array(
);
>>>>expected.txt
-Opt_SectionNotFound_Exception
+Opt_Instruction_Section_Exception
View
6 tests/Package/Instruction/Tests/Grid/grid_5.txt → ...e/Instruction/Tests/Grid/grid_section_nested3.txt
@@ -2,7 +2,7 @@ Test whether the section is started in a valid place.
>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
-<opt:root>
+<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:grid name="items" cols="3">
:ROW START
<opt:item>
@@ -10,9 +10,9 @@ Test whether the section is started in a valid place.
<opt:section name="foo" parent="items">
</opt:section>
</opt:item>
-<opt:emptyItem>
+<opt:empty-item>
Empty
-</opt:emptyItem>
+</opt:empty-item>
:ROW END
</opt:grid>
</opt:root>
View
6 tests/Package/Instruction/Tests/Grid/grid_6.txt → .../Package/Instruction/Tests/Grid/grid_snippets.txt
@@ -2,7 +2,7 @@ Test if the grid works with snippets.
>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
-<opt:root>
+<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:snippet name="snip">
:ROW START
<opt:item>
@@ -10,9 +10,9 @@ Test if the grid works with snippets.
<opt:section name="foo" parent="items">
</opt:section>
</opt:item>
-<opt:emptyItem>
+<opt:empty-item>
Empty
-</opt:emptyItem>
+</opt:empty-item>
:ROW END
</opt:snippet>
<opt:grid name="items" cols="3" opt:use="snip">
View
6 tests/Package/Instruction/Tests/Grid/grid_7.txt → ...Package/Instruction/Tests/Grid/grid_snippets2.txt
@@ -2,7 +2,7 @@ Test if the grid works with snippets - part two.
>>>>templates/test.tpl
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
-<opt:root>
+<opt:root xmlns:opt="http://xml.invenzzia.org/opt">
<opt:snippet name="snip">
FOO:{$snip.foo}
</opt:snippet>
@@ -10,9 +10,9 @@ FOO:{$snip.foo}
:ROW START
<opt:item opt:use="snip">
</opt:item>
-<opt:emptyItem>
+<opt:empty-item>
Empty
-</opt:emptyItem>
+</opt:empty-item>
:ROW END
</opt:grid>
</opt:root>
Please sign in to comment.
Something went wrong with that request. Please try again.