Skip to content

Commit 5d85a3e

Browse files
committed
Added UT for getDOM()
1 parent d0df783 commit 5d85a3e

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ $headlessChromer = new HeadlessChrome();
158158
$headlessChromer->setBinaryPath('C:\Program Files (x86)\Google\Chrome\Application\chrome');
159159
$headlessChromer->setOutputDirectory(__DIR__);
160160
$headlessChromer->setHTMLFile(__DIR__ . '\assets\HTMLFile.html');
161+
161162
var_dump($headlessChromer->getDOM());
162163
```
163164

tests/HeadlessChromeTestSuite.php

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,48 @@
33
use daandesmedt\PHPHeadlessChrome\HeadlessChrome;
44
use PHPUnit\Framework\TestCase;
55

6-
final class HeadlessChromeTestSuite extends TestCase{
6+
final class HeadlessChromeTestSuite extends TestCase
7+
{
78

89
protected $binaryPath = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe';
910
protected $url = 'http://www.google.be';
1011
protected $ouputDirectory = 'C:/output/headlesschrome';
1112

1213

13-
public function testConstructor(){
14+
public function testConstructor()
15+
{
1416
$headlessChromer = new HeadlessChrome($this->url, $this->binaryPath);
1517
$this->assertEquals($this->url, $headlessChromer->getUrl());
1618
$this->assertEquals($this->binaryPath, $headlessChromer->getBinaryPath());
1719
}
1820

1921

20-
public function testSetBinaryPath() {
22+
public function testSetBinaryPath()
23+
{
2124
$headlessChromer = new HeadlessChrome();
2225
$headlessChromer->setBinaryPath($this->binaryPath);
2326
$this->assertEquals($this->binaryPath, $headlessChromer->getBinaryPath());
2427
}
2528

2629

27-
public function testSetURL() {
30+
public function testSetURL()
31+
{
2832
$headlessChromer = new HeadlessChrome();
2933
$headlessChromer->setUrl($this->url);
3034
$this->assertEquals($this->url, $headlessChromer->getUrl());
3135
}
3236

3337

34-
public function testSetOutputDirectory() {
38+
public function testSetOutputDirectory()
39+
{
3540
$headlessChromer = new HeadlessChrome();
3641
$headlessChromer->setOutputDirectory($this->ouputDirectory);
3742
$this->assertEquals(realpath($this->ouputDirectory), $headlessChromer->getOutputDirectory());
3843
}
3944

4045

41-
public function testSetArguments() {
46+
public function testSetArguments()
47+
{
4248
$arguments = [
4349
'--headless' => '',
4450
'--disable-gpu' => '',
@@ -54,7 +60,8 @@ public function testSetArguments() {
5460
}
5561

5662

57-
public function testSetArgumentsEmpty() {
63+
public function testSetArgumentsEmpty()
64+
{
5865
$arguments = [
5966
'' => '',
6067
' ' => ' ',
@@ -68,7 +75,8 @@ public function testSetArgumentsEmpty() {
6875
}
6976

7077

71-
public function testSetArgument() {
78+
public function testSetArgument()
79+
{
7280
$arguments = [
7381
'--headless' => '',
7482
'--disable-gpu' => '',
@@ -77,47 +85,59 @@ public function testSetArgument() {
7785
'--added-argument=' => 'value',
7886
];
7987
$headlessChromer = new HeadlessChrome();
80-
$headlessChromer->setArgument('--added-argument','value');
88+
$headlessChromer->setArgument('--added-argument', 'value');
8189
foreach ($arguments as $argument => $value) {
8290
$this->assertArrayHasKey($argument, $headlessChromer->getArguments());
8391
$this->assertEquals($value, $headlessChromer->getArguments()[$argument]);
8492
}
8593
}
86-
8794

88-
public function testWindowSize() {
95+
96+
public function testWindowSize()
97+
{
8998
$headlessChromer = new HeadlessChrome();
90-
$headlessChromer->setWindowSize(1024,2048);
99+
$headlessChromer->setWindowSize(1024, 2048);
91100
$this->assertEquals('1024,2048', $headlessChromer->getArguments()['--window-size=']);
92101
}
93102

94103

95-
public function testSetHTML() {
104+
public function testSetHTML()
105+
{
96106
$HTML = 'test HTML content';
97107
$headlessChromer = new HeadlessChrome();
98108
$headlessChromer->setHTML($HTML);
99109
$this->assertEquals('data:text/html,' . rawurlencode($HTML), $headlessChromer->getUrl());
100110
}
101111

102112

103-
public function testSetHTMLFile() {
113+
public function testSetHTMLFile()
114+
{
104115
$filePath = __DIR__ . '\..\examples\assets\HTMLFile.html';
105116
$headlessChromer = new HeadlessChrome();
106117
$headlessChromer->setHTMLFile($filePath);
107118
$this->assertEquals("file://$filePath", $headlessChromer->getUrl());
108119
}
109120

110-
public function testSetHTMLFileException() {
121+
public function testSetHTMLFileException()
122+
{
111123
$filePath = __DIR__ . '\HTMLFile.html';
112124
$headlessChromer = new HeadlessChrome();
113125
$this->setExpectedException(Exception::class);
114126
$headlessChromer->setHTMLFile($filePath);
115127
}
116128

117-
public function testUseMobile() {
129+
public function testUseMobile()
130+
{
118131
$headlessChromer = new HeadlessChrome();
119132
$headlessChromer->useMobile();
120133
$this->assertEquals('Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30', $headlessChromer->getArguments()['--user-agent=']);
121134
}
122135

123-
}
136+
public function testGetDOM()
137+
{
138+
$HTML = '<div>DOM</div>';
139+
$headlessChromer = new HeadlessChrome();
140+
$headlessChromer->setHTML($HTML);
141+
$this->assertEquals($headlessChromer->getDOM(), $HTML);
142+
}
143+
}

0 commit comments

Comments
 (0)