3
3
use daandesmedt \PHPHeadlessChrome \HeadlessChrome ;
4
4
use PHPUnit \Framework \TestCase ;
5
5
6
- final class HeadlessChromeTestSuite extends TestCase{
6
+ final class HeadlessChromeTestSuite extends TestCase
7
+ {
7
8
8
9
protected $ binaryPath = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe ' ;
9
10
protected $ url = 'http://www.google.be ' ;
10
11
protected $ ouputDirectory = 'C:/output/headlesschrome ' ;
11
12
12
13
13
- public function testConstructor (){
14
+ public function testConstructor ()
15
+ {
14
16
$ headlessChromer = new HeadlessChrome ($ this ->url , $ this ->binaryPath );
15
17
$ this ->assertEquals ($ this ->url , $ headlessChromer ->getUrl ());
16
18
$ this ->assertEquals ($ this ->binaryPath , $ headlessChromer ->getBinaryPath ());
17
19
}
18
20
19
21
20
- public function testSetBinaryPath () {
22
+ public function testSetBinaryPath ()
23
+ {
21
24
$ headlessChromer = new HeadlessChrome ();
22
25
$ headlessChromer ->setBinaryPath ($ this ->binaryPath );
23
26
$ this ->assertEquals ($ this ->binaryPath , $ headlessChromer ->getBinaryPath ());
24
27
}
25
28
26
29
27
- public function testSetURL () {
30
+ public function testSetURL ()
31
+ {
28
32
$ headlessChromer = new HeadlessChrome ();
29
33
$ headlessChromer ->setUrl ($ this ->url );
30
34
$ this ->assertEquals ($ this ->url , $ headlessChromer ->getUrl ());
31
35
}
32
36
33
37
34
- public function testSetOutputDirectory () {
38
+ public function testSetOutputDirectory ()
39
+ {
35
40
$ headlessChromer = new HeadlessChrome ();
36
41
$ headlessChromer ->setOutputDirectory ($ this ->ouputDirectory );
37
42
$ this ->assertEquals (realpath ($ this ->ouputDirectory ), $ headlessChromer ->getOutputDirectory ());
38
43
}
39
44
40
45
41
- public function testSetArguments () {
46
+ public function testSetArguments ()
47
+ {
42
48
$ arguments = [
43
49
'--headless ' => '' ,
44
50
'--disable-gpu ' => '' ,
@@ -54,7 +60,8 @@ public function testSetArguments() {
54
60
}
55
61
56
62
57
- public function testSetArgumentsEmpty () {
63
+ public function testSetArgumentsEmpty ()
64
+ {
58
65
$ arguments = [
59
66
'' => '' ,
60
67
' ' => ' ' ,
@@ -68,7 +75,8 @@ public function testSetArgumentsEmpty() {
68
75
}
69
76
70
77
71
- public function testSetArgument () {
78
+ public function testSetArgument ()
79
+ {
72
80
$ arguments = [
73
81
'--headless ' => '' ,
74
82
'--disable-gpu ' => '' ,
@@ -77,47 +85,59 @@ public function testSetArgument() {
77
85
'--added-argument= ' => 'value ' ,
78
86
];
79
87
$ headlessChromer = new HeadlessChrome ();
80
- $ headlessChromer ->setArgument ('--added-argument ' ,'value ' );
88
+ $ headlessChromer ->setArgument ('--added-argument ' , 'value ' );
81
89
foreach ($ arguments as $ argument => $ value ) {
82
90
$ this ->assertArrayHasKey ($ argument , $ headlessChromer ->getArguments ());
83
91
$ this ->assertEquals ($ value , $ headlessChromer ->getArguments ()[$ argument ]);
84
92
}
85
93
}
86
-
87
94
88
- public function testWindowSize () {
95
+
96
+ public function testWindowSize ()
97
+ {
89
98
$ headlessChromer = new HeadlessChrome ();
90
- $ headlessChromer ->setWindowSize (1024 ,2048 );
99
+ $ headlessChromer ->setWindowSize (1024 , 2048 );
91
100
$ this ->assertEquals ('1024,2048 ' , $ headlessChromer ->getArguments ()['--window-size= ' ]);
92
101
}
93
102
94
103
95
- public function testSetHTML () {
104
+ public function testSetHTML ()
105
+ {
96
106
$ HTML = 'test HTML content ' ;
97
107
$ headlessChromer = new HeadlessChrome ();
98
108
$ headlessChromer ->setHTML ($ HTML );
99
109
$ this ->assertEquals ('data:text/html, ' . rawurlencode ($ HTML ), $ headlessChromer ->getUrl ());
100
110
}
101
111
102
112
103
- public function testSetHTMLFile () {
113
+ public function testSetHTMLFile ()
114
+ {
104
115
$ filePath = __DIR__ . '\..\examples\assets\HTMLFile.html ' ;
105
116
$ headlessChromer = new HeadlessChrome ();
106
117
$ headlessChromer ->setHTMLFile ($ filePath );
107
118
$ this ->assertEquals ("file:// $ filePath " , $ headlessChromer ->getUrl ());
108
119
}
109
120
110
- public function testSetHTMLFileException () {
121
+ public function testSetHTMLFileException ()
122
+ {
111
123
$ filePath = __DIR__ . '\HTMLFile.html ' ;
112
124
$ headlessChromer = new HeadlessChrome ();
113
125
$ this ->setExpectedException (Exception::class);
114
126
$ headlessChromer ->setHTMLFile ($ filePath );
115
127
}
116
128
117
- public function testUseMobile () {
129
+ public function testUseMobile ()
130
+ {
118
131
$ headlessChromer = new HeadlessChrome ();
119
132
$ headlessChromer ->useMobile ();
120
133
$ 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= ' ]);
121
134
}
122
135
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