Security update for Core, with self-updated composer
[yaffs-website] / vendor / masterminds / html5 / test / HTML5 / Parser / FileInputStreamTest.php
1 <?php
2 namespace Masterminds\HTML5\Tests\Parser;
3
4 use Masterminds\HTML5\Parser\FileInputStream;
5
6 class FileInputStreamTest extends \Masterminds\HTML5\Tests\TestCase
7 {
8
9     public function testConstruct()
10     {
11         $s = new FileInputStream(__DIR__ . '/FileInputStreamTest.html');
12
13         $this->assertInstanceOf('\Masterminds\HTML5\Parser\FileInputStream', $s);
14     }
15
16     public function testNext()
17     {
18         $s = new FileInputStream(__DIR__ . '/FileInputStreamTest.html');
19
20         $s->next();
21         $this->assertEquals('!', $s->current());
22         $s->next();
23         $this->assertEquals('d', $s->current());
24     }
25
26     public function testKey()
27     {
28         $s = new FileInputStream(__DIR__ . '/FileInputStreamTest.html');
29
30         $this->assertEquals(0, $s->key());
31
32         $s->next();
33         $this->assertEquals(1, $s->key());
34     }
35
36     public function testPeek()
37     {
38         $s = new FileInputStream(__DIR__ . '/FileInputStreamTest.html');
39
40         $this->assertEquals('!', $s->peek());
41
42         $s->next();
43         $this->assertEquals('d', $s->peek());
44     }
45
46     public function testCurrent()
47     {
48         $s = new FileInputStream(__DIR__ . '/FileInputStreamTest.html');
49
50         $this->assertEquals('<', $s->current());
51
52         $s->next();
53         $this->assertEquals('!', $s->current());
54
55         $s->next();
56         $this->assertEquals('d', $s->current());
57     }
58
59     public function testColumnOffset()
60     {
61         $s = new FileInputStream(__DIR__ . '/FileInputStreamTest.html');
62         $this->assertEquals(0, $s->columnOffset());
63         $s->next();
64         $this->assertEquals(1, $s->columnOffset());
65         $s->next();
66         $this->assertEquals(2, $s->columnOffset());
67         $s->next();
68         $this->assertEquals(3, $s->columnOffset());
69
70         // Make sure we get to the second line
71         $s->next();
72         $s->next();
73         $s->next();
74         $s->next();
75         $s->next();
76         $s->next();
77         $s->next();
78         $s->next();
79         $s->next();
80         $s->next();
81         $s->next();
82         $s->next();
83         $s->next();
84         $this->assertEquals(0, $s->columnOffset());
85
86         $s->next();
87         $canary = $s->current(); // h
88         $this->assertEquals('h', $canary);
89         $this->assertEquals(1, $s->columnOffset());
90     }
91
92     public function testCurrentLine()
93     {
94         $s = new FileInputStream(__DIR__ . '/FileInputStreamTest.html');
95
96         $this->assertEquals(1, $s->currentLine());
97
98         // Make sure we get to the second line
99         $s->next();
100         $s->next();
101         $s->next();
102         $s->next();
103         $s->next();
104         $s->next();
105         $s->next();
106         $s->next();
107         $s->next();
108         $s->next();
109         $s->next();
110         $s->next();
111         $s->next();
112         $s->next();
113         $s->next();
114         $s->next();
115         $this->assertEquals(2, $s->currentLine());
116
117         // Make sure we get to the third line
118         $s->next();
119         $s->next();
120         $s->next();
121         $s->next();
122         $s->next();
123         $s->next();
124         $s->next();
125         $s->next();
126         $s->next();
127         $s->next();
128         $s->next();
129         $s->next();
130         $s->next();
131         $s->next();
132         $s->next();
133         $s->next();
134         $s->next();
135         $this->assertEquals(3, $s->currentLine());
136     }
137
138     public function testRemainingChars()
139     {
140         $text = file_get_contents(__DIR__ . '/FileInputStreamTest.html');
141         $s = new FileInputStream(__DIR__ . '/FileInputStreamTest.html');
142         $this->assertEquals($text, $s->remainingChars());
143
144         $text = substr(file_get_contents(__DIR__ . '/FileInputStreamTest.html'), 1);
145         $s = new FileInputStream(__DIR__ . '/FileInputStreamTest.html');
146         $s->next(); // Pop one.
147         $this->assertEquals($text, $s->remainingChars());
148     }
149
150     public function testCharsUnitl()
151     {
152         $s = new FileInputStream(__DIR__ . '/FileInputStreamTest.html');
153
154         $this->assertEquals('', $s->charsUntil('<'));
155         // Pointer at '<', moves to ' '
156         $this->assertEquals('<!doctype', $s->charsUntil(' ', 20));
157
158         // Pointer at ' ', moves to '>'
159         $this->assertEquals(' html', $s->charsUntil('>'));
160
161         // Pointer at '>', moves to '\n'.
162         $this->assertEquals('>', $s->charsUntil("\n"));
163
164         // Pointer at '\n', move forward then to the next'\n'.
165         $s->next();
166         $this->assertEquals('<html lang="en">', $s->charsUntil("\n"));
167
168         // Ony get one of the spaces.
169         $this->assertEquals("\n ", $s->charsUntil('<', 2));
170
171         // Get the other space.
172         $this->assertEquals(" ", $s->charsUntil('<'));
173
174         // This should scan to the end of the file.
175         $text = "<head>
176     <meta charset=\"utf-8\">
177     <title>Test</title>
178   </head>
179   <body>
180     <p>This is a test.</p>
181   </body>
182 </html>";
183         $this->assertEquals($text, $s->charsUntil("\t"));
184     }
185
186     public function testCharsWhile()
187     {
188         $s = new FileInputStream(__DIR__ . '/FileInputStreamTest.html');
189
190         $this->assertEquals('<!', $s->charsWhile('!<'));
191         $this->assertEquals('', $s->charsWhile('>'));
192         $this->assertEquals('doctype', $s->charsWhile('odcyept'));
193         $this->assertEquals(' htm', $s->charsWhile('html ', 4));
194     }
195 }