コード例 #1
0
ファイル: ReplaceTest.php プロジェクト: saxenap/Template
 public function testSimpleReplace()
 {
     $div = $this->dom->createElement('div', 'it does not matter');
     $span = $this->dom->createElement('span', 'it matters');
     $this->dom->appendChild($div);
     new Decorator($div, Adapter::factory($this->dom, $span));
     $this->assertContains('<span>it matters</span>', $this->dom->saveXML());
 }
コード例 #2
0
ファイル: AdapterTest.php プロジェクト: saxenap/Template
 /**
  * @dataProvider instances
  */
 public function testInstances($className, $content, $decorator)
 {
     $adapter = Adapter::factory($this->dom, $content);
     $className = 'Respect\\Template\\Adapters\\' . $className;
     $decorator = 'Respect\\Template\\Decorators\\' . $decorator;
     $this->assertInstanceOf($className, $adapter);
     $this->assertEquals($decorator, $adapter->getDecorator());
 }
コード例 #3
0
ファイル: HtmlElementTest.php プロジェクト: saxenap/Template
 public function testAdaptation()
 {
     $parent = $this->dom->createElement('div');
     $expected = $this->dom->createElement('ul');
     $base = H::ul();
     $adapter = Factory::factory($this->dom, $base);
     $this->assertInstanceOf('Respect\\Template\\Adapters\\HtmlElement', $adapter);
     $this->assertEquals($expected, $adapter->adaptTo($parent));
 }
コード例 #4
0
ファイル: Document.php プロジェクト: nickl-/Template
 /**
  * Replaces this dom content with the given array. 
  * The array structure is: $array['Css Selector to Eelement'] = 'content';
  * 
  * @param 	array 	            $data
  * @param   string[optional]    $decorator  Class to be used as decorator
  * @return 	Respect\Template\Document
  */
 public function decorate(array $data, $decorator = null)
 {
     foreach ($data as $selector => $with) {
         $adapter = Adapter::factory($this->getDom(), $with);
         $decorator = $decorator ?: $adapter->getDecorator();
         $query = new Query($this, $selector);
         new $decorator($query, $adapter);
     }
     return $this;
 }
コード例 #5
0
ファイル: A.php プロジェクト: nickl-/Template
 protected function getDomNode($data, DOMNode $parent)
 {
     $element = $this->createElement($parent, 'a');
     $element->setAttribute('href', $this->getProperty($data, 'href'));
     if ($this->hasProperty($data, 'innerHtml')) {
         $inner = $this->getProperty($data, 'innerHtml');
         $adapter = Adapter::factory($this->getDom(), $inner);
         new Append($element, $adapter);
     }
     return $element;
 }
コード例 #6
0
ファイル: CleanAppendTest.php プロジェクト: saxenap/Template
 /**
  * @dataProvider traversables
  */
 public function testInjectingOnAUl($with)
 {
     $ul = $this->dom->createElement('ul');
     for ($i = 3; $i > 0; $i--) {
         $ul->appendChild($this->dom->createElement('li', 'test'));
     }
     $this->dom->appendChild($ul);
     $this->assertTrue($ul->hasChildNodes());
     new Decorator(array($ul), Adapter::factory($this->dom, $with));
     $this->assertTrue($ul->hasChildNodes());
 }
コード例 #7
0
ファイル: AppendTest.php プロジェクト: saxenap/Template
 /**
  * @dataProvider strings
  */
 public function testWithSingleElement($with)
 {
     $doc = new DOMDocument('1.0', 'iso-8859-1');
     $node = $doc->createElement('div');
     $expect = '<div>' . $with . '</div>';
     $elements = array($node);
     $doc->appendChild($node);
     $this->assertFalse($node->hasChildNodes());
     new Append($elements, Adapter::factory($doc, $with));
     $this->assertTrue($node->hasChildNodes());
     $this->assertContains($expect, $doc->saveXml());
 }
コード例 #8
0
ファイル: ATest.php プロジェクト: saxenap/Template
 public function testAdaptationWithInnerHtml()
 {
     $std = new StdClass();
     $std->href = '#top';
     $std->innerHtml = 'Top';
     $adapter = A::factory($this->dom, $std);
     $this->assertInstanceOf('Respect\\Template\\Adapters\\A', $adapter);
     $to = $adapter->adaptTo($this->dom);
     $this->assertInstanceOf('DOMElement', $to);
     $this->assertTrue($to->hasAttribute('href'));
     $expected = $this->dom->createElement('a', 'Top');
     $expected->setAttribute('href', '#top');
     $this->assertEquals($expected, $to);
 }