Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit e52112c

Browse files
committed
ENH: refs #0426. Add a test for search controller
1 parent ed981ed commit e52112c

File tree

6 files changed

+169
-5
lines changed

6 files changed

+169
-5
lines changed

core/controllers/SearchController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function indexAction()
6060
$results = $this->Component->Search->searchAll($this->userSession->Dao, $keyword, $order);
6161
if(isset($ajax))
6262
{
63-
$this->_helper->layout->disableLayout();
63+
$this->disableLayout();
6464
$this->_helper->viewRenderer->setNoRender();
6565
echo JsonComponent::encode($results);
6666
}
@@ -86,7 +86,7 @@ public function liveAction()
8686
// ajax requests simultaneously
8787
session_write_close();
8888

89-
$this->_helper->layout->disableLayout();
89+
$this->disableLayout();
9090
$this->_helper->viewRenderer->setNoRender();
9191

9292
$search = $this->getRequest()->getParam('term');

core/public/js/item/item.editmetadata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
$(document).ready(function() {
3-
3+
44
jsonMetadata = jQuery.parseJSON($('div#jsonMetadata').html());
55
initElementMetaData();
66
$('select, input').change(function(){

core/tests/controllers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_midas_test( BrowseController BrowseControllerTest.php )
22
add_midas_test( FeedController FeedControllerTest.php )
33
add_midas_test( ItemController ItemControllerTest.php )
4+
add_midas_test( SearchController SearchControllerTest.php )
45
add_midas_test( UploadDownloadController UploadDownloadControllerTest.php )
56
add_midas_test( UserController UserControllerTest.php )
67

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
/** test search controller*/
21+
class SearchControllerTest extends ControllerTestCase
22+
{
23+
24+
/** init test*/
25+
public function setUp()
26+
{
27+
$this->setupDatabase(array('default'));
28+
$this->_models = array('User');
29+
parent::setUp();
30+
}
31+
32+
/** Test the search results page */
33+
public function testIndexAction()
34+
{
35+
$this->dispatchUrI('/search/?q=name');
36+
$this->assertController('search');
37+
$this->assertAction('index');
38+
39+
$this->resetAll();
40+
$this->dispatchUrI('/search/?q=name&ajax');
41+
$this->assertController('search');
42+
$this->assertAction('index');
43+
44+
$resp = json_decode($this->getBody());
45+
$this->assertEquals($resp->nitems, 0);
46+
$this->assertEquals($resp->nfolders, 2);
47+
$this->assertEquals($resp->ncommunities, 0);
48+
$this->assertEquals($resp->nusers, 2);
49+
50+
$this->assertEquals(count($resp->results), 4);
51+
52+
// First results should be the users
53+
$this->assertEquals($resp->results[0]->resultType, 'user');
54+
$this->assertEquals($resp->results[1]->resultType, 'user');
55+
$this->assertTrue(is_numeric($resp->results[0]->user_id));
56+
$this->assertTrue(is_numeric($resp->results[1]->user_id));
57+
$this->assertNotEmpty($resp->results[0]->firstname);
58+
$this->assertNotEmpty($resp->results[1]->firstname);
59+
$this->assertNotEmpty($resp->results[0]->lastname);
60+
$this->assertNotEmpty($resp->results[1]->lastname);
61+
62+
// Next results should be the folders
63+
$this->assertEquals($resp->results[2]->resultType, 'folder');
64+
$this->assertEquals($resp->results[3]->resultType, 'folder');
65+
$this->assertTrue(is_numeric($resp->results[2]->folder_id));
66+
$this->assertTrue(is_numeric($resp->results[3]->folder_id));
67+
$this->assertNotEmpty($resp->results[2]->name);
68+
$this->assertNotEmpty($resp->results[3]->name);
69+
}
70+
71+
/** Test the live search response */
72+
public function testLiveSearch()
73+
{
74+
$this->dispatchUrI('/search/live?term=name');
75+
$this->assertController('search');
76+
$this->assertAction('live');
77+
78+
$resp = json_decode($this->getBody());
79+
80+
// Ensure we get item and user results from live search
81+
$this->assertEquals(count($resp), 4);
82+
$this->assertEquals($resp[0]->category, 'Folders');
83+
$this->assertNotEmpty($resp[0]->value);
84+
$this->assertTrue(is_numeric($resp[0]->folderid));
85+
$this->assertEquals($resp[1]->category, 'Folders');
86+
$this->assertNotEmpty($resp[1]->value);
87+
$this->assertTrue(is_numeric($resp[1]->folderid));
88+
$this->assertEquals($resp[2]->category, 'Users');
89+
$this->assertNotEmpty($resp[2]->value);
90+
$this->assertTrue(is_numeric($resp[2]->userid));
91+
$this->assertEquals($resp[3]->category, 'Users');
92+
$this->assertNotEmpty($resp[3]->value);
93+
$this->assertTrue(is_numeric($resp[3]->userid));
94+
95+
// Ensure we get community results from live search
96+
$this->resetAll();
97+
$this->dispatchUrI('/search/live?term=community');
98+
$this->assertController('search');
99+
$this->assertAction('live');
100+
$resp = json_decode($this->getBody());
101+
$this->assertEquals(count($resp), 1);
102+
$this->assertEquals($resp[0]->category, 'Communities');
103+
$this->assertTrue(is_numeric($resp[0]->communityid));
104+
$this->assertNotEmpty($resp[0]->label);
105+
$this->assertNotEmpty($resp[0]->value);
106+
107+
// Ensure we get group results from live search with shareSearch enabled
108+
$this->resetAll();
109+
$this->dispatchUrI('/search/live?term=community&shareSearch');
110+
$this->assertController('search');
111+
$this->assertAction('live');
112+
$resp = json_decode($this->getBody());
113+
$this->assertEquals(count($resp), 3);
114+
foreach($resp as $result)
115+
{
116+
$this->assertEquals($result->category, 'Groups');
117+
$this->assertTrue(is_numeric($result->groupid));
118+
$this->assertNotEmpty($result->label);
119+
$this->assertNotEmpty($result->value);
120+
}
121+
122+
// Ensure we get only user results from live search with userSearch enabled
123+
$this->resetAll();
124+
$this->dispatchUrI('/search/live?term=name&userSearch');
125+
$this->assertController('search');
126+
$this->assertAction('live');
127+
$resp = json_decode($this->getBody());
128+
$this->assertEquals(count($resp), 2);
129+
foreach($resp as $result)
130+
{
131+
$this->assertEquals($result->category, 'Users');
132+
$this->assertTrue(is_numeric($result->userid));
133+
$this->assertNotEmpty($result->label);
134+
$this->assertNotEmpty($result->value);
135+
}
136+
137+
// Ensure we can't see items that we don't have read permissions on
138+
$this->resetAll();
139+
$this->dispatchUrI('/search/live?term=name&itemSearch');
140+
$this->assertController('search');
141+
$this->assertAction('live');
142+
$resp = json_decode($this->getBody());
143+
$this->assertEquals(count($resp), 0);
144+
145+
// Ensure we get item results from live search with itemSearch enabled if user has permissions
146+
$usersFile = $this->loadData('User', 'default');
147+
$userDao = $this->User->load($usersFile[2]->getKey());
148+
$this->resetAll();
149+
$this->dispatchUrI('/search/live?term=name&itemSearch', $userDao);
150+
$this->assertController('search');
151+
$this->assertAction('live');
152+
$resp = json_decode($this->getBody());
153+
154+
$this->assertEquals(count($resp), 1);
155+
foreach($resp as $result)
156+
{
157+
$this->assertEquals($result->category, 'Items');
158+
$this->assertTrue(is_numeric($result->itemid));
159+
$this->assertNotEmpty($result->label);
160+
$this->assertNotEmpty($result->value);
161+
}
162+
}
163+
}

core/translation/fr-main.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Group's members;Membres du groupe
166166
Create a new Folder;Créer un nouveau répertoire
167167
Advanced search;Recherche avancée
168168
Sort by;Trier par
169-
All the results;Tous les résultats
169+
All results;Tous les résultats
170170
Number of views;Nombre de vues
171171
No result found.;Aucun résultat trouvé pour votre recherche.
172172
Show more results.;Montrer plus de résultats.

core/views/search/index.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $this->headScript()->appendFile($this->coreWebroot.'/public/js/search/search.ind
2424
<ul>
2525
<li><a id="allResults">
2626
<img alt='' src="<?php echo $this->coreWebroot?>/public/images/FileTree/zip.png"/>
27-
<?php echo $this->t('All the results')?> (<?php echo ($this->nitems+$this->nusers+$this->nfolders+$this->ncommunities)?>)</a></li>
27+
<?php echo $this->t('All results')?> (<?php echo ($this->nitems+$this->nusers+$this->nfolders+$this->ncommunities)?>)</a></li>
2828
<li><a id="itemResults">
2929
<img alt='' src="<?php echo $this->coreWebroot?>/public/images/FileTree/txt.png"/>
3030
<?php echo $this->t('Items')?></a> (<?php echo $this->nitems?>)</li>

0 commit comments

Comments
 (0)