load() public static method

If $actual is already a DOMDocument, it is returned with no changes. Otherwise, $actual is loaded into a new DOMDocument as either HTML or XML, depending on the value of $isHtml. Note: prior to PHPUnit 3.3.0, this method loaded a file and not a string as it currently does. To load a file into a DOMDocument, use loadFile() instead.
Author: Mike Naberezny (mike@maintainable.com)
Author: Derek DeVries (derek@maintainable.com)
public static load ( string | DOMDocument $actual, boolean $isHtml = FALSE, string $filename = '' ) : DOMDocument
$actual string | DOMDocument
$isHtml boolean
$filename string
return DOMDocument
コード例 #1
0
ファイル: base_testcase.php プロジェクト: evltuma/moodle
 /**
  * Note: we are overriding this method to remove the deprecated error
  * @see https://tracker.moodle.org/browse/MDL-47129
  *
  * @param  array   $matcher
  * @param  string  $actual
  * @param  string  $message
  * @param  boolean $ishtml
  *
  * @deprecated 3.0
  */
 public static function assertNotTag($matcher, $actual, $message = '', $ishtml = true)
 {
     $dom = PHPUnit_Util_XML::load($actual, $ishtml);
     $tags = self::findNodes($dom, $matcher, $ishtml);
     $matched = count($tags) > 0 && $tags[0] instanceof DOMNode;
     self::assertFalse($matched, $message);
 }
コード例 #2
0
ファイル: PageTest.php プロジェクト: nickimproove/magento2
 public function testToOptionArray()
 {
     $this->dispatch('backend/admin/system_config/edit/section/admin');
     $dom = PHPUnit_Util_XML::load($this->getResponse()->getBody(), true);
     $select = $dom->getElementById('admin_startup_menu_item_id');
     $this->assertNotEmpty($select, 'Startup Page select missed');
     $options = $select->getElementsByTagName('option');
     $optionsCount = $options->length;
     $this->assertGreaterThan(0, $optionsCount, 'There must be present menu items at the admin backend');
     $this->assertEquals('Dashboard', $options->item(0)->nodeValue, 'First element is not Dashboard');
     $this->assertContains('Configuration', $options->item($optionsCount - 1)->nodeValue);
 }
コード例 #3
0
ファイル: Assert.php プロジェクト: karnurik/zf2-turtorial
 /**
  * This assertion is the exact opposite of assertTag().
  *
  * Rather than asserting that $matcher results in a match, it asserts that
  * $matcher does not match.
  *
  * @param array  $matcher
  * @param string $actual
  * @param string $message
  * @param bool   $isHtml
  * @since  Method available since Release 3.3.0
  * @author Mike Naberezny <*****@*****.**>
  * @author Derek DeVries <*****@*****.**>
  * @deprecated
  */
 public static function assertNotTag($matcher, $actual, $message = '', $isHtml = true)
 {
     trigger_error(__METHOD__ . ' is deprecated', E_USER_DEPRECATED);
     $dom = PHPUnit_Util_XML::load($actual, $isHtml);
     $tags = PHPUnit_Util_XML::findNodes($dom, $matcher, $isHtml);
     $matched = count($tags) > 0 && $tags[0] instanceof DOMNode;
     self::assertFalse($matched, $message);
 }
コード例 #4
0
 /**
  * @param array $matcher
  * @param string $actual
  * @param bool $isHtml
  *
  * @return bool
  */
 private static function tagMatch($matcher, $actual, $isHtml = true)
 {
     $dom = PHPUnit_Util_XML::load($actual, $isHtml);
     $tags = PHPUnit_Util_XML::findNodes($dom, $matcher, $isHtml);
     return count($tags) > 0 && $tags[0] instanceof DOMNode;
 }
