コード例 #1
0
ファイル: Loop.php プロジェクト: OPL/Open-Power-Template
 /**
  * Processes the loop separator. The programmer must provide the
  * variable name that will be used to check if we need to apply
  * the separator, and the optional value of "separator" attribute
  * in the node attributes. The separator is added to the specified
  * XML node.
  *
  * If the node contains too many opt:separator tags, an exception
  * is thrown.
  *
  * @param string $varname The internal variable name
  * @param string $arg The value of "separator" attribute
  * @param Opt_Xml_Scannable $node The node the separator will be added to.
  * @throws Opt_InstructionTooManyItems_Exception
  */
 public function processSeparator($varname, $arg, Opt_Xml_Scannable $node)
 {
     $items = $node->getElementsByTagNameNS('opt', 'separator', false);
     switch (sizeof($items)) {
         case 1:
             // Move this node to the beginning
             $node->removeChild($items[0]);
             $node->insertBefore($items[0], 0);
             $this->_process($items[0]);
             $items[0]->set('hidden', false);
             // Add PHP code
             $node->addBefore(Opt_Xml_Buffer::TAG_BEFORE, ' ' . $varname . ' = 0;');
             $items[0]->addBefore(Opt_Xml_Buffer::TAG_BEFORE, 'if(' . $varname . ' == 1){');
             $items[0]->addAfter(Opt_Xml_Buffer::TAG_AFTER, '}else{ ' . $varname . ' = 1; }');
             break;
         case 0:
             if (!is_null($arg)) {
                 $node->addBefore(Opt_Xml_Buffer::TAG_BEFORE, $varname . ' = 0;');
                 $node->addBefore(Opt_Xml_Buffer::TAG_CONTENT_BEFORE, 'if(' . $varname . ' == 1){ echo ' . $arg . '; }else{ ' . $varname . ' = 1; }');
             }
             break;
         default:
             throw new Opt_InstructionTooManyItems_Exception('opt:separator', $node->getXmlName(), 'Zero or one');
     }
 }
コード例 #2
0
 /**
  * Skip this test due to a bug in PHPUnit.
  *
  * @skip
  * @covers Opt_Xml_Scannable::insertBefore
  */
 public function testInsertBefore()
 {
     $mock = array(0 => $this->getMock('Opt_Xml_Node'));
     $mock[0]->expects($this->exactly(1))->method('setParent')->with($this->isInstanceOf('Opt_Xml_Scannable'));
     $mock[1] = $this->getMock('Opt_Xml_Node');
     $mock[1]->expects($this->exactly(1))->method('setParent')->with($this->isInstanceOf('Opt_Xml_Scannable'));
     $mock[2] = $this->getMock('Opt_Xml_Node');
     $mock[2]->expects($this->exactly(1))->method('setParent')->with($this->isInstanceOf('Opt_Xml_Scannable'));
     $this->_obj->appendChild($mock[0]);
     $this->_obj->appendChild($mock[1]);
     $this->_obj->insertBefore($mock[2], 1);
     $suggestedOutput = array(0 => $mock[0], $mock[2], $mock[1]);
     $i = 0;
     foreach ($this->_obj as $obj) {
         $this->assertSame($suggestedOutput[$i], $obj);
         $i++;
     }
 }