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()); }
/** * @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()); }
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)); }
/** * 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; }
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; }
/** * @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()); }
/** * @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()); }
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); }