コード例 #5
0
 /**
  * Asserts that two XML documents are not equal.
  *
  * @param string $expectedXml
  * @param string $actualXml
  * @param string $message
  *
  * @since  Method available since Release 3.1.0
  */
 public static function assertXmlStringNotEqualsXmlString($expectedXml, $actualXml, $message = '')
 {
     $expected = PHPUnit_Util_XML::load($expectedXml);
     $actual = PHPUnit_Util_XML::load($actualXml);
     self::assertNotEquals($expected, $actual, $message);
 }
コード例 #6
0
ファイル: SeleniumTestCase.php プロジェクト: humansky/qframe
 /**
  * Runs a test from a Selenese (HTML) specification.
  *
  * @param string $filename
  * @access public
  */
 public function runSelenese($filename)
 {
     $document = PHPUnit_Util_XML::load($filename, TRUE);
     $xpath = new DOMXPath($document);
     $rows = $xpath->query('body/table/tbody/tr');
     foreach ($rows as $row) {
         $action = NULL;
         $arguments = array();
         $columns = $xpath->query('td', $row);
         foreach ($columns as $column) {
             if ($action === NULL) {
                 $action = $column->nodeValue;
             } else {
                 $arguments[] = $column->nodeValue;
             }
         }
         $this->__call($action, $arguments);
     }
 }
コード例 #7
0
ファイル: Configuration.php プロジェクト: xiplias/pails
 /**
  * Loads a PHPUnit configuration file.
  *
  * @param  string $filename
  */
 public function __construct($filename)
 {
     $this->document = PHPUnit_Util_XML::load($filename);
     $this->xpath = new DOMXPath($this->document);
 }
コード例 #8
0
ファイル: XMLTest.php プロジェクト: alvarobfdev/applog
 /**
  * @expectedException PHPUnit_Framework_Exception
  * @expectedExceptionMessage Could not load XML from boolean
  */
 public function testLoadBoolean()
 {
     PHPUnit_Util_XML::load(false);
 }
