0); $changeSet->alterHtml('~/foo.html', function (\phpQueryObject $doc, $file) use (&$counts) { $counts[$file]++; $doc->find('.foo')->after('
world
'); }); $changeSet->alterHtml('~/f*.html', function (\phpQueryObject $doc, $file) use (&$counts) { $counts[$file]++; $doc->find('.bar')->after('cruel world
'); }); $changeSet->alterHtml('/path/does/not/exist.html', function(\phpQueryObject $doc) { throw new \Exception("This should not be called. The file does not exist!"); }); $results = ChangeSet::applyResourceFilters(array($changeSet), 'partials', array( '~/foo.html' => 'Hello
', )); $this->assertHtmlEquals( 'Hello
world
cruel world
', $results['~/foo.html'] ); $this->assertEquals(2, $counts['~/foo.html']); } /** * Insert content using append() and prepend(). */ public function testAppendPrepend() { $changeSet = ChangeSet::create(__FUNCTION__); $counts = array('~/foo.html' => 0); $changeSet->alterHtml('~/foo.html', function (\phpQueryObject $doc, $file) use (&$counts) { $counts[$file]++; $doc->find('.foo')->append('world
'); }); $changeSet->alterHtml('~/*.html', function (\phpQueryObject $doc, $file) use (&$counts) { $counts[$file]++; $doc->find('.bar')->prepend('Cruel world,'); }); $changeSet->alterHtml('/path/does/not/exist.html', function(\phpQueryObject $doc) { throw new \Exception("This should not be called. The file does not exist!"); }); $originals = array( '~/foo.html' => 'Hello
', ); $results = ChangeSet::applyResourceFilters(array($changeSet), 'partials', $originals); $this->assertHtmlEquals( 'Hello
world
', $results['~/foo.html'] ); $this->assertEquals(2, $counts['~/foo.html']); } protected function assertHtmlEquals($expected, $actual, $message = '') { $expected = preg_replace(';>[ \r\n\t]+;', '>', $expected); $actual = preg_replace(';>[ \r\n\t]+;', '>', $actual); $this->assertEquals($expected, $actual, $message); } }