forked from artesis/ding_facetbrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathding_facetbrowser.test
More file actions
160 lines (137 loc) · 5.71 KB
/
ding_facetbrowser.test
File metadata and controls
160 lines (137 loc) · 5.71 KB
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
<?php
class DingFacetbrowserUnit extends DrupalUnitTestCase {
static function getInfo() {
return array(
'name' => t('Ding Facetbrowser Unit tests'),
'description' => t('Unit tests for the Ding Facetbrowser module'),
'group' => 'Ding! - Facetbrowser',
);
}
function testFacetbrowser() {
drupal_load('module', 'ding_facetbrowser');
$form = array();
$form_state = array();
$facets = array();
$facets['First area'] = (object) array(
'name' => 'Loremipsum',
'terms' => array(
'Dolor' => 3,
'Vestibulum' => 'Vestibulum',
),
);
$facets['Second area'] = (object) array(
'name' => 'Nullamdolor',
'terms' => array(
'Sagittis' => 2,
'Adipiscing' => 3,
'Lobortis' => 3,
'Massa' => 'Vestibulum',
),
);
$facet_form = ding_facetbrowser_form($form, $form_state, $facets);
$this->assertTrue(is_array($facet_form), 'Facetbrowser form is an array');
foreach ($facet_form as $name => $value) {
if ($value['#type'] != 'submit' && !empty($value[$name])) {
$this->assertTrue(is_array($value), $name . ' is an array and a ' . $value['#type']);
$this->assertTrue(is_array($value[$name]['#options']), $name . ' is a ' . $value[$name]['#type'] . ' contains ' . count($value[$name]['#options']) . ' facets');
}
}
}
}
class DingFacetbrowserWeb extends DrupalWebTestCase {
static function getInfo() {
return array(
'name' => t('Ding Facetbrowser Web Tests'),
'description' => t('Webtests for the Ding Facetbrowser module'),
'group' => 'Ding! - Facetbrowser',
);
}
public function setUp() {
$this->profile = 'minimal';
parent::setUp('ting', 'ding_facetbrowser', 'search', 'ting_search');
variable_set('ting_agency', '100200');
variable_set('ting_search_url', 'http://opensearch.addi.dk/next_2.0/');
variable_set('ting_scan_url', 'http://openscan.addi.dk/1.7/');
variable_set('ting_spell_url', 'http://openspell.addi.dk/1.2/');
variable_set('ting_recommendation_url', 'http://openadhl.addi.dk/1.1/');
variable_set('search_active_modules', array('node' => 'node', 'ting_search' => 'ting_search'));
variable_set('search_default_module', 'ting_search');
// Set up some facets for testing.
variable_set('ding_facetbrowser_facets', array(
0 => array(
'name' => 'facet.subject',
'title' => '!!facet.subject!!',
'weight' => '-10',
),
1 => array(
'name' => 'facet.creator',
'title' => '!!facet.creator!!',
'weight' => '-9',
),
2 => array(
'name' => 'facet.type',
'title' => '!!facet.type!!',
'weight' => '-8',
),
3 => array(
'name' => 'facet.category',
'title' => '!!facet.category!!',
'weight' => '-7',
),
4 => array(
'name' => 'facet.language',
'title' => '!!facet.language!!',
'weight' => '-6',
),
5 => array(
'name' => 'facet.date',
'title' => '!!facet.date!!',
'weight' => '-5',
),
6 => array(
'name' => 'facet.acSource',
'title' => '!!facet.acSource!!',
'weight' => '-4',
),
)
);
$this->nodetype = $this->drupalCreateContentType();
$this->web_user = $this->drupalCreateUser(array('administer search', 'administer blocks', 'search content', 'create ' . $this->nodetype->name . ' content'));
$this->drupalLogin($this->web_user);
}
public function testFacetModules() {
// Check if search module is installed
$exists = module_exists('search');
$this->assertTrue($exists, 'Search is enabled');
// Check if ding_facetbrowser module is installed
$exists = module_exists('ding_facetbrowser');
$this->assertTrue($exists, 'Ding Facetbrowser is enabled');
// Check if the facetbrowser block is available
$this->drupalGet('admin/structure/block');
$this->assertRaw('Facet browser', 'The facetbrowser block is available');
$this->drupalPost('admin/structure/block', array('blocks[ding_facetbrowser_facetbrowser][region]' => 'content'), 'Save blocks');
$this->assertFieldByName('blocks[ding_facetbrowser_facetbrowser][region]', 'content', 'Configurable text block is enabled in first sidebar successfully verified.');
// Create a custom node containing the text 'harry'
$node_title = $this->randomName(10);
$node_info = array(
'title' => $node_title,
'body[und][0][value]' => 'Harry potter rocks',
);
$this->drupalPost('node/add/' . $this->nodetype->name, $node_info, t('Save'));
$node = $this->drupalGetNodeByTitle($node_title);
$this->assertTrue($node, t('Node ' . $node_title . ' found in database'));
// // Execute cron to update search index
$this->cronRun();
// // Search the site for harry
$this->drupalGet('search/node/harry');
$this->assertNoText('Harry rocks', 'Search for "Harry rocks" in drupal - failed');
$this->assertText('Harry potter rocks', 'Search for "Harry potter rocks" in drupal - complete');
$this->drupalGet('search/ting/harry');
$this->assertNoText('Da pensionisten Harry Browns gamle', 'Search for title from external search service NOT found');
$this->assertNoText('Harry potter rocks', "We're not seeing the node.");
$this->assertText('Harry Blotter', "'Harry Blotter' found.");
// Check if the facetbrowser has any content
$this->assertText('!!facet.subject!!', 'Found the facet.subject fieldset in the facetbrowser');
$this->assertFieldById('edit-subject-instrumental', 'instrumental', 'Found the \'instrumental\' facet in the facet.subject fieldset');
}
}