PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / vendor / sebastian / comparator / src / DOMNodeComparator.php
kubio / vendor / sebastian / comparator / src Last commit date
exceptions 1 year ago ArrayComparator.php 1 year ago Comparator.php 1 year ago ComparisonFailure.php 1 year ago DOMNodeComparator.php 1 year ago DateTimeComparator.php 1 year ago DoubleComparator.php 1 year ago ExceptionComparator.php 1 year ago Factory.php 1 year ago MockObjectComparator.php 1 year ago NumericComparator.php 1 year ago ObjectComparator.php 1 year ago ResourceComparator.php 1 year ago ScalarComparator.php 1 year ago SplObjectStorageComparator.php 1 year ago TypeComparator.php 1 year ago
DOMNodeComparator.php
94 lines
1 <?php declare(strict_types=1);
2 /*
3 * This file is part of sebastian/comparator.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10 namespace SebastianBergmann\Comparator;
11
12 use function sprintf;
13 use function strtolower;
14 use DOMDocument;
15 use DOMNode;
16 use ValueError;
17
18 /**
19 * Compares DOMNode instances for equality.
20 */
21 class DOMNodeComparator extends ObjectComparator
22 {
23 /**
24 * Returns whether the comparator can compare two values.
25 *
26 * @param mixed $expected The first value to compare
27 * @param mixed $actual The second value to compare
28 *
29 * @return bool
30 */
31 public function accepts($expected, $actual)
32 {
33 return $expected instanceof DOMNode && $actual instanceof DOMNode;
34 }
35
36 /**
37 * Asserts that two values are equal.
38 *
39 * @param mixed $expected First value to compare
40 * @param mixed $actual Second value to compare
41 * @param float $delta Allowed numerical distance between two values to consider them equal
42 * @param bool $canonicalize Arrays are sorted before comparison when set to true
43 * @param bool $ignoreCase Case is ignored when set to true
44 * @param array $processed List of already processed elements (used to prevent infinite recursion)
45 *
46 * @throws ComparisonFailure
47 */
48 public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false, array &$processed = [])/*: void*/
49 {
50 $expectedAsString = $this->nodeToText($expected, true, $ignoreCase);
51 $actualAsString = $this->nodeToText($actual, true, $ignoreCase);
52
53 if ($expectedAsString !== $actualAsString) {
54 $type = $expected instanceof DOMDocument ? 'documents' : 'nodes';
55
56 throw new ComparisonFailure(
57 $expected,
58 $actual,
59 $expectedAsString,
60 $actualAsString,
61 false,
62 sprintf("Failed asserting that two DOM %s are equal.\n", $type)
63 );
64 }
65 }
66
67 /**
68 * Returns the normalized, whitespace-cleaned, and indented textual
69 * representation of a DOMNode.
70 */
71 private function nodeToText(DOMNode $node, bool $canonicalize, bool $ignoreCase): string
72 {
73 if ($canonicalize) {
74 $document = new DOMDocument;
75
76 try {
77 @$document->loadXML($node->C14N());
78 } catch (ValueError $e) {
79 }
80
81 $node = $document;
82 }
83
84 $document = $node instanceof DOMDocument ? $node : $node->ownerDocument;
85
86 $document->formatOutput = true;
87 $document->normalizeDocument();
88
89 $text = $node instanceof DOMDocument ? $node->saveXML() : $document->saveXML($node);
90
91 return $ignoreCase ? strtolower($text) : $text;
92 }
93 }
94