Exemple #1
0
 /**
  * @covers PhCompile\Template\Directive\NgClass::compile
  * @dataProvider compileExceptionProvider
  * @expectedException PhCompile\Template\Expression\InvalidExpressionException
  */
 public function testCompileException($scopeData, $classString)
 {
     $this->scope->setData($scopeData);
     $document = Utils::loadHTML('<span ng-class="' . $classString . '"></span>');
     $element = $document->getElementsByTagName('span')->item(0);
     $this->ngClass->compile($element, $this->scope);
 }
Exemple #2
0
 /**
  * @covers PhCompile\Template\Directive\NgValue::compile
  * @dataProvider compileProvider
  */
 public function testCompile($scopeData, $bindString, $expected)
 {
     $this->scope->setData($scopeData);
     $document = Utils::loadHTML('<span ng-value="' . $bindString . '"></span>');
     $element = $document->getElementsByTagName('span')->item(0);
     $compiledHtml = Utils::saveHTML($this->ngValue->compile($element, $this->scope)->ownerDocument);
     $expectedHtml = '<span ng-value="' . $bindString . '" value="' . $expected . '"></span>';
     $this->assertSame($expectedHtml, $compiledHtml);
 }
Exemple #3
0
 /**
  * @covers PhCompile\Template\Directive\NgHide::compile
  * @dataProvider compileProvider
  */
 public function testCompile($scopeData, $expression, $expectedClass)
 {
     $this->scope->setData($scopeData);
     $document = Utils::loadHTML('<span ng-hide="' . $expression . '" class=""></span>');
     $element = $document->getElementsByTagName('span')->item(0);
     $this->ngHide->compile($element, $this->scope);
     $renderedHtml = Utils::saveHTML($element->ownerDocument);
     $expectedHtml = '<span ng-hide="' . $expression . '" class="' . $expectedClass . '"></span>';
     $this->assertSame($expectedHtml, $renderedHtml);
 }
Exemple #4
0
 /**
  * @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);
 }
Exemple #5
0
 /**
  * Sets config given as array to config Scope object.
  * Existing elements in config's Scope will be overwritten.
  *
  * @param array $config Array containing new config.
  */
 public function setConfig(array $config)
 {
     $this->config->setData($config);
 }
Exemple #6
0
 /**
  * Sets special properties for given scope based on current ng-repeat cycle.
  *
  * @param Scope $scope Scope to set data to.
  * @param int $repeatCount Size of the array we iterate over.
  * @param int $repeatIndex Current index of the array we iterate over.
  * @return Scope Scope object with set values.
  */
 protected function setScopeSpecial(Scope $scope, $repeatCount, $repeatIndex)
 {
     $scopeData['$index'] = $repeatIndex;
     $scopeData['$first'] = $repeatIndex === 0;
     $scopeData['$last'] = $repeatIndex === $repeatCount - 1;
     $scopeData['$middle'] = !($scopeData['$first'] || $scopeData['$last']);
     $scopeData['$even'] = $repeatIndex % 2 === 0;
     $scopeData['$odd'] = !$scopeData['$even'];
     $scope->setData($scopeData);
     return $scope;
 }
Exemple #7
0
 /**
  * @covers PhCompile\Scope::hasData
  * @dataProvider hasDataProvider
  * @depends testGetData
  */
 public function testHasData($data, $accessString, $expected)
 {
     $this->scope->setData($data);
     $this->assertSame($expected, $this->scope->hasData($accessString));
 }