public function testWithPrerender()
 {
     $elementString = $this->react->render('Alert', ['name' => 'react-laravel'], ['prerender' => true]);
     $wrapperElement = TestHelpers::stringToElement($elementString);
     $this->assertEquals('Hello, react-laravel', $wrapperElement->textContent);
     $expectedElement = TestHelpers::stringToElement('<div><span>Hello, </span><strong>react-laravel</strong></div>');
     $elementWithoutAttributes = TestHelpers::removeAttributes($wrapperElement->childNodes->item(0));
     $this->assertEquals(TestHelpers::innerHTML($expectedElement), TestHelpers::innerHTML($elementWithoutAttributes));
 }
示例#2
0
 public static function removeAttributes($node)
 {
     $newNode = $node->cloneNode(true);
     if ($node->hasAttributes()) {
         $attributes = $node->attributes;
         foreach ($attributes as $i => $attr) {
             $newNode->removeAttribute($attr->name);
         }
     }
     if ($newNode->hasChildNodes()) {
         $childNodes = $newNode->childNodes;
         for ($i = 0; $i < $childNodes->length; $i++) {
             $child = $childNodes->item($i);
             $newNode->replaceChild(TestHelpers::removeAttributes($child), $child);
         }
     }
     return $newNode;
 }