/
PluginTest.php
151 lines (132 loc) · 4.45 KB
/
PluginTest.php
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
<?php
# MantisBT - a php based bugtracking system
# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
/**
* Mantis Unit Tests
* @package Tests
* MantisBT Core Unit Tests
* @subpackage Plugin
* @copyright Copyright 2017 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/
# Includes
require_once dirname( dirname( __FILE__ ) ) . '/TestConfig.php';
# MantisBT Core API
require_mantis_core();
/**
* Helper API tests
* @package Tests
* @subpackage String
*/
class MantisPluginTest extends PHPUnit_Framework_TestCase {
const MANTISCORE = 'MantisCore';
/**
* References of version requirements to test against MantisCore versions.
*/
const REQ_13 = '1.3';
const REQ_130 = '1.3.0';
const REQ_131 = '1.3.1';
const REQ_13_20 = '1.3, <2.0';
const REQ_13_21 = '1.3, <2.1';
const REQ_13_30 = '1.3, <3.0';
const REQ_20 = '2.0';
const REQ_21 = '2.1';
const REQ_210 = '2.1.0';
const REQ_210_DEV = '2.1.0-dev';
const REQ_210_A1 = '2.1.0-beta.1';
const REQ_210_B1 = '2.1.0-beta.1';
const REQ_211 = '2.1.1';
/**
* Tests setup.
*/
public function setUp() {
plugin_register(self::MANTISCORE);
}
/**
* Tests plugin_dependency() for MantisCore.
*
* @param string $p_core_version MantisCore version to test against
* @param string $p_requirement Version requirement string
* @param bool $p_expected True if dependency OK (function returned 1)
*
* @dataProvider providerDependency
*/
public function testPluginDependency( $p_core_version, $p_requirement, $p_expected ) {
global $g_plugin_cache;
# Set MantisCore version for the test
$g_plugin_cache[self::MANTISCORE]->version = $p_core_version;
$t_result = plugin_dependency(
self::MANTISCORE,
$p_requirement
);
$this->assertEquals(
$p_expected,
$t_result == 1,
"MantisCore '$p_core_version' should "
. ( $p_expected ? 'meet' : 'have failed' )
. " requirement '$p_requirement'"
);
}
/**
* Provides a series of dependency test cases.
*
* Test case structure:
* array( <core version>, <requirement>, <result> )
*
* plugin_dependency() is called to check the given <core version> against
* <requirement>. <result> indicates whether we expect the test to
* pass (i.e. function returns 1) or fail (returns value is 0 or -1).
*
* @return array List of test cases
*/
public function providerDependency() {
return array(
array( '1.3.0', self::REQ_13, true ),
array( '1.3.0', self::REQ_130, true ),
array( '1.3.0', self::REQ_131, false ),
array( '1.3.0', self::REQ_13_20, true ),
array( '1.3.0', self::REQ_13_30, true ),
array( '1.3.0', self::REQ_20, false ),
array( '2.0.0', self::REQ_13, false ),
array( '2.0.0', self::REQ_13_20, false ),
array( '2.0.0', self::REQ_13_21, true ),
array( '2.0.0', self::REQ_13_30, true ),
array( '2.0.0', self::REQ_20, true ),
array( '2.0.0', self::REQ_210_DEV, false ),
array( '2.0.0-beta.1', self::REQ_20, true ),
array( '2.1.0', self::REQ_13, false ),
array( '2.1.0', self::REQ_13_20, false ),
array( '2.1.0', self::REQ_13_21, false ),
array( '2.1.0', self::REQ_13_30, true ),
array( '2.1.0', self::REQ_20, true ),
array( '2.1.0', self::REQ_21, true ),
array( '2.1.0', self::REQ_210_DEV, true ),
array( '2.1.0', self::REQ_210_B1, true ),
array( '2.1.0', self::REQ_211, false ),
array( '2.1.0-dev', self::REQ_21, true ),
array( '2.1.0-dev', self::REQ_210, true ),
array( '2.1.0-dev', self::REQ_210_DEV, true ),
array( '2.1.0-dev', self::REQ_210_A1, true ),
array( '2.1.0-dev', self::REQ_210_B1, true ),
array( '2.1.0-alpha.1', self::REQ_21, true ),
array( '2.1.0-alpha.1', self::REQ_210_DEV, true ),
array( '2.1.1', self::REQ_20, true ),
array( '2.1.1', self::REQ_21, true ),
array( '2.1.1', self::REQ_211, true ),
array( '3.0.0', self::REQ_13_20, false ),
array( '3.0.0', self::REQ_13_30, false ),
array( '3.0.0', self::REQ_20, false ),
);
}
}