This repository was archived by the owner on Aug 19, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOptionTest.php
More file actions
187 lines (155 loc) · 4.85 KB
/
Copy pathOptionTest.php
File metadata and controls
187 lines (155 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
* Licensing and applications manager.
*
* @author Josantonius <hello@josantonius.com>
* @copyright 2017 - 2018 (c) Josantonius - License Handler
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
* @link https://github.com/eliasis-framework/license-handler.git
* @since 1.0.1
*/
namespace Eliasis\Plugins\LicenseHandler;
use Eliasis\Complement\Type\Plugin;
use Eliasis\Framework\App;
use Josantonius\Database\Database;
use PHPUnit\Framework\TestCase;
/**
* Tests class for License Handler Eliasis plugin.
*/
final class OptionTest extends TestCase
{
/**
* Table name.
*
* @var string
*/
protected $table = 'test_options';
/**
* App instance.
*
* @var object
*/
protected $app;
/**
* Option controller instance.
*
* @var object
*/
protected $option;
/**
* Launcher instance.
*
* @var object
*/
protected $launcher;
/**
* Root path.
*
* @var string
*/
protected $root;
/**
* Database connection.
*
* @var object
*/
protected $db;
/**
* Set up.
*/
public function setUp()
{
parent::setUp();
$this->app = new App();
$this->root = $_SERVER['DOCUMENT_ROOT'];
$app = $this->app;
$app::run($this->root);
$this->db = Database::getConnection('app');
$plugin = Plugin::LicenseHandler();
$this->option = $plugin->getControllerInstance('Option');
$this->launcher = $plugin->getControllerInstance('Launcher');
}
/**
* Check if it is an instance of.
*/
public function testIsInstanceOf()
{
$this->assertInstanceOf('Eliasis\Framework\App', $this->app);
$this->assertInstanceOf('Josantonius\Database\Database', $this->db);
$this->assertInstanceOf(
'Eliasis\Plugins\LicenseHandler\Controller\Launcher',
$this->launcher
);
}
/**
* A table should be created when install the plugin.
*/
public function testTableShouldBeCreatedWhenInstallThePlugin()
{
$rows = $this->db->query("SELECT count(*)
FROM information_schema.tables
WHERE table_schema = '{$GLOBALS['DB_NAME']}'
AND table_name = '$this->table'");
$result = array_values((array) $rows[0]);
$this->assertSame((int) $result[0], 1);
}
/**
* Should create a row with default fields.
*/
public function testShouldCreateRowWithDefaultFields()
{
$result = $this->db->select()
->from($this->table)
->where(['option_id = 1'])
->execute();
$this->assertSame($result[0]->option_id, '1');
$this->assertSame($result[0]->lic_id, '1');
$this->assertSame($result[0]->option_name, 'lang');
$this->assertSame($result[0]->option_value, 'es-ES');
}
/**
* Should insert elements into the database.
*/
public function testShouldInsertElementsIntoTheDatabase()
{
$id = $this->option->add(1, 'lang', 'es-ES');
$this->assertSame($id, 2);
$result = $this->db->select()
->from($this->table)
->where(['option_id = 2'])
->execute();
$this->assertSame($result[0]->option_id, '2');
$this->assertSame($result[0]->lic_id, '1');
$this->assertSame($result[0]->option_name, 'lang');
$this->assertSame($result[0]->option_value, 'es-ES');
}
/**
* Should replace elements into the database.
*/
public function testShouldReplaceElementsIntoTheDatabase()
{
$rows = $this->option->update(2, 1, 'lang', 'en-EN');
$this->assertSame($rows, 1);
$result = $this->db->select()
->from($this->table)
->where(['option_id = 2'])
->execute();
$this->assertSame($result[0]->option_id, '2');
$this->assertSame($result[0]->lic_id, '1');
$this->assertSame($result[0]->option_name, 'lang');
$this->assertSame($result[0]->option_value, 'en-EN');
}
/**
* A table should be deleted when uninstall the plugin.
*/
public function testTableShouldBeDeletedWhenUninstallThePlugin()
{
Plugin::LicenseHandler()->doAction('uninstallation');
$rows = $this->db->query("SELECT count(*)
FROM information_schema.tables
WHERE table_schema = '{$GLOBALS['DB_NAME']}'
AND table_name = '$this->table'");
$result = array_values((array) $rows[0]);
$this->assertSame((int) $result[0], 0);
}
}