4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\BrowserKit\Tests;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\BrowserKit\History;
16 use Symfony\Component\BrowserKit\Request;
18 class HistoryTest extends TestCase
20 public function testAdd()
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');
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');
29 $history->add(new Request('http://www.example3.com/', 'get'));
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');
35 $this->assertSame('http://www.example2.com/', $history->current()->getUri(), '->add() adds a request to the history');
38 public function testClearIsEmpty()
40 $history = new History();
41 $history->add(new Request('http://www.example.com/', 'get'));
43 $this->assertFalse($history->isEmpty(), '->isEmpty() returns false if the history is not empty');
47 $this->assertTrue($history->isEmpty(), '->isEmpty() true if the history is empty');
50 public function testCurrent()
52 $history = new History();
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');
61 $history->add(new Request('http://www.example.com/', 'get'));
63 $this->assertSame('http://www.example.com/', $history->current()->getUri(), '->current() returns the current request in the history');
66 public function testBack()
68 $history = new History();
69 $history->add(new Request('http://www.example.com/', 'get'));
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');
78 $history->add(new Request('http://www.example1.com/', 'get'));
81 $this->assertSame('http://www.example.com/', $history->current()->getUri(), '->back() returns the previous request in the history');
84 public function testForward()
86 $history = new History();
87 $history->add(new Request('http://www.example.com/', 'get'));
88 $history->add(new Request('http://www.example1.com/', 'get'));
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');
100 $this->assertSame('http://www.example1.com/', $history->current()->getUri(), '->forward() returns the next request in the history');