forked from minkphp/driver-testsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContentTest.php
95 lines (76 loc) · 3.29 KB
/
ContentTest.php
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace Behat\Mink\Tests\Driver\Basic;
use Behat\Mink\Tests\Driver\TestCase;
final class ContentTest extends TestCase
{
public function testOuterHtml(): void
{
$this->getSession()->visit($this->pathTo('/index.html'));
$element = $this->getAssertSession()->elementExists('css', '.travers');
$this->assertEquals(
"<div class=\"travers\">\n <div class=\"sub\">el1</div>\n" .
" <div class=\"sub\">el2</div>\n <div class=\"sub\">\n" .
" <a href=\"some_url\">some <strong>deep</strong> url</a>\n" .
" </div>\n </div>",
$element->getOuterHtml()
);
}
public function testGetText(): void
{
$this->getSession()->visit($this->pathTo('/index.html'));
$element = $this->getAssertSession()->elementExists('css', '.get-text-trim');
/*
* Tests, these things:
* - <br> gets replaced with a space
* - spaces around the text are trimmed
* - are replaced with " " (non-breakable space) and then with " " (regular space)
*/
$this->assertEquals('line 2: text inside div line 3:', $element->getText());
}
public function testDumpingEmptyElements(): void
{
$this->getSession()->visit($this->pathTo('/index.html'));
$element = $this->getAssertSession()->elementExists('css', '#empty');
$this->assertEquals(
'An empty <em></em> tag should be rendered with both open and close tags.',
trim($element->getHtml())
);
}
/**
* @dataProvider getAttributeDataProvider
*/
public function testGetAttribute(string $attributeName, ?string $attributeValue): void
{
$this->getSession()->visit($this->pathTo('/index.html'));
$element = $this->getSession()->getPage()->findById('attr-elem[' . $attributeName . ']');
$this->assertNotNull($element);
$this->assertSame($attributeValue, $element->getAttribute($attributeName));
}
/**
* @return iterable<array{string, mixed}>
*/
public static function getAttributeDataProvider(): iterable
{
return [
['with-value', 'some-value'],
['without-value', ''],
['with-empty-value', ''],
['with-missing', null],
];
}
public function testHtmlDecodingNotPerformed(): void
{
$session = $this->getSession();
$webAssert = $this->getAssertSession();
$session->visit($this->pathTo('/html_decoding.html'));
$page = $session->getPage();
$span = $webAssert->elementExists('css', 'span');
$input = $webAssert->elementExists('css', 'input');
$expectedHtml = '<span custom-attr="&">some text</span>';
$this->assertStringContainsString($expectedHtml, $page->getHtml(), '.innerHTML is returned as-is');
$this->assertStringContainsString($expectedHtml, $page->getContent(), '.outerHTML is returned as-is');
$this->assertEquals('&', $span->getAttribute('custom-attr'), '.getAttribute value is decoded');
$this->assertEquals('&', $input->getAttribute('value'), '.getAttribute value is decoded');
$this->assertEquals('&', $input->getValue(), 'node value is decoded');
}
}