object_dom.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --TEST--
  2. Test V8::executeString() : DOM object passed from PHP
  3. --SKIPIF--
  4. <?php
  5. if(!class_exists('DomDocument')) {
  6. die('skip');
  7. }
  8. require_once(dirname(__FILE__) . '/skipif.inc');
  9. ?>
  10. --FILE--
  11. <?php
  12. $JS = <<< EOT
  13. print('js1: ', PHP.test.length, "\\n");
  14. var elements = PHP.dom.getElementsByTagName('node');
  15. print('js2: ', elements.length, "\\n");
  16. var node = elements.item(0);
  17. print("hasChildNodes: "); var_dump(node.hasChildNodes());
  18. print("hasAttribute('class'): "); var_dump(node.hasAttribute('class'));
  19. //var_dump(node);
  20. EOT;
  21. $dom = new DomDocument();
  22. $dom->loadXML('<node class="test"/>');
  23. $elements = $dom->getElementsByTagName('node');
  24. echo 'php: ', $elements->length, "\n";
  25. $node = $elements->item(0);
  26. echo "hasChildNodes: "; var_dump($node->hasChildNodes());
  27. echo "hasAttribute('class'): "; var_dump($node->hasAttribute('class'));
  28. //var_dump($node);
  29. $a = new V8Js();
  30. $a->dom = $dom;
  31. $a->test = array( 'length' => 1 );
  32. $a->executeString($JS, "test.js");
  33. ?>
  34. ===EOF===
  35. --EXPECT--
  36. php: 1
  37. hasChildNodes: bool(false)
  38. hasAttribute('class'): bool(true)
  39. js1: 1
  40. js2: 1
  41. hasChildNodes: bool(false)
  42. hasAttribute('class'): bool(true)
  43. ===EOF===