|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CakeCMS Core |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the of the simple cms based on CakePHP 3. |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @package Core |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
* @copyright MIT License http://www.opensource.org/licenses/mit-license.php |
|
12
|
|
|
* @link https://github.com/CakeCMS/Core". |
|
13
|
|
|
* @author Sergey Kalistratov <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Core\TestSuite; |
|
17
|
|
|
|
|
18
|
|
|
use Core\Plugin; |
|
19
|
|
|
use Cake\Cache\Cache; |
|
20
|
|
|
use Cake\Utility\Hash; |
|
21
|
|
|
use Cake\TestSuite\IntegrationTestCase as CakeIntegrationTestCase; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class IntegrationTestCase |
|
25
|
|
|
* |
|
26
|
|
|
* @package Core\TestSuite |
|
27
|
|
|
*/ |
|
28
|
|
|
class IntegrationTestCase extends CakeIntegrationTestCase |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Default plugin. |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $_plugin = 'Core'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Core plugin. |
|
40
|
|
|
* |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
private $_corePlugin = 'Core'; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Default url. |
|
47
|
|
|
* |
|
48
|
|
|
* @var array |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $_url = [ |
|
51
|
|
|
'prefix' => null, |
|
52
|
|
|
'plugin' => 'Core', |
|
53
|
|
|
'action' => '', |
|
54
|
|
|
]; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Setup the test case, backup the static object values so they can be restored. |
|
58
|
|
|
* Specifically backs up the contents of Configure and paths in App if they have |
|
59
|
|
|
* not already been backed up. |
|
60
|
|
|
* |
|
61
|
|
|
* @return void |
|
62
|
|
|
*/ |
|
63
|
|
|
public function setUp() |
|
64
|
|
|
{ |
|
65
|
|
|
parent::setUp(); |
|
66
|
|
|
|
|
67
|
|
View Code Duplication |
if (!Plugin::loaded($this->_corePlugin)) { |
|
|
|
|
|
|
68
|
|
|
$loadParams = [ |
|
69
|
|
|
'bootstrap' => true, |
|
70
|
|
|
'routes' => true, |
|
71
|
|
|
'path' => ROOT . DS, |
|
72
|
|
|
]; |
|
73
|
|
|
|
|
74
|
|
|
Plugin::load($this->_corePlugin, $loadParams); |
|
75
|
|
|
Plugin::routes($this->_corePlugin); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if ($this->_plugin !== $this->_corePlugin) { |
|
79
|
|
|
$options = [ |
|
80
|
|
|
'bootstrap' => true, |
|
81
|
|
|
'routes' => true, |
|
82
|
|
|
'autoload' => true, |
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
|
|
Plugin::load($this->_plugin, $options); |
|
86
|
|
|
Plugin::routes($this->_plugin); |
|
87
|
|
|
|
|
88
|
|
|
$this->_url['plugin'] = $this->_plugin; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Clears the state used for requests. |
|
94
|
|
|
* |
|
95
|
|
|
* @return void |
|
96
|
|
|
*/ |
|
97
|
|
View Code Duplication |
public function tearDown() |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
parent::tearDown(); |
|
100
|
|
|
|
|
101
|
|
|
Plugin::unload($this->_corePlugin); |
|
102
|
|
|
if ($this->_plugin !== $this->_corePlugin) { |
|
103
|
|
|
Plugin::unload($this->_plugin); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
Cache::drop('test_cached'); |
|
107
|
|
|
unset($this->_url); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Prepare url. |
|
112
|
|
|
* |
|
113
|
|
|
* @param array $url |
|
114
|
|
|
* @return array |
|
115
|
|
|
*/ |
|
116
|
|
|
protected function _getUrl(array $url = []) |
|
117
|
|
|
{ |
|
118
|
|
|
return Hash::merge($this->_url, $url); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.