1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Tests\Module; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Db; |
5
|
|
|
use Redaxscript\Module; |
6
|
|
|
use Redaxscript\Tests\TestCaseAbstract; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* ModuleTest |
10
|
|
|
* |
11
|
|
|
* @since 2.2.0 |
12
|
|
|
* |
13
|
|
|
* @package Redaxscript |
14
|
|
|
* @category Tests |
15
|
|
|
* @author Henry Ruhs |
16
|
|
|
* |
17
|
|
|
* @covers Redaxscript\Module\Module |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
class ModuleTest extends TestCaseAbstract |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* setUp |
24
|
|
|
* |
25
|
|
|
* @since 3.1.0 |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
public function setUp() : void |
29
|
|
|
{ |
30
|
|
|
parent::setUp(); |
31
|
|
|
$this->createDatabase(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* tearDown |
36
|
|
|
* |
37
|
|
|
* @since 3.1.0 |
38
|
|
|
*/ |
39
|
|
|
|
40
|
|
|
public function tearDown() : void |
41
|
|
|
{ |
42
|
|
|
$this->dropDatabase(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* testInit |
47
|
|
|
* |
48
|
|
|
* @since 2.2.0 |
49
|
|
|
*/ |
50
|
|
|
|
51
|
|
|
public function testInit() : void |
52
|
|
|
{ |
53
|
|
|
/* setup */ |
54
|
|
|
|
55
|
|
|
$module = new Module\Module($this->_registry, $this->_request, $this->_language, $this->_config); |
56
|
|
|
$module->init( |
57
|
|
|
[ |
58
|
|
|
'name' => 'Test Dummy', |
59
|
|
|
'alias' => 'TestDummy' |
60
|
|
|
]); |
61
|
|
|
|
62
|
|
|
/* actual */ |
63
|
|
|
|
64
|
|
|
$actual = $module; |
65
|
|
|
|
66
|
|
|
/* compare */ |
67
|
|
|
|
68
|
|
|
$this->assertIsObject($actual); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* testInstallAndUninstall |
73
|
|
|
* |
74
|
|
|
* @since 2.6.0 |
75
|
|
|
*/ |
76
|
|
|
|
77
|
|
|
public function testInstallAndUninstall() : void |
78
|
|
|
{ |
79
|
|
|
/* setup */ |
80
|
|
|
|
81
|
|
|
$module = new Module\Module($this->_registry, $this->_request, $this->_language, $this->_config); |
82
|
|
|
$module->init( |
83
|
|
|
[ |
84
|
|
|
'name' => 'Test Dummy', |
85
|
|
|
'alias' => 'TestDummy' |
86
|
|
|
]); |
87
|
|
|
|
88
|
|
|
/* install */ |
89
|
|
|
|
90
|
|
|
$actualInstall = $module->install(); |
91
|
|
|
$actualModulesInstall = Db::forTablePrefix('modules')->count(); |
92
|
|
|
$actualTablesInstall = Db::countTablePrefix(); |
93
|
|
|
|
94
|
|
|
/* uninstall */ |
95
|
|
|
|
96
|
|
|
$actualUninstall = $module->uninstall(); |
97
|
|
|
$actualModulesUninstall = Db::forTablePrefix('modules')->count(); |
98
|
|
|
$actualTablesUninstall = Db::countTablePrefix(); |
99
|
|
|
|
100
|
|
|
/* compare */ |
101
|
|
|
|
102
|
|
|
$this->assertTrue($actualInstall); |
103
|
|
|
$this->assertTrue($actualUninstall); |
104
|
|
|
$this->assertEquals(1, $actualModulesInstall); |
105
|
|
|
$this->assertEquals(9, $actualTablesInstall); |
106
|
|
|
$this->assertEquals(0, $actualModulesUninstall); |
107
|
|
|
$this->assertEquals(8, $actualTablesUninstall); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* testInstallAndUninstallInvalid |
112
|
|
|
* |
113
|
|
|
* @since 4.0.0 |
114
|
|
|
* |
115
|
|
|
* @runInSeparateProcess |
116
|
|
|
*/ |
117
|
|
|
|
118
|
|
|
public function testInstallAndUninstallInvalid() : void |
119
|
|
|
{ |
120
|
|
|
/* setup */ |
121
|
|
|
|
122
|
|
|
$module = new Module\Module($this->_registry, $this->_request, $this->_language, $this->_config); |
123
|
|
|
$module->init(); |
124
|
|
|
|
125
|
|
|
/* actual */ |
126
|
|
|
|
127
|
|
|
$actualInstall = $module->install(); |
128
|
|
|
$actualUninstall = $module->uninstall(); |
129
|
|
|
|
130
|
|
|
/* compare */ |
131
|
|
|
|
132
|
|
|
$this->assertFalse($actualInstall); |
133
|
|
|
$this->assertFalse($actualUninstall); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|