-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjournalstream.test
executable file
·265 lines (238 loc) · 9.4 KB
/
journalstream.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
class JournalStreamWebTestCase extends DrupalWebTestCase {
protected $biblio_node;
function setUp() {
// Enable any module that you will need in your tests.
parent::setUp('journalstream');
$web_user = $this->drupalCreateUser(array('create collection content','create topic_queue content', 'create biblio content', 'access overlay', 'edit any topic_queue content'));
$this->drupalLogin($web_user);
//Create a bilbio node for testing
$this->biblio_node = $this->createBiblioNode();
}
/**
* Helper function for creating biblio node
*/
function createBiblioNode($type = 100) {
$schema = drupal_get_schema('biblio');
foreach ($schema['fields'] as $name => $values) {
if ($values['type'] == 'int') continue;
switch ($values['type']) {
case 'varchar':
$length = $values['length'];
break;
case 'text':
$length = 1000;
break;
}
$biblio_fields["$name"] = $name;
}
$settings = array(
'title' => 'Biblio Title',
'type' => 'biblio', // This replaces the default type
'biblio_type' => $type, // This appends a new field.
'biblio_year' => 2009,
'biblio_contributors' => array(0 => array('name' => 'Ron J. Jeromezzzzzz', 'auth_type' => 1, 'auth_category' => 1),
1 => array('name' => 'John Smithzzzzzz', 'auth_type' => 1, 'auth_category' => 1),
2 => array('name' => 'George W. Bushzzzzzz', 'auth_type' => 1, 'auth_category' => 1)),
'biblio_keywords' => array('biblio_keywords')
);
$settings = array_merge($biblio_fields, $settings);
$node = $this->drupalCreateNode($settings);
return $node;
}
}
class JournalStreamNodeCreationTestCase extends JournalStreamWebTestCase {
public static function getInfo(){
return array(
'name' => 'JournalStream - Collection Node Creation',
'description' => 'Tests that a Collection node type has been created',
'group' => 'SCF',
);
}
function testCollectionNodeCreation() {
// Create a node.
$edit = array();
$node_type = 'collection';
$edit['title'] = 'Collection Title';
$this->drupalPost('node/add/collection', $edit, t('Save'));
$this->assertText(t('Collection @title has been created.', array('@title' => $edit['title'])));
$node = $this->drupalGetNodeByTitle($edit['title']);
$this->assertEqual($node->title, $edit['title']);
$this->assertEqual($node->type, $node_type);
}
/**
* TODO: This needs refactoring. Wasn't able to post [nid:xxx] to html form
*/
function testCollectionBiblioReference() {
$edit = array();
$edit['title'] = 'Collection Title';
$edit['type'] = 'collection';
$edit['field_papers'] = array(LANGUAGE_NONE => array(0 => array('nid' => $this->biblio_node->nid)));
$node = $this->drupalCreateNode($edit);
$this->assertNotNull($node->field_papers);
}
}
class SCFLibraryTopicQueueNodeCreationTestCase extends JournalStreamWebTestCase {
public static function getInfo(){
return array(
'name' => 'JournalStream - Topic Queue Node Creation',
'description' => 'Tests that a Topic Queue node type has been created',
'group' => 'SCF',
);
}
/**
* Test the creation of a topic queue node
*/
function testTopicQueueNodeCreation() {
$edit = array();
$edit['title'] = 'Topic Title';
$edit['type'] = 'topic-queue';
$node = $this->drupalCreateNode($edit);
$this->assertEqual($node->title, $edit['title']);
$this->assertEqual($node->type, $edit['type']);
}
/**
* Test the node reference fields of topic queue
*/
function testTopicQueueReferences() {
$edit = array();
$accepted_node = $this->createBiblioNode();
$rejected_node = $this->createBiblioNode();
$not_reviewed_node = $this->createBiblioNode();
$edit['title'] = 'Topic Title';
$edit['type'] = 'topic-queue';
$edit['field_accepted_nodes'] = array(LANGUAGE_NONE => array(0 => array('nid' => $accepted_node->nid)));
$edit['field_rejected_nodes'] = array(LANGUAGE_NONE => array(0 => array('nid' => $rejected_node->nid)));
$edit['field_not_reviewed_nodes'] = array(LANGUAGE_NONE => array(0 => array('nid' => $not_reviewed_node->nid)));
$node = $this->drupalCreateNode($edit);
$this->assertNotNull($node->field_accepted_nodes);
$this->assertNotNull($node->field_rejected_nodes);
$this->assertNotNull($node->field_not_reviewed_nodes);
}
/**
* Tests creating a collection from a topic queue
*/
/*
function testCollectionFromTopicQueue() {
$edit = array();
$accepted_node = $this->createBiblioNode();
$rejected_node = $this->createBiblioNode();
$not_reviewed_node = $this->createBiblioNode();
$edit['title'] = 'Topic Title';
$edit['type'] = 'topic-queue';
$edit['field_accepted_nodes'] = array(LANGUAGE_NONE => array(0 => array('nid' => $accepted_node->nid)));
$edit['field_rejected_nodes'] = array(LANGUAGE_NONE => array(0 => array('nid' => $rejected_node->nid)));
$edit['field_not_reviewed_nodes'] = array(LANGUAGE_NONE => array(0 => array('nid' => $not_reviewed_node->nid)));
$node = $this->drupalCreateNode($edit);
$this->assertNotNull($node);
//Create a collection
$collection['title'] = 'Collection Title';
$this->drupalPost('node/add/collection/' . $node->nid, $collection, t('Save'));
$this->assertText(t('Collection @title has been created.', array('@title' => $collection['title'])));
}
*/
}
class SCFLibraryAPITestCase extends JournalStreamWebTestCase {
protected $biblio_nodes;
public static function getInfo() {
return array(
'name' => 'JournalStream - API Tests',
'description' => 'Tests JournalStream Library API hooks',
'group' => 'SCF',
);
}
function setUp() {
parent::setUp('journalstream');
$this->biblio_nodes = array(
0 => $this->createBiblioNode(),
1 => $this->createBiblioNode(),
2 => $this->createBiblioNode(),
);
}
/**
* Test journalstream_add_to_queue
*/
function testAddToQueueHook() {
$queue_nodes = array();
foreach($this->biblio_nodes as $node) {
$queue_nodes[] = $node->nid;
}
//Create Node
$edit = array();
$edit['title'] = 'Topic Title';
$this->drupalPost('node/add/topic-queue', $edit, t('Save'));
$this->assertText(t('Topic Queue @title has been created.', array('@title' => $edit['title'])));
$node = $this->drupalGetNodeByTitle($edit['title']);
$this->assertNotEqual($node,FALSE);
//Test Not Reviewed
journalstream_add_to_queue($queue_nodes,$node->nid,'not_reviewed');
$node = node_load($node->nid);
$this->assertFalse(empty($node->field_not_reviewed_nodes));
//Test Accepted
$node = node_load($node->nid);
journalstream_add_to_queue($queue_nodes,$node->nid,'accepted');
$this->assertFalse(empty($node->field_accepted_nodes));
//Test Rejected
$node = node_load($node->nid);
journalstream_add_to_queue($queue_nodes,$node->nid,'rejected');
$this->assertFalse(empty($node->field_rejected_nodes));
}
}
class JournalStreamViewsTestCase extends JournalStreamWebTestCase{
protected $topic_queue_node;
public static function getInfo() {
return array(
'name' => 'JournalStream - Views Test Case',
'description' => 'Tests SCF Library Views (moderation queue)',
'group' => 'SCF',
);
}
function setUp() {
parent::setUp('journalstream');
$this->createTopicQueue();
}
function testQueueViews() {
$this->drupalGet('node/' . $this->topic_queue_node->nid);
$not_reviewed_nodes = array();
$acceppted_nodes = array();
$rejected_nodes = array();
$i = 0;
while($i < 3) {
$not_reviewed_nodes[] = $this->createBiblioNode();
$accepted_nodes[] = $this->createBiblioNode();
$rejected_nodes[] = $this->createBiblioNode();
$i++;
}
function get_nid($val) {
return $val->nid;
}
//Test Not Reviewed Queue
journalstream_add_to_queue(array_map('get_nid',$not_reviewed_nodes),$this->topic_queue_node->nid,'not_reviewed');
$node = node_load($this->topic_queue_node->nid);
$this->assertFalse(empty($node->field_not_reviewed_nodes));
$this->drupalGet('node/' . $this->topic_queue_node->nid . '/not_reviewed');
$this->assertText($not_reviewed_nodes[0]->title);
//Test Accepted Queue
journalstream_add_to_queue(array_map('get_nid',$accepted_nodes),$this->topic_queue_node->nid,'accepted');
$node = node_load($this->topic_queue_node->nid);
$this->assertFalse(empty($node->field_accepted_nodes));
$this->drupalGet('node/' . $this->topic_queue_node->nid . '/accepted');
$this->assertText($accepted_nodes[0]->title);
//Test Rejected Queue
journalstream_add_to_queue(array_map('get_nid',$rejected_nodes),$this->topic_queue_node->nid,'rejected');
$node = node_load($this->topic_queue_node->nid);
$this->assertFalse(empty($node->field_rejected_nodes));
$this->drupalGet('node/' . $this->topic_queue_node->nid . '/rejected');
$this->assertText($rejected_nodes[0]->title);
//Test Preview Queue
$this->drupalGet('node/' . $this->topic_queue_node->nid . '/preview');
$this->assertText($accepted_nodes[0]->title);
}
function createTopicQueue() {
$edit = array();
$edit['title'] = 'Topic Title';
$this->drupalPost('node/add/topic-queue', $edit, t('Save'));
$this->topic_queue_node = $this->drupalGetNodeByTitle($edit['title']);
}
}
?>