/** * @covers PhCompile\Template\Directive\NgRepeat::compile * @dataProvider repeatSpectialPropertiesProvider */ public function testRepeatSpecialProperties($expression, $expectedArray) { $this->scope->setData(array('bar' => array(1, 2, 3, 4, 5, 6))); $document = Utils::loadHTML('<span ng-repeat="n in bar">{{' . $expression . '}}</span>'); $element = $document->getElementsByTagName('span')->item(0); $renderClass = $this->phCompile->getConfig('compile.class'); $renderAttr = $this->phCompile->getConfig('compile.attr'); $this->ngRepeat->compile($element, $this->scope); $compiledHtml = Utils::saveHTML($document); $expectedHtml = '<span ng-repeat="n in bar" class="ng-hide">{{' . $expression . '}}</span>'; for ($i = 0; $i < 6; $i++) { $expectedHtml .= '<span class="' . $renderClass . '"><span ' . $renderAttr . '="' . $expression . '">' . $expectedArray[$i] . '</span></span>'; } $this->assertSame($expectedHtml, $compiledHtml); }
/** * Finds and compiles expressions in template's HTML. */ protected function compileExpressions() { $foundExpressions = array(); $renderAttribute = $this->phCompile->getConfig('compile.attr'); $expression = new Expression($this->phCompile); /** * Find all {{}} expressions. */ preg_match_all('/{{([^}]+)}}/', $this->html, $foundExpressions); foreach ($foundExpressions[1] as $foundExpression) { /** * Render and cover with span for easy client-site reverting. */ $renderedExpression = $expression->compile($foundExpression, $this->scope); $renderedExpression = '<span ' . $renderAttribute . '="' . $foundExpression . '">' . $renderedExpression . '</span>'; /** * Replace {{}} expression with rendered value. */ $this->html = str_replace('{{' . $foundExpression . '}}', $renderedExpression, $this->html); } }
/** * @covers PhCompile\PhCompile::addDefaultDirectives * @covers PhCompile\PhCompile::__construct * @depends testGetDirectives */ public function testNoDefaultDirectives() { $config = array('directive' => array('defaults' => false)); $phCompile = new PhCompile($config); $this->assertEmpty($phCompile->getDirectives()); }