コード例 #9
0
 protected function equalValues()
 {
     // cyclic dependencies
     $book1 = new Book();
     $book1->author = new Author('Terry Pratchett');
     $book1->author->books[] = $book1;
     $book2 = new Book();
     $book2->author = new Author('Terry Pratchett');
     $book2->author->books[] = $book2;
     $object1 = new SampleClass(4, 8, 15);
     $object2 = new SampleClass(4, 8, 15);
     $storage1 = new SplObjectStorage();
     $storage1->attach($object1);
     $storage2 = new SplObjectStorage();
     $storage2->attach($object1);
     return array(array('a', 'A', 0, false, true), array(array('a' => 1, 'b' => 2), array('b' => 2, 'a' => 1)), array(array(1), array('1')), array(array(3, 2, 1), array(2, 3, 1), 0, true), array(2.3, 2.5, 0.5), array(array(2.3), array(2.5), 0.5), array(array(array(2.3)), array(array(2.5)), 0.5), array(new Struct(2.3), new Struct(2.5), 0.5), array(array(new Struct(2.3)), array(new Struct(2.5)), 0.5), array(1, 2, 1), array($object1, $object2), array($book1, $book2), array($storage1, $storage2), array(PHPUnit_Util_XML::load('<root></root>'), PHPUnit_Util_XML::load('<root/>')), array(PHPUnit_Util_XML::load('<root attr="bar"></root>'), PHPUnit_Util_XML::load('<root attr="bar"/>')), array(PHPUnit_Util_XML::load('<root><foo attr="bar"></foo></root>'), PHPUnit_Util_XML::load('<root><foo attr="bar"/></root>')), array(PHPUnit_Util_XML::load("<root>\n  <child/>\n</root>"), PHPUnit_Util_XML::load('<root><child/></root>')), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York'))), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 04:13:25', new DateTimeZone('America/New_York')), 10), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 04:14:40', new DateTimeZone('America/New_York')), 65), array(new DateTime('2013-03-29', new DateTimeZone('America/New_York')), new DateTime('2013-03-29', new DateTimeZone('America/New_York'))), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/Chicago'))), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 03:13:49', new DateTimeZone('America/Chicago')), 15), array(new DateTime('2013-03-30', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 23:00:00', new DateTimeZone('America/Chicago'))), array(new DateTime('2013-03-30', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 23:01:30', new DateTimeZone('America/Chicago')), 100), array(new DateTime('@1364616000'), new DateTime('2013-03-29 23:00:00', new DateTimeZone('America/Chicago'))), array(new DateTime('2013-03-29T05:13:35-0500'), new DateTime('2013-03-29T04:13:35-0600')), array(0, '0'), array('0', 0), array(2.3, '2.3'), array('2.3', 2.3), array((string) (1 / 3), 1 - 2 / 3), array(1 / 3, (string) (1 - 2 / 3)), array('string representation', new ClassWithToString()), array(new ClassWithToString(), 'string representation'));
 }
コード例 #10
0
 protected function equalValues()
 {
     // cyclic dependencies
     $book1 = new Book();
     $book1->author = new Author('Terry Pratchett');
     $book1->author->books[] = $book1;
     $book2 = new Book();
     $book2->author = new Author('Terry Pratchett');
     $book2->author->books[] = $book2;
     $object1 = new SampleClass(4, 8, 15);
     $object2 = new SampleClass(4, 8, 15);
     $storage1 = new SplObjectStorage();
     $storage1->attach($object1);
     $storage2 = new SplObjectStorage();
     $storage2->attach($object1);
     return [['a', 'A', 0, false, true], [['a' => 1, 'b' => 2], ['b' => 2, 'a' => 1]], [[1], ['1']], [[3, 2, 1], [2, 3, 1], 0, true], [2.3, 2.5, 0.5], [[2.3], [2.5], 0.5], [[[2.3]], [[2.5]], 0.5], [new Struct(2.3), new Struct(2.5), 0.5], [[new Struct(2.3)], [new Struct(2.5)], 0.5], [1, 2, 1], [$object1, $object2], [$book1, $book2], [$storage1, $storage2], [PHPUnit_Util_XML::load('<root></root>'), PHPUnit_Util_XML::load('<root/>')], [PHPUnit_Util_XML::load('<root attr="bar"></root>'), PHPUnit_Util_XML::load('<root attr="bar"/>')], [PHPUnit_Util_XML::load('<root><foo attr="bar"></foo></root>'), PHPUnit_Util_XML::load('<root><foo attr="bar"/></root>')], [PHPUnit_Util_XML::load("<root>\n  <child/>\n</root>"), PHPUnit_Util_XML::load('<root><child/></root>')], [new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York'))], [new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 04:13:25', new DateTimeZone('America/New_York')), 10], [new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 04:14:40', new DateTimeZone('America/New_York')), 65], [new DateTime('2013-03-29', new DateTimeZone('America/New_York')), new DateTime('2013-03-29', new DateTimeZone('America/New_York'))], [new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/Chicago'))], [new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 03:13:49', new DateTimeZone('America/Chicago')), 15], [new DateTime('2013-03-30', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 23:00:00', new DateTimeZone('America/Chicago'))], [new DateTime('2013-03-30', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 23:01:30', new DateTimeZone('America/Chicago')), 100], [new DateTime('@1364616000'), new DateTime('2013-03-29 23:00:00', new DateTimeZone('America/Chicago'))], [new DateTime('2013-03-29T05:13:35-0500'), new DateTime('2013-03-29T04:13:35-0600')], [0, '0'], ['0', 0], [2.3, '2.3'], ['2.3', 2.3], [(string) (1 / 3), 1 - 2 / 3], [1 / 3, (string) (1 - 2 / 3)], ['string representation', new ClassWithToString()], [new ClassWithToString(), 'string representation']];
 }
コード例 #11
0
ファイル: AssertTest.php プロジェクト: mrbadao/api-official
 protected function notEqualValues()
 {
     // cyclic dependencies
     $book1 = new Book();
     $book1->author = new Author('Terry Pratchett');
     $book1->author->books[] = $book1;
     $book2 = new Book();
     $book2->author = new Author('Terry Pratch');
     $book2->author->books[] = $book2;
     $book3 = new Book();
     $book3->author = 'Terry Pratchett';
     $book4 = new stdClass();
     $book4->author = 'Terry Pratchett';
     $object1 = new SampleClass(4, 8, 15);
     $object2 = new SampleClass(16, 23, 42);
     $object3 = new SampleClass(4, 8, 15);
     $storage1 = new SplObjectStorage();
     $storage1->attach($object1);
     $storage2 = new SplObjectStorage();
     $storage2->attach($object3);
     // same content, different object
     // cannot use $filesDirectory, because neither setUp() nor
     // setUpBeforeClass() are executed before the data providers
     $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'foo.xml';
     return array(array('a', 'b'), array('a', 'A'), array('9E6666666', '9E7777777'), array(1, 2), array(2, 1), array(2.3, 4.2), array(2.3, 4.2, 0.5), array(array(2.3), array(4.2), 0.5), array(array(array(2.3)), array(array(4.2)), 0.5), array(new Struct(2.3), new Struct(4.2), 0.5), array(array(new Struct(2.3)), array(new Struct(4.2)), 0.5), array(NAN, NAN), array(array(), array(0 => 1)), array(array(0 => 1), array()), array(array(0 => NULL), array()), array(array(0 => 1, 1 => 2), array(0 => 1, 1 => 3)), array(array('a', 'b' => array(1, 2)), array('a', 'b' => array(2, 1))), array(new SampleClass(4, 8, 15), new SampleClass(16, 23, 42)), array($object1, $object2), array($book1, $book2), array($book3, $book4), array(fopen($file, 'r'), fopen($file, 'r')), array($storage1, $storage2), array(PHPUnit_Util_XML::load('<root></root>'), PHPUnit_Util_XML::load('<bar/>')), array(PHPUnit_Util_XML::load('<foo attr1="bar"/>'), PHPUnit_Util_XML::load('<foo attr1="foobar"/>')), array(PHPUnit_Util_XML::load('<foo> bar </foo>'), PHPUnit_Util_XML::load('<foo />')), array(PHPUnit_Util_XML::load('<foo xmlns="urn:myns:bar"/>'), PHPUnit_Util_XML::load('<foo xmlns="urn:notmyns:bar"/>')), array(PHPUnit_Util_XML::load('<foo> bar </foo>'), PHPUnit_Util_XML::load('<foo> bir </foo>')), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/New_York'))), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/New_York')), 3500), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 05:13:35', new DateTimeZone('America/New_York')), 3500), array(new DateTime('2013-03-29', new DateTimeZone('America/New_York')), new DateTime('2013-03-30', new DateTimeZone('America/New_York'))), array(new DateTime('2013-03-29', new DateTimeZone('America/New_York')), new DateTime('2013-03-30', new DateTimeZone('America/New_York')), 43200), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/Chicago'))), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/Chicago')), 3500), array(new DateTime('2013-03-30', new DateTimeZone('America/New_York')), new DateTime('2013-03-30', new DateTimeZone('America/Chicago'))), array(new DateTime('2013-03-29T05:13:35-0600'), new DateTime('2013-03-29T04:13:35-0600')), array(new DateTime('2013-03-29T05:13:35-0600'), new DateTime('2013-03-29T05:13:35-0500')), array(new SampleClass(4, 8, 15), FALSE), array(FALSE, new SampleClass(4, 8, 15)), array(array(0 => 1, 1 => 2), FALSE), array(FALSE, array(0 => 1, 1 => 2)), array(array(), new stdClass()), array(new stdClass(), array()), array(0, 'Foobar'), array('Foobar', 0), array(3, acos(8)), array(acos(8), 3));
 }
