-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtde.test
161 lines (139 loc) · 4.51 KB
/
tde.test
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
<?php
/**
* @file
* Tests for tde.module.
*/
/**
* Provides automated tests for the TDE module.
*/
class TdeTestCase extends DrupalWebTestCase {
/**
* A user with taxonomy privileges.
*/
protected $taxonomy_user;
/**
* A sample array to create a vocabulary from.
*/
protected $base_vocab;
/**
* The base vocab with extra items added
*/
protected $extended_vocab;
public static function getInfo() {
return array(
'name' => 'Taxonomy Developer Extras functionality',
'description' => 'Create, and update Vocabularies from a simple array.',
'group' => 'Taxonomy',
);
}
function setUp() {
parent::setUp('taxonomy', 'tde');
// Create users.
$this->taxonomy_user = $this->drupalCreateUser(array(
'access administration pages',
'administer taxonomy',
));
// Build 2 vocabulary arrays
$key1 = 'v1 ' . $this->randomName(16);
$key2 = 'v2 ' . $this->randomName(16);
// Our first one is a simple flat vocab
$this->base_vocab = array(
$key1 => array(
'level 1 ' . $this->randomName(8),
'level 1 ' . $this->randomName(8),
'level 1 ' . $this->randomName(8),
),
);
// The second builds on the first to create a more involved structure.
$this->extended_vocab = $this->base_vocab;
$this->extended_vocab[$key1]['level 1 ' . $this->randomName(8)] = array(
'level 2 ' . $this->randomName(4),
'level 2 ' . $this->randomName(4),
'level 2 ' . $this->randomName(4),
);
$this->extended_vocab[$key2] = array(
'level 1 ' . $this->randomName(8) => array(
'level 2 ' . $this->randomName(4),
'level 2 ' . $this->randomName(4),
),
'level 1 ' . $this->randomName(8),
'level 1 ' . $this->randomName(8),
);
variable_set('clean_url', 1);
$this->drupalLogin($this->taxonomy_user);
}
/**
* Test basic User access
*/
function testUserAccess() {
$this->drupalGet("admin/structure/taxonomy");
$this->assertResponse(200, 'User is allowed to view the Taxonomy admin page.');
$this->assertText('Add vocabulary', "Found the Add vocabulary link.");
// Can we add a taxonomy manually?
$this->drupalGet("admin/structure/taxonomy/add");
$edit = array();
$edit['name'] = $this->randomName(8);
$edit['machine_name'] = strtolower($edit['name']);
$this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
$this->assertText(t('Created new vocabulary @name.', array('@name' => $edit['name'])));
}
/**
* Test creating a new vocabulary.
*/
function testCreateVocabulary() {
// Visit the main taxonomy administration page.
$this->drupalGet('admin/structure/taxonomy');
// Assert our Vocab does not exist.
$keys = array_keys($this->extended_vocab);
$this->assertNoText($keys[0]);
$this->assertNoText($keys[1]);
// Create our test taxonomy from the base vocab
tde_build_vocabs($this->base_vocab);
$this->drupalGet('admin/structure/taxonomy/' . _tde_machine_name($keys[0]));
// Reload the main taxonomy administration page.
$this->drupalGet('admin/structure/taxonomy');
$this->assertText($keys[0]);
$this->assertNoText($keys[1]);
// Check our base vocabs terms
$this->drupalGet('admin/structure/taxonomy/' . _tde_machine_name($keys[0]));
$terms = $this->base_vocab[$keys[0]];
for ($i = 0; $i < count($terms); $i++) {
$this->assertText(
$terms[$i],
t('Term !name in !vocab was found.', array(
'!name' => $terms[$i],
'!vocab' => $keys[0],
))
);
}
// Extend Taxonomy with extra in the existing vocab and
// a new one
tde_build_vocabs($this->extended_vocab);
// Check we now have both.
$this->drupalGet('admin/structure/taxonomy');
$this->assertText($keys[0]);
$this->assertText($keys[1]);
// Check all the terms are in each.
for ($k = 0; $k < count($keys); $k++) {
$this->drupalGet('admin/structure/taxonomy/' . _tde_machine_name($keys[$k]));
$terms = $this->extended_vocab[$keys[$k]];
$flat_terms = array_walk_recursive(
$terms,
function($a) use (&$return) {
$return[] = $a;
}
);
for ($i = 0; $i < count($flat_terms); $i++) {
if (!empty($flat_terms[$i])) {
$this->assertText(
$flat_terms[$i],
t('Term !name in !vocab was found.', array(
'!name' => $flat_terms[$i],
'!vocab' => $keys[$k],
))
);
}
}
}
}
}