|
5 | 5 | namespace Flow\ETL\Tests\Unit\Function; |
6 | 6 |
|
7 | 7 | use function Flow\ETL\DSL\{config, flow_context, ref, row}; |
8 | | -use Flow\ETL\Tests\FlowTestCase; |
| 8 | +use Dom\{HTMLDocument, HTMLElement}; |
| 9 | +use PHPUnit\Framework\Attributes\RequiresPhp; |
| 10 | +use PHPUnit\Framework\TestCase; |
9 | 11 |
|
10 | | -final class DOMElementAttributesCountTest extends FlowTestCase |
| 12 | +final class DOMElementAttributesCountTest extends TestCase |
11 | 13 | { |
12 | | - public function test_attributes_count_on_element_with_multiple_attributes() : void |
| 14 | + #[RequiresPhp('>= 8.4')] |
| 15 | + public function test_html_attributes_count_on_element_with_multiple_attributes() : void |
| 16 | + { |
| 17 | + $element = HTMLDocument::createFromString('<span data-attr="1" data-foo="2" data-bar="3">foobar</span>', \LIBXML_HTML_NOIMPLIED | \LIBXML_NOERROR); |
| 18 | + |
| 19 | + self::assertInstanceOf(HTMLElement::class, $element->documentElement); |
| 20 | + self::assertSame( |
| 21 | + 3, |
| 22 | + ref('value')->domElementAttributesCount()->eval( |
| 23 | + row(flow_context(config())->entryFactory()->create('value', $element->documentElement)) |
| 24 | + ) |
| 25 | + ); |
| 26 | + } |
| 27 | + |
| 28 | + #[RequiresPhp('>= 8.4')] |
| 29 | + public function test_html_attributes_count_on_element_with_one_attribute() : void |
| 30 | + { |
| 31 | + $element = HTMLDocument::createFromString('<span data-attr="1"">foobar</span>', \LIBXML_HTML_NOIMPLIED | \LIBXML_NOERROR); |
| 32 | + |
| 33 | + self::assertInstanceOf(HTMLElement::class, $element->documentElement); |
| 34 | + self::assertSame( |
| 35 | + 1, |
| 36 | + ref('value')->domElementAttributesCount()->eval( |
| 37 | + row(flow_context(config())->entryFactory()->create('value', $element->documentElement)) |
| 38 | + ) |
| 39 | + ); |
| 40 | + } |
| 41 | + |
| 42 | + #[RequiresPhp('>= 8.4')] |
| 43 | + public function test_html_attributes_count_on_element_with_zero_attributes() : void |
| 44 | + { |
| 45 | + $element = HTMLDocument::createFromString('<span>foobar</span>', \LIBXML_HTML_NOIMPLIED | \LIBXML_NOERROR); |
| 46 | + |
| 47 | + self::assertInstanceOf(HTMLElement::class, $element->documentElement); |
| 48 | + self::assertSame( |
| 49 | + 0, |
| 50 | + ref('value')->domElementAttributesCount()->eval( |
| 51 | + row(flow_context(config())->entryFactory()->create('value', $element->documentElement)) |
| 52 | + ) |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + public function test_xml_attributes_count_on_element_with_multiple_attributes() : void |
13 | 57 | { |
14 | 58 | $xml = new \DOMDocument(); |
15 | 59 | $xml->loadXML('<root><foo atr-01="1" atr-02="2" atr-03="3">bar</foo></root>'); |
16 | 60 |
|
17 | 61 | self::assertInstanceOf(\DOMElement::class, $xml->documentElement); |
18 | | - self::assertEquals( |
| 62 | + self::assertSame( |
19 | 63 | 3, |
20 | 64 | ref('value')->domElementAttributesCount()->eval( |
21 | 65 | row(flow_context(config())->entryFactory()->create('value', $xml->documentElement->firstChild)) |
22 | 66 | ) |
23 | 67 | ); |
24 | 68 | } |
25 | 69 |
|
26 | | - public function test_attributes_count_on_element_with_one_attribute() : void |
| 70 | + public function test_xml_attributes_count_on_element_with_one_attribute() : void |
27 | 71 | { |
28 | 72 | $xml = new \DOMDocument(); |
29 | 73 | $xml->loadXML('<root><foo baz="buz">bar</foo></root>'); |
30 | 74 |
|
31 | 75 | self::assertInstanceOf(\DOMElement::class, $xml->documentElement); |
32 | | - self::assertEquals( |
| 76 | + self::assertSame( |
33 | 77 | 1, |
34 | 78 | ref('value')->domElementAttributesCount()->eval( |
35 | 79 | row(flow_context(config())->entryFactory()->create('value', $xml->documentElement->firstChild)) |
36 | 80 | ) |
37 | 81 | ); |
38 | 82 | } |
39 | 83 |
|
40 | | - public function test_attributes_count_on_element_with_zero_attributes() : void |
| 84 | + public function test_xml_attributes_count_on_element_with_zero_attributes() : void |
41 | 85 | { |
42 | 86 | $xml = new \DOMDocument(); |
43 | 87 | $xml->loadXML('<root><foo>bar</foo></root>'); |
44 | 88 |
|
45 | 89 | self::assertInstanceOf(\DOMElement::class, $xml->documentElement); |
46 | | - self::assertEquals( |
| 90 | + self::assertSame( |
47 | 91 | 0, |
48 | 92 | ref('value')->domElementAttributesCount()->eval( |
49 | 93 | row(flow_context(config())->entryFactory()->create('value', $xml->documentElement->firstChild)) |
|
0 commit comments