File: node.php

package info (click to toggle)
php-nunomaduro-termwind 2.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,172 kB
  • sloc: php: 3,969; makefile: 34
file content (61 lines) | stat: -rw-r--r-- 2,033 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php

use Termwind\ValueObjects\Node;

it('it should return empty string for dom comment', function () {
    $node = new Node(new \DOMComment('You will not be able to see this text.'));

    expect($node->getAttribute('foo'))->toBe('');
});

it('it should return empty string for dom text', function () {
    $node = new Node(new \DOMText('bar'));

    expect($node->getAttribute('foo'))->toBe('');
});

it('it should return bar for dom element', function () {
    $doc = new \DOMDocument('1.0');
    $node = $doc->createElement('div');
    $el = $doc->appendChild($node);
    $el->setAttribute('foo', 'bar');
    $node = new Node($el);

    expect($node->getAttribute('foo'))->toBe('bar');
});

it('gets next sibling node with empty text', function () {
    $dom = new DOMDocument;

    $html = '<?xml encoding="UTF-8"><body><div></div>     <div></div></body>';
    $dom->loadHTML($html, LIBXML_COMPACT | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS | LIBXML_NOXMLDECL);

    $body = $dom->getElementsByTagName('body')->item(0);
    $node = new Node($body->firstChild);

    expect($node->getNextSibling()->getNextSibling())->toBeNull();
});

it('gets next sibling node with empty line', function () {
    $dom = new DOMDocument;

    $html = "<?xml encoding=\"UTF-8\"><body><div></div>\n<div></div></body>";
    $dom->loadHTML($html, LIBXML_COMPACT | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS | LIBXML_NOXMLDECL);

    $body = $dom->getElementsByTagName('body')->item(0);
    $node = new Node($body->firstChild);

    expect($node->getNextSibling()->getNextSibling())->toBeNull();
});

it('gets next sibling node with comment', function () {
    $dom = new DOMDocument;

    $html = '<?xml encoding="UTF-8"><body><div></div><!-- Hello world --><div></div></body>';
    $dom->loadHTML($html, LIBXML_COMPACT | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS | LIBXML_NOXMLDECL);

    $body = $dom->getElementsByTagName('body')->item(0);
    $node = new Node($body->firstChild);

    expect($node->getNextSibling()->getNextSibling())->toBeNull();
});