forked from grasmash/opendata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopendata.test
174 lines (151 loc) · 6.49 KB
/
opendata.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
<?php
/**
* Content test for Open Data.
*/
class OpenDataContentTestCase extends DrupalWebTestCase {
/**
* Implements getInfo().
*/
public static function getInfo() {
return array (
'name' => t('Content'),
'description' => t('Verifies correct content and content structure Open Data.'),
'group' => t('Open Data'),
);
}
public function setUp() {
// Enable modules.
parent::setUp('opendata', 'opendata_content');
}
public function testContent() {
// Load Catalog node. THIS DOESN'T WORK! Somehow, field values aren't set
// when opendata_content_catalog_node_create() is called by hook_install().
// $catalog_node = node_load($catalog_nid);
$catalog_node = opendata_content_catalog_node_create();
$catalog_nid = variable_get('opendata_catalog_node', 0);
// debug('Catalog node created: ' . var_export($catalog_node, TRUE));
$this->assertNotEqual($catalog_nid, 0, t('Catalog NID is set to @nid', array('@nid' => $catalog_nid)));
// Check that catalog fields are set.
$this->assertTrue(isset($catalog_node->field_opendata_distribution['und'][0]), t('Catalog node field_opendata_distribution is set.'));
$this->assertTrue(isset($catalog_node->field_opendata_identifier['und'][0]), t('Catalog node field_opendata_identifier is set.'));
$this->assertTrue(isset($catalog_node->field_opendata_mbox['und'][0]), t('Catalog node field_opendata_mbox is set.'));
}
}
/**
* JSON test for Open Data.
*/
class OpenDataJSONTestCase extends DrupalWebTestCase {
protected $privileged_user;
/**
* Implements getInfo().
*/
public static function getInfo() {
return array (
'name' => t('JSON'),
'description' => t('Verifies correct JSON output for Open Data.'),
'group' => t('Open Data'),
);
}
public function setUp() {
// Enable modules.
parent::setUp('opendata', 'opendata_content');
}
public function testViewJSON() {
$catalog_node = opendata_content_catalog_node_create();
$this->drupalGet('data.json');
$this->assertRaw(t('"title":!title', array('!title' => json_encode($catalog_node->title))), t('Data Catalog title JSON is displayed correctly.'));
$vars = array(
'!access_url' => json_encode($catalog_node->field_opendata_distribution['und'][0]['access_url']),
'!format' => json_encode($catalog_node->field_opendata_distribution['und'][0]['format']),
);
$this->assertRaw(t('"distribution":[{"accessURL":!access_url,"format":!format}]', $vars), t('Data Catalog distribution JSON is displayed correctly.'));
}
}
/**
* Administrator test for Open Data.
*/
class OpenDataAdminTestCase extends DrupalWebTestCase {
/**
* Implements getInfo().
*/
public static function getInfo() {
return array (
'name' => t('Admin'),
'description' => t('Verifies correct behavior for administering Open Data.'),
'group' => t('Open Data'),
);
}
public function setUp() {
// Enable modules.
parent::setUp('opendata', 'opendata_content');
// Create and log in our privileged user.
$this->privileged_user = $this->drupalCreateUser(array(
'administer site configuration',
));
$this->drupalLogin($this->privileged_user);
}
// @todo create this test.
public function testChangeAdminSettings() {
// $this->drupalGet('admin/config/services/opendata');
// $this->assertText(t('Simpletest Example Node Type @title has been created.', array('@title' => $edit['title'])));
}
// @todo create this test.
public function testCreateDataset() {
// Create node to edit.
// $edit = array();
// $edit['title'] = $this->randomName(8);
// $edit["body[und][0][value]"] = $this->randomName(16);
// post more fields.
// $this->drupalPost('node/add/opendata-dataset', $edit, t('Save'));
// $this->assertText(t('Simpletest Example Node Type @title has been created.', array('@title' => $edit['title'])));
}
}
/**
* HTML tests for Open Data.
*/
class OpenDataHTMLTestCase extends DrupalWebTestCase {
/**
* Implements getInfo().
*/
public static function getInfo() {
return array (
'name' => t('HTML'),
'description' => t('Verifies correct display of Open Data HTML.'),
'group' => t('Open Data'),
);
}
public function setUp() {
// Enable modules.
parent::setUp('opendata', 'opendata_content', 'opendata_view');
}
public function testViewHTML() {
// Load Catalog node.
$catalog_node = opendata_content_catalog_node_create();
$vars = array(
'@title' => $catalog_node->title,
'@description' => $catalog_node->field_opendata_description['und'][0]['value'],
'@keyword' => $catalog_node->field_opendata_keyword['und'][0]['value'],
'@modified' => $catalog_node->field_opendata_modified['und'][0]['value'],
'@publisher' => $catalog_node->field_opendata_publisher['und'][0]['value'],
'@person' => $catalog_node->field_opendata_person['und'][0]['value'],
'@mbox' => $catalog_node->field_opendata_mbox['und'][0]['email'],
'@identifier' => $catalog_node->field_opendata_identifier['und'][0]['value'],
'@access_level' => ucfirst($catalog_node->field_opendata_access_level['und'][0]['value']),
'@access_url' => $catalog_node->field_opendata_distribution['und'][0]['access_url'],
'@format' => $catalog_node->field_opendata_distribution['und'][0]['format'],
);
debug(t('@access_level', $vars));
$this->drupalGet('data');
$this->assertText(t('@title', $vars), t('Data catalog title is displayed correctly.'));
$this->assertText(t('@description', $vars), t('Data catalog description is displayed correctly.'));
$this->assertText(t('@keyword', $vars), t('Data catalog keyword is displayed correctly.'));
$this->assertText(t('@modified', $vars), t('Data catalog last update is displayed correctly.'));
$this->assertText(t('@publisher', $vars), t('Data catalog publisher is displayed correctly.'));
$this->assertText(t('@person', $vars), t('Data catalog person is displayed correctly.'));
$this->assertText(t('@mbox', $vars), t('Data catalog person is displayed correctly.'));
$this->assertText(t('@identifier', $vars), t('Data catalog identifier is displayed correctly.'));
$this->assertText(t('@access_level', $vars), t('Data catalog access level is displayed correctly.'));
$this->assertText(t('Download URL: @access_url', $vars), t('Data catalog download URL is displayed correctly.'));
$this->assertText(t('Format: @format', $vars), t('Data catalog distribution format is displayed correctly.'));
}
}