コード例 #12
0
ファイル: yTest_Dom.php プロジェクト: rsaugier/ytest
 private function __construct($testCase, $html)
 {
     $this->testCase = $testCase;
     $this->doc = PHPUnit_Util_XML::load($html, true);
     $this->domxpath = new DOMXPath($this->doc);
 }
コード例 #13
0
ファイル: Functional.php プロジェクト: lerre/framework
 /**
  * CSS-style selector-based assertion that makes [[assertTag()]] look quite cumbersome.
  * The first argument is a string that is essentially a standard CSS selectors used to
  * match the element we want:
  *
  *  - `div`             : an element of type `div`
  *  - `div.class_nm`    : an element of type `div` whose class is `warning`
  *  - `div#myid`        : an element of type `div` whose ID equal to `myid`
  *  - `div[foo="bar"]`  : an element of type `div` whose `foo` attribute value is exactly
  *                        equal to `bar`
  *  - `div[foo~="bar"]` : an element of type `div` whose `foo` attribute value is a list
  *                        of space-separated values, one of which is exactly equal
  *                        to `bar`
  *  - `div[foo*="bar"]` : an element of type `div` whose `foo` attribute value contains
  *                        the substring `bar`
  *  - `div span`        : an span element descendant of a `div` element
  *  - `div > span`      : a span element which is a direct child of a `div` element
  *
  * We can also do combinations to any degree:
  *
  *  - `div#folder.open a[href="http://foo"][title="bar"].selected.big > span`
  *
  * The second argument determines what we're matching in the content or number of tags.
  * It can be one 4 options:
  *
  *  - `content`    : match the content of the tag
  *  - `true/false` : match if the tag exists/doesn't exist
  *  - `number`     : match a specific number of elements
  *  - `range`      : to match a range of elements, we can use an array with the options
  *                         `>` and `<`.
  *
  * {{code: php
  *     ...
  *     
  *     // There is an element with the id "binder_1" with the content "Test Foo"
  *     $this->assertSelect("#binder_1", "Test Foo");
  *     
  *     // There are 10 div elements with the class folder:
  *     $this->assertSelect("div.folder", 10);
  *     
  *     // There are more than 2, less than 10 li elements
  *     $this->assertSelect("ul > li", array('>' => 2, '<' => 10));
  *     
  *     // There are more than or exactly 2, less than or exactly 10 li elements
  *     $this->assertSelect("ul > li", array('>=' => 2, '<=' => 10));
  *     
  *     // The "#binder_foo" id exists
  *     $this->assertSelect('#binder_foo");
  *     $this->assertSelect('#binder_foo", true);
  *     
  *     // The "#binder_foo" id DOES NOT exist
  *     $this->assertSelect('#binder_foo", false);
  *     
  *     ...
  * }}
  *
  * @param   string  $selector
  * @param   mixed   $content
  * @param   boolean $exists
  * @param   string  $msg
  * @param   boolean $isHtml
  * @throws  Mad_Test_Exception
  */
 public function assertSelect($selector, $content = true, $exists = true, $msg = null, $isHtml = true)
 {
     if (!method_exists($this, 'assertSelectEquals')) {
         throw new Mad_Test_Exception('PHPUnit selector assertion support required');
     }
     // only parse response into dom once for better performance
     if ($this->_responseDom === null) {
         $body = $this->response->getBody();
         $this->_responseDom = PHPUnit_Util_XML::load($body, $isHtml);
     }
     if (is_string($content)) {
         if (preg_match('!^/.*/.?$!', $content)) {
             $this->assertSelectRegexp($selector, $content, $exists, $this->_responseDom, $msg, $isHtml);
         } else {
             $this->assertSelectEquals($selector, $content, $exists, $this->_responseDom, $msg, $isHtml);
         }
     } else {
         $this->assertSelectCount($selector, $content, $this->_responseDom, $msg, $isHtml);
     }
 }