Version 1
[yaffs-website] / vendor / symfony / browser-kit / Tests / HistoryTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\BrowserKit\Tests;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\BrowserKit\History;
16 use Symfony\Component\BrowserKit\Request;
17
18 class HistoryTest extends TestCase
19 {
20     public function testAdd()
21     {
22         $history = new History();
23         $history->add(new Request('http://www.example1.com/', 'get'));
24         $this->assertSame('http://www.example1.com/', $history->current()->getUri(), '->add() adds a request to the history');
25
26         $history->add(new Request('http://www.example2.com/', 'get'));
27         $this->assertSame('http://www.example2.com/', $history->current()->getUri(), '->add() adds a request to the history');
28
29         $history->add(new Request('http://www.example3.com/', 'get'));
30         $history->back();
31         $history->add(new Request('http://www.example4.com/', 'get'));
32         $this->assertSame('http://www.example4.com/', $history->current()->getUri(), '->add() adds a request to the history');
33
34         $history->back();
35         $this->assertSame('http://www.example2.com/', $history->current()->getUri(), '->add() adds a request to the history');
36     }
37
38     public function testClearIsEmpty()
39     {
40         $history = new History();
41         $history->add(new Request('http://www.example.com/', 'get'));
42
43         $this->assertFalse($history->isEmpty(), '->isEmpty() returns false if the history is not empty');
44
45         $history->clear();
46
47         $this->assertTrue($history->isEmpty(), '->isEmpty() true if the history is empty');
48     }
49
50     public function testCurrent()
51     {
52         $history = new History();
53
54         try {
55             $history->current();
56             $this->fail('->current() throws a \LogicException if the history is empty');
57         } catch (\Exception $e) {
58             $this->assertInstanceOf('LogicException', $e, '->current() throws a \LogicException if the history is empty');
59         }
60
61         $history->add(new Request('http://www.example.com/', 'get'));
62
63         $this->assertSame('http://www.example.com/', $history->current()->getUri(), '->current() returns the current request in the history');
64     }
65
66     public function testBack()
67     {
68         $history = new History();
69         $history->add(new Request('http://www.example.com/', 'get'));
70
71         try {
72             $history->back();
73             $this->fail('->back() throws a \LogicException if the history is already on the first page');
74         } catch (\Exception $e) {
75             $this->assertInstanceOf('LogicException', $e, '->current() throws a \LogicException if the history is already on the first page');
76         }
77
78         $history->add(new Request('http://www.example1.com/', 'get'));
79         $history->back();
80
81         $this->assertSame('http://www.example.com/', $history->current()->getUri(), '->back() returns the previous request in the history');
82     }
83
84     public function testForward()
85     {
86         $history = new History();
87         $history->add(new Request('http://www.example.com/', 'get'));
88         $history->add(new Request('http://www.example1.com/', 'get'));
89
90         try {
91             $history->forward();
92             $this->fail('->forward() throws a \LogicException if the history is already on the last page');
93         } catch (\Exception $e) {
94             $this->assertInstanceOf('LogicException', $e, '->forward() throws a \LogicException if the history is already on the last page');
95         }
96
97         $history->back();
98         $history->forward();
99
100         $this->assertSame('http://www.example1.com/', $history->current()->getUri(), '->forward() returns the next request in the history');
101     }
102 }