1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace SmrTest\lib\DefaultGame; |
4
|
|
|
|
5
|
|
|
use Page; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* This is an integration test, but does not need to extend BaseIntegrationTest |
9
|
|
|
* since we are not (or should not be!) writing any data. |
10
|
|
|
* @covers Page |
11
|
|
|
*/ |
12
|
|
|
class PageIntegrationTest extends \PHPUnit\Framework\TestCase { |
13
|
|
|
|
14
|
|
|
public function test_create() { |
15
|
|
|
// Test create with $extra as array |
16
|
|
|
$page = Page::create('file', 'body', ['extra' => 'data']); |
17
|
|
|
// Check that the expected keys of the ArrayObject are set |
18
|
|
|
$expected = ['extra' => 'data', 'url' => 'file', 'body' => 'body']; |
19
|
|
|
self::assertSame($expected, $page->getArrayCopy()); |
20
|
|
|
|
21
|
|
|
// Test create with $extra as a Page object |
22
|
|
|
$page2 = Page::create('file2', extra: $page); |
23
|
|
|
// Check that the expected keys of the ArrayObject are set |
24
|
|
|
$expected2 = ['extra' => 'data', 'url' => 'file2', 'body' => '']; |
25
|
|
|
self::assertSame($expected2, $page2->getArrayCopy()); |
26
|
|
|
|
27
|
|
|
// Make sure they are not references to the same underlying object |
28
|
|
|
self::assertNotSame($page, $page2); |
29
|
|
|
// Make sure passing $page to create didn't modify the original |
30
|
|
|
self::assertSame($expected, $page->getArrayCopy()); |
31
|
|
|
|
32
|
|
|
// Test create when setting $remainingPageLoads |
33
|
|
|
$page3 = Page::create('file', remainingPageLoads: 2); |
34
|
|
|
self::assertSame(2, $page3['RemainingPageLoads']); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function test_copy() { |
38
|
|
|
// Create an arbitrary Page |
39
|
|
|
$page = Page::create('file'); |
40
|
|
|
// The copy should be equal, but not the same |
41
|
|
|
$copy = Page::copy($page); |
42
|
|
|
self::assertNotSame($page, $copy); |
43
|
|
|
self::assertEquals($page, $copy); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function test_useAsGlobalVar() { |
47
|
|
|
// Create an arbitrary Page |
48
|
|
|
$page = Page::create('file'); |
49
|
|
|
|
50
|
|
|
// Unset the global $var in case it has been set elsewhere |
51
|
|
|
global $var; |
52
|
|
|
$var = null; |
53
|
|
|
|
54
|
|
|
// The global $var should be the same object as $page |
55
|
|
|
$page->useAsGlobalVar(); |
56
|
|
|
self::assertSame($var, $page); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function test_href() { |
60
|
|
|
// Create an arbitrary Page |
61
|
|
|
$page = Page::create('file'); |
62
|
|
|
|
63
|
|
|
// The Page should not be modified when href() is called |
64
|
|
|
$expected = $page->getArrayCopy(); |
65
|
|
|
srand(0); // for a deterministic SN |
66
|
|
|
$_SERVER['REQUEST_URI'] = 'loader.php'; // prevent "Undefined array key" |
67
|
|
|
$href = $page->href(); |
68
|
|
|
self::assertSame('?sn=qpbqzr', $href); |
69
|
|
|
self::assertSame($expected, $page->getArrayCopy()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|