|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PSFS\tests; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use PSFS\base\config\Config; |
|
7
|
|
|
use PSFS\base\Request; |
|
8
|
|
|
use PSFS\base\Router; |
|
9
|
|
|
use PSFS\base\Security; |
|
10
|
|
|
use PSFS\base\types\helpers\AdminHelper; |
|
11
|
|
|
use PSFS\Dispatcher; |
|
12
|
|
|
|
|
13
|
|
|
class PSFSTest extends TestCase { |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Basic test for the basic functionality |
|
17
|
|
|
* @covers \PSFS\Dispatcher |
|
18
|
|
|
*/ |
|
19
|
|
|
public function testDispatcher() |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var \PSFS\Dispatcher $dispatcher */ |
|
22
|
|
|
$dispatcher = Dispatcher::getInstance(); |
|
23
|
|
|
|
|
24
|
|
|
// Is instance of Dispatcher? |
|
25
|
|
|
$this->assertTrue($dispatcher instanceof Dispatcher); |
|
26
|
|
|
|
|
27
|
|
|
// Did timestamp generated? |
|
28
|
|
|
$this->assertTrue($dispatcher->getTs() > 0); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Basic test for Config functionality |
|
33
|
|
|
* @covers \PSFS\base\config\Config |
|
34
|
|
|
*/ |
|
35
|
|
|
public function testConfig() |
|
36
|
|
|
{ |
|
37
|
|
|
$config = Config::getInstance(); |
|
38
|
|
|
|
|
39
|
|
|
// Is config instance? |
|
40
|
|
|
$this->assertTrue($config instanceof Config); |
|
41
|
|
|
|
|
42
|
|
|
// Is the platform configured? |
|
43
|
|
|
$this->assertTrue(is_bool($config->isConfigured())); |
|
44
|
|
|
|
|
45
|
|
|
// Is the platform in debug mode? |
|
46
|
|
|
$this->assertTrue(is_bool($config->getDebugMode())); |
|
47
|
|
|
|
|
48
|
|
|
// Check the variable extraction |
|
49
|
|
|
$this->assertEmpty($config->get(uniqid())); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Basic test for Router functionality |
|
54
|
|
|
* @covers \PSFS\base\Router |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testRouter() |
|
57
|
|
|
{ |
|
58
|
|
|
$router = Router::getInstance(); |
|
59
|
|
|
|
|
60
|
|
|
// Is ROuter instance? |
|
61
|
|
|
$this->assertTrue($router instanceof Router); |
|
62
|
|
|
|
|
63
|
|
|
// Check if route file exists |
|
64
|
|
|
$this->assertFileExists(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json"); |
|
65
|
|
|
|
|
66
|
|
|
// CHecks if we have admin routes as minimal routes |
|
67
|
|
|
$adminRoutes = AdminHelper::getAdminRoutes($router->getRoutes()); |
|
68
|
|
|
$this->assertNotEmpty($adminRoutes); |
|
69
|
|
|
$this->assertArrayHasKey("PSFS", $adminRoutes); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Basic test for Security functionality |
|
74
|
|
|
* @covers \PSFS\base\Security |
|
75
|
|
|
*/ |
|
76
|
|
|
public function testSecurity() |
|
77
|
|
|
{ |
|
78
|
|
|
$security = Security::getInstance(); |
|
79
|
|
|
|
|
80
|
|
|
// Is Security instance? |
|
81
|
|
|
$this->assertTrue($security instanceof Security); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Basic test for Request functionality |
|
86
|
|
|
* @covers \PSFS\base\Request |
|
87
|
|
|
*/ |
|
88
|
|
|
public function testRequest() |
|
89
|
|
|
{ |
|
90
|
|
|
$request = Request::getInstance(); |
|
91
|
|
|
|
|
92
|
|
|
// Is Request instance? |
|
93
|
|
|
$this->assertTrue($request instanceof Request); |
|
94
|
|
|
|
|
95
|
|
|
// Check headers, uploads and cookies checkers |
|
96
|
|
|
$this->assertTrue(is_bool($request->hasHeader("session"))); |
|
97
|
|
|
$this->assertTrue(is_bool($request->hasUpload())); |
|
98
|
|
|
$this->assertTrue(is_bool($request->hasCookies())); |
|
99
|
|
|
$this->assertTrue(is_bool($request->isAjax())); |
|
100
|
|
|
|
|
101
|
|
|
// Checks if timestamp was generated |
|
102
|
|
|
$this->assertNotNull($request->getTs()); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|