Completed
Push — master ( d21053...c59b30 )
by
unknown
08:11
created

MissionLibraryTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 249
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 249
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 1

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A tearDown() 0 4 1
A testIsValidPhoneNumber() 0 13 1
A testIsValidPersonName() 0 10 1
A testIsValidGuidNumber() 0 11 1
A testPackLanguage() 0 19 1
B testUnpackLanguage() 0 96 1
A testPackTime() 0 18 1
A testUnpackTime() 0 50 1
A testFirstPostErrorCheck() 0 11 1
1
<?php
2
3
4
/**
5
 * Mission Library Tests
6
 *
7
 * these tests are integrated into the system unit tests (see start.php)
8
 * the functions that are tested are in a library, which is registered and loaded (see start.php)
9
 *
10
 * these tests only test library functions that DO NOT access the database
11
 *
12
 * to run the tests integrated into the core tests:
13
 *    - Administration page | Develop | Tools | Unit Tests | (press Run)
14
 *			-- or --
15
 *    - [GCconnex base URL]/engine/tests/suite.php
16
 *
17
 * to run independently of the core tests:
18
 *    - requires install and activate ufcoe_testable plugin from
19
 *     		git clone [email protected]:ufcoe/Elgg-ufcoe_testable.git ufcoe_testable
20
 *    - Administration page  | Develop | Plugin Tests | (click Micro Missions Run tests!)
21
 *			-- or --
22
 *	  - [GCconnex base URL]/testable/run/missions
23
 */
