/
phpunittests.php
192 lines (169 loc) · 6.71 KB
/
phpunittests.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
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
188
189
190
191
192
<?php
define("ROOT_PATH", dirname(dirname(__FILE__)));
define("MODULES_DIR", ROOT_PATH."/endpoint");
define("PROVISIONER_BASE", ROOT_PATH.'/');
require_once(PROVISIONER_BASE.'autoload.php');
date_default_timezone_set('America/Los_Angeles');
class StackTest extends PHPUnit_Framework_TestCase
{
/**
* Test for valid/missing json in all json files
**/
public function testjsons()
{
$brand = 'polycom';
$family = 'spipm';
$model = 'SoundPoint IP 550';
$class = "endpoint_" . $brand . "_" . $family . '_phone';
$endpoint = new $class();
$data = $endpoint->file2json(MODULES_DIR.'/master.json');
foreach (glob(MODULES_DIR."/*",GLOB_ONLYDIR) as $branddir) {
$brand_filename = $branddir.'/brand_data.json';
$this->assertTrue(file_exists($brand_filename), $branddir . ' is missing brand_data.json');
if(file_exists($brand_filename)) {
$brand_data = $endpoint->file2json($brand_filename);
$family_list = $brand_data['data']['brands']['family_list'];
$family_ids = array();
foreach($family_list as $familydir) {
if(!in_array($familydir['id'], $family_ids)){
$family_ids[]=$familydir['id'];
} else {
$this->assertFalse(TRUE, "family_list id " . $familydir['id'] . " is duplicated in " . $brand_filename);
}
$family_filename = $branddir . '/' . $familydir['directory'] . '/family_data.json';
$this->assertTrue(file_exists($family_filename), $branddir . '/' . $familydir['directory'] . ' is missing family_data.json');
if(file_exists($family_filename)) {
$family_data = $endpoint->file2json($family_filename);
$model_data = $family_data['data']['model_list'];
$model_ids = array();
foreach($model_data as $modeld) {
if(!in_array($modeld['id'], $model_ids)){
$model_ids[]=$modeld['id'];
} else {
$this->assertFalse(TRUE, "model_list id " . $modeld['id'] . " duplicated in " . $family_filename);
}
foreach($modeld['template_data'] as $template_filenames) {
$this->assertTrue(file_exists($branddir . '/' . $familydir['directory'] . '/'. $template_filenames), $branddir . '/' . $familydir['directory'] . ' is missing '. $template_filenames);
$template_data = $endpoint->file2json($branddir . '/' . $familydir['directory'] . '/'. $template_filenames);
}
}
}
}
}
}
}
/**
* Test autoloader
**/
public function testautoload()
{
$brand = 'polycom';
$family = 'spipm';
$model = 'SoundPoint IP 550';
$class = "endpoint_" . $brand . "_" . $family . '_phone';
$this->endpoint = new $class();
$this->assertTrue(is_object($this->endpoint));
$this->assertTrue(method_exists($this->endpoint,"generate_all_files"));
}
public function testreplacementone()
{
$brand = 'polycom';
$family = 'spipm';
$model = 'SoundPoint IP 550';
$class = "endpoint_" . $brand . "_" . $family . '_phone';
$endpoint = new $class();
$endpoint->brand_name = $brand;
$endpoint->family_line = $family;
$endpoint->model = $model;
$endpoint->mac = '0123456789AB';
$endpoint->processor_info = 'PHPUNIT TESTING';
if (!class_exists("DateTimeZone")) { require(PROVISIONER_BASE.'/samples/tz.php'); }
$endpoint->DateTimeZone = new DateTimeZone('US/Pacific');;
$endpoint->settings['line'][0] = array(
"username" => "username_l1",
"secret" => "secret_l1",
"server_host" => "server_host_l1",
"server_port" => "server_port_l1",
"displayname" => "displayname_l1",
"line" => "1"
);
$unmodified_settings = $endpoint->settings;
$endpoint->generate_all_files();
foreach($unmodified_settings['line'][0] as $key => $linedata) {
$this->assertSame($linedata, $endpoint->replacement_array['lines'][1]['$'.$key], 'Error with '.$key.' replacement');
}
}
/**
* @group large
*/
public function testreplacementall()
{
$brand = 'polycom';
$family = 'spipm';
$model = 'SoundPoint IP 550';
$class = "endpoint_" . $brand . "_" . $family . '_phone';
$all_list = array();
$endpoint = new $class();
$data = $endpoint->file2json(MODULES_DIR.'/master.json');
foreach (glob(MODULES_DIR."/*",GLOB_ONLYDIR) as $branddir) {
$brand_filename = $branddir.'/brand_data.json';
if(file_exists($brand_filename)) {
$brand_data = $endpoint->file2json($brand_filename);
$bn = $brand_data['data']['brands']['directory'];
$all_list[$bn] = array();
$family_list = $brand_data['data']['brands']['family_list'];
foreach($family_list as $familydir) {
$family_filename = $branddir . '/' . $familydir['directory'] . '/family_data.json';
if(file_exists($family_filename)) {
$family_data = $endpoint->file2json($family_filename);
$fn = $family_data['data']['directory'];
$all_list[$bn][$fn] = array();
$model_data = $family_data['data']['model_list'];
foreach($model_data as $modeld) {
$all_list[$bn][$fn][] = $modeld;
foreach($modeld['template_data'] as $template_filenames) {
$template_data = $endpoint->file2json($branddir . '/' . $familydir['directory'] . '/'. $template_filenames);
}
}
}
}
}
}
unset($endpoint);
foreach($all_list as $kbrand => $family_list) {
$brand = $kbrand;
foreach($family_list as $kfamily => $model_list) {
$family = $kfamily;
$class = "endpoint_" . $brand . "_" . $family . '_phone';
foreach($model_list as $final_list) {
$endpoint = new $class();
$endpoint->brand_name = $brand;
$endpoint->family_line = $family;
$endpoint->model = $final_list['model'];
$endpoint->mac = '0123456789AB';
$endpoint->processor_info = 'PHPUNIT TESTING';
if (!class_exists("DateTimeZone")) { require(PROVISIONER_BASE.'/samples/tz.php'); }
$endpoint->DateTimeZone = new DateTimeZone('US/Pacific');;
$endpoint->settings['line'][0] = array(
"username" => "username_l1",
"secret" => "secret_l1",
"server_host" => "server_host_l1",
"server_port" => "server_port_l1",
"displayname" => "display_l1",
"line" => "1"
);
$unmodified_settings = $endpoint->settings;
$endpoint->generate_all_files();
//Test Line stuff
foreach($unmodified_settings['line'][0] as $key => $linedata) {
if(isset($endpoint->replacement_array['lines'][1]['$'.$key])) {
$this->assertSame($linedata, $endpoint->replacement_array['lines'][1]['$'.$key], 'Error with '.$key.' replacement on model:'.$endpoint->model);
}
}
//Load the json templates and assign values then replace those values in the file
unset($endpoint);
}
}
}
}
}