24
class MissionLibraryTest extends ElggCoreUnitTest {
25
26
	private $session_language = null;
27
28
	function setUp() {
29
		$this->session_language = get_current_language();
30
    }
31
32
    function tearDown() {
33
        //$_SESSION['language'] = $this->session_language;
34
		$this->session_language = null;
35
    }
36
37
    public function testIsValidPhoneNumber() {
38
     	$this->assertTrue(mm_is_valid_phone_number('5555555555'));
39
     	$this->assertTrue(mm_is_valid_phone_number('555-555-5555'));
40
     	$this->assertTrue(mm_is_valid_phone_number('555 555 5555'));
41
     	$this->assertTrue(mm_is_valid_phone_number('1(555) 555-5555'));
42
     	$this->assertTrue(mm_is_valid_phone_number('1 (555) 555-5555'));
43
     	$this->assertTrue(mm_is_valid_phone_number('1-555-555-5555'));
44
45
     	$this->assertFalse(mm_is_valid_phone_number('5'));
46
     	$this->assertFalse(mm_is_valid_phone_number('555-5555'));
47
     	//$this->assertFalse(mm_is_valid_phone_number('1-(555)-555-5555'));
48
     	$this->assertFalse(mm_is_valid_phone_number('(555) PA8-7572'));
49
    }
50
51
    public function testIsValidPersonName() {
52
     	$this->assertTrue(mm_is_valid_person_name('Eileen'));
53
     	$this->assertTrue(mm_is_valid_person_name('Eileen Williamson'));
54
55
     	$this->assertTrue(mm_is_valid_person_name('%$@#%$#&/:'.']}'));
56
57
     	$this->assertFalse(mm_is_valid_person_name('4Wesley'));
58
     	$this->assertFalse(mm_is_valid_person_name('Wes7ley'));
59
     	$this->assertFalse(mm_is_valid_person_name('Wesley9'));
60
    }
61
62
    public function testIsValidGuidNumber() {
63
     	$this->assertTrue(mm_is_guid_number('5'));
64
     	$this->assertTrue(mm_is_guid_number('673445'));
65
66
     	$this->assertFalse(mm_is_guid_number('1.0'));
67
     	$this->assertFalse(mm_is_guid_number('-2'));
68
     	$this->assertFalse(mm_is_guid_number('1.314E-7'));
69
     	$this->assertFalse(mm_is_guid_number('532K351'));
70
     	$this->assertFalse(mm_is_guid_number('@578532)'));
71
     	$this->assertFalse(mm_is_guid_number('578(532)'));
72
    }
73
74
	public function testPackLanguage() {
75
		//valid inputs
76
77
		$this->assertIdentical('englishABC', mm_pack_language('A', 'B', 'C', 'English'));
78
		$this->assertIdentical('english---', mm_pack_language('-', '-', '-', 'English'));
79
		$this->assertIdentical('english---', mm_pack_language('', '', '', 'English'));
80
81
		$this->assertIdentical('frenchABC', mm_pack_language('A', 'B', 'C', 'French'));
82
		$this->assertIdentical('french---', mm_pack_language('-', '-', '-', 'French'));
83
		$this->assertIdentical('french---', mm_pack_language('', '', '', 'French'));
84
85
		//invalid inputs
86
87
		$this->assertIdentical('englishDEF', mm_pack_language('D', 'E', 'F', 'English'));
88
		$this->assertIdentical('french789', mm_pack_language('7', '8', '9', 'French'));
89
		$this->assertIdentical('nosuchlanguage---', mm_pack_language('', '', '', 'nosuchlanguage'));
90
		$this->assertIdentical('---', mm_pack_language('', '', '', ''));
91
		$this->assertIdentical('---', mm_pack_language(NULL, NULL, NULL, NULL));
92
	}
93
94
	public function testUnpackLanguage() {
95
		//valid inputs
96
97
		$actual = mm_unpack_language('englishABC', 'English');
98
		$expected = array(
99
    		'lwc_english' => 'A',
100
    		'lwe_english' => 'B',
101
    		'lop_english' => 'C'
102
		);
103
		$this->assertIdentical($expected, $actual);
104
105
		$actual = mm_unpack_language('english---', 'English');
106
		$expected = array(
107
    		'lwc_english' => '',
108
    		'lwe_english' => '',
109
    		'lop_english' => ''
110
		);
111
		$this->assertIdentical($expected, $actual);
112
113
		$actual = mm_unpack_language('frenchABC', 'French');
114
		$expected = array(
115
    		'lwc_french' => 'A',
116
    		'lwe_french' => 'B',
117
    		'lop_french' => 'C'
118
		);
119
		$this->assertIdentical($expected, $actual);
120
121
		$actual = mm_unpack_language('french---', 'French');
122
		$expected = array(
123
    		'lwc_french' => '',
124
    		'lwe_french' => '',
125
    		'lop_french' => ''
126
		);
127
		$this->assertIdentical($expected, $actual);
128
129
		$actual = mm_unpack_language('---', '');
130
		$expected = array(
131
    		'lwc_' => '',
132
    		'lwe_' => '',
133
    		'lop_' => ''
134
		);
135
		$this->assertIdentical($expected, $actual);
136
137
		$actual = mm_unpack_language('CBA', '');
138
		$expected = array(
139
    		'lwc_' => 'C',
140
    		'lwe_' => 'B',
141
    		'lop_' => 'A'
142
		);
143
		$this->assertIdentical($expected, $actual);
144
145
146
		//invalid inputs
147
148
		$actual = mm_unpack_language('englishABC', 'Thisisnotalanguage');
149
		$expected = array(
150
			'lwc_thisisnotalanguage' => false,
151
			'lwe_thisisnotalanguage' => false,
152
			'lop_thisisnotalanguage' => false
153
		);
154
		$this->assertIdentical($expected, $actual);
155
156
		$actual = mm_unpack_language('ABC', 'Thisisnotalanguage');
157
		$expected = array(
158
			'lwc_thisisnotalanguage' => false,
159
			'lwe_thisisnotalanguage' => false,
160
			'lop_thisisnotalanguage' => false
161
		);
162
		$this->assertIdentical($expected, $actual);
163
164
		$actual = mm_unpack_language('', 'English');
165
		$expected = array(
166
			'lwc_english' => false,
167
			'lwe_english' => false,
168
			'lop_english' => false
169
		);
170
		$this->assertIdentical($expected, $actual);
171
172
		$actual = mm_unpack_language(NULL, 'English');
173
		$expected = array(
174
			'lwc_english' => false,
175
			'lwe_english' => false,
176
			'lop_english' => false
177
		);
178
		$this->assertIdentical($expected, $actual);
179
180
181
		$actual = mm_unpack_language(NULL, NULL);
182
		$expected = array(
183
			'lwc_' => false,
184
			'lwe_' => false,
185
			'lop_' => false
186
		);
187
		$this->assertIdentical($expected, $actual);
188
189
	}
190
191
	public function testPackTime() {
192
		//valid inputs
193
194
		$this->assertIdentical('mon_start0859', mm_pack_time('08', '59', 'mon_start'));
195
		$this->assertIdentical('tue_start', mm_pack_time('', '', 'tue_start'));
196
		$this->assertIdentical('wed_end6667', mm_pack_time('66', '67', 'wed_end'));
197
		$this->assertIdentical('thu_start--', mm_pack_time('-', '-', 'thu_start'));
198
		$this->assertIdentical('fri_end-55', mm_pack_time('-', '55', 'fri_end'));
199
		$this->assertIdentical('sat_start12-', mm_pack_time('12', '-', 'sat_start'));
200
201
		//invalid inputs
202
203
		$this->assertIdentical('Nosuchday0055', mm_pack_time('00', '55', 'Nosuchday'));
204
		$this->assertIdentical('0055', mm_pack_time('00', '55', ''));
205
		$this->assertIdentical('', mm_pack_time('', '', ''));
206
		$this->assertIdentical('', mm_pack_time(NULL, NULL, NULL));
207
208
	}
209
210
	public function testUnpackTime() {
211
		//valid inputs
212
213
		$actual = mm_unpack_time('mon_start0859', 'mon_start');
214
		$expected = array(
215
    		'mon_start_hour' => '08',
216
    		'mon_start_min' => '59',
217
		);
218
		$this->assertIdentical($expected, $actual);
219
220
		$actual = mm_unpack_time('mon_end0910', 'mon_end');
221
		$expected = array(
222
    		'mon_end_hour' => '09',
223
    		'mon_end_min' => '10',
224
		);
225
		$this->assertIdentical($expected, $actual);
226
227
228
229
		//invalid inputs
230
231
		$actual = mm_unpack_time('tuesday6789', 'nonsenseday');
232
		$expected = array(
233
    		'nonsenseday_hour' => false,
234
    		'nonsenseday_min' => false,
235
		);
236
		$this->assertIdentical($expected, $actual);
237
238
		$actual = mm_unpack_time('1234', '');
239
		$expected = array(
240
    		'_hour' => '12',
241
    		'_min' => '34',
242
		);
243
		$this->assertIdentical($expected, $actual);
244
245
		$actual = mm_unpack_time('1234', NULL);
246
		$expected = array(
247
    		'_hour' => '12',
248
    		'_min' => '34',
249
		);
250
		$this->assertIdentical($expected, $actual);
251
252
		$actual = mm_unpack_time(NULL, 'mon_start');
253
		$expected = array();
254
		$this->assertIdentical($expected, $actual);
255
256
		$actual = mm_unpack_time(NULL, NULL);
257
		$expected = array();
258
		$this->assertIdentical($expected, $actual);
259
	}
260
261
	public function testFirstPostErrorCheck() {
262
		$user = elgg_get_logged_in_user_entity();
263
		$input_array = array(
264
				'name' => $user->name,
265
				'email' => $user->email,
266
				'org-drop' => mo_get_tree_root()->guid,
267
				'other_node' => '',
268
				'phone' => '6139930617'
269
		);
270
		$this->assertFalse(mm_first_post_error_check($input_array));
271
	}
272
}
273
274
275