]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/ListView/ListViewDisplayTest.php
Release 6.5.10
[Github/sugarcrm.git] / tests / include / ListView / ListViewDisplayTest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37  
38 require_once 'include/ListView/ListViewDisplay.php';
39
40 class ListViewDisplayTest extends Sugar_PHPUnit_Framework_TestCase
41 {
42     private $save_query;
43
44     public function setUp()
45     {
46         $this->_lvd = new ListViewDisplayMock();
47         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
48         $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
49         global $sugar_config;
50         if(isset($sugar_config['save_query']))
51         {
52             $this->save_query = $sugar_config['save_query'];
53         }
54     }
55
56     public function tearDown()
57     {
58         global $sugar_config;
59         if(!empty($this->save_query))
60         {
61             $sugar_config['save_query'] = $this->save_query;
62         }
63         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
64         unset($GLOBALS['current_user']);
65         unset($GLOBALS['app_strings']);
66     }
67
68     public function testConstructor()
69     {
70         $this->assertInstanceOf('ListViewData',$this->_lvd->lvd);
71         $this->assertInternalType('array',$this->_lvd->searchColumns);
72     }
73
74     public function testShouldProcessWhenConfigSaveQueryIsNotSet()
75     {
76         if ( isset($GLOBALS['sugar_config']['save_query']) ) {
77             $oldsavequery = $GLOBALS['sugar_config']['save_query'];
78         }
79         $GLOBALS['sugar_config']['save_query'] = null;
80
81         $this->assertTrue($this->_lvd->shouldProcess('foo'));
82         $this->assertTrue($this->_lvd->should_process);
83
84         if ( isset($oldsavequery) ) {
85             $GLOBALS['sugar_config']['save_query'] = $oldsavequery;
86         }
87     }
88
89     public function testShouldProcessWhenConfigSaveQueryIsNotPopulateOnly()
90     {
91         if ( isset($GLOBALS['sugar_config']['save_query']) ) {
92             $oldsavequery = $GLOBALS['sugar_config']['save_query'];
93         }
94         $GLOBALS['sugar_config']['save_query'] = 'populate_always';
95
96         $this->assertTrue($this->_lvd->shouldProcess('foo'));
97         $this->assertTrue($this->_lvd->should_process);
98
99         if ( isset($oldsavequery) ) {
100             $GLOBALS['sugar_config']['save_query'] = $oldsavequery;
101         }
102     }
103
104     public function testShouldProcessWhenGlobalDisplayListViewIsTrue()
105     {
106         if ( isset($GLOBALS['sugar_config']['save_query']) ) {
107             $oldsavequery = $GLOBALS['sugar_config']['save_query'];
108         }
109         $GLOBALS['sugar_config']['save_query'] = 'populate_only';
110         $GLOBALS['displayListView'] = true;
111
112         $this->assertTrue($this->_lvd->shouldProcess('foo'));
113         $this->assertTrue($this->_lvd->should_process);
114
115         if ( isset($oldsavequery) ) {
116             $GLOBALS['sugar_config']['save_query'] = $oldsavequery;
117         }
118     }
119
120     public function testShouldProcessWhenGlobalDisplayListViewIsFalseAndRequestClearQueryIsTrue()
121     {
122         if ( isset($GLOBALS['sugar_config']['save_query']) ) {
123             $oldsavequery = $GLOBALS['sugar_config']['save_query'];
124         }
125         $GLOBALS['sugar_config']['save_query'] = 'populate_only';
126         $GLOBALS['displayListView'] = false;
127         $_REQUEST['clear_query'] = true;
128         $_REQUEST['module'] = 'foo';
129
130         $this->assertFalse($this->_lvd->shouldProcess('foo'));
131         $this->assertFalse($this->_lvd->should_process);
132
133         if ( isset($oldsavequery) ) {
134             $GLOBALS['sugar_config']['save_query'] = $oldsavequery;
135         }
136     }
137
138     public function testShouldProcessWhenGlobalDisplayListViewIsFalseAndRequestClearQueryIsFalseAndModulesDoNotEqual()
139     {
140         if ( isset($GLOBALS['sugar_config']['save_query']) ) {
141             $oldsavequery = $GLOBALS['sugar_config']['save_query'];
142         }
143         $GLOBALS['sugar_config']['save_query'] = 'populate_only';
144         $GLOBALS['displayListView'] = false;
145         $_REQUEST['clear_query'] = false;
146         $_REQUEST['module'] = 'bar';
147
148         $this->assertTrue($this->_lvd->shouldProcess('foo'));
149         $this->assertTrue($this->_lvd->should_process);
150
151         if ( isset($oldsavequery) ) {
152             $GLOBALS['sugar_config']['save_query'] = $oldsavequery;
153         }
154     }
155
156     public function testShouldProcessWhenGlobalDisplayListViewIsFalseAndRequestClearQueryIsFalseAndModulesDoEqualAndQueryIsEmpty()
157     {
158         if ( isset($GLOBALS['sugar_config']['save_query']) ) {
159             $oldsavequery = $GLOBALS['sugar_config']['save_query'];
160         }
161         $GLOBALS['sugar_config']['save_query'] = 'populate_only';
162         $GLOBALS['displayListView'] = false;
163         $_REQUEST['clear_query'] = false;
164         $_REQUEST['module'] = 'foo';
165         $_REQUEST['query'] = '';
166         $_SESSION['last_search_mod'] = '';
167
168         $this->assertFalse($this->_lvd->shouldProcess('foo'));
169         $this->assertFalse($this->_lvd->should_process);
170
171         if ( isset($oldsavequery) ) {
172             $GLOBALS['sugar_config']['save_query'] = $oldsavequery;
173         }
174     }
175
176     public function testShouldProcessWhenGlobalDisplayListViewIsFalseAndRequestClearQueryIsFalseAndModulesDoEqualAndQueryEqualsMsi()
177     {
178         if ( isset($GLOBALS['sugar_config']['save_query']) ) {
179             $oldsavequery = $GLOBALS['sugar_config']['save_query'];
180         }
181         $GLOBALS['sugar_config']['save_query'] = 'populate_only';
182         $GLOBALS['displayListView'] = false;
183         $_REQUEST['clear_query'] = false;
184         $_REQUEST['module'] = 'foo';
185         $_REQUEST['query'] = 'MSI';
186         $_SESSION['last_search_mod'] = '';
187
188         $this->assertFalse($this->_lvd->shouldProcess('foo'));
189         $this->assertFalse($this->_lvd->should_process);
190
191         if ( isset($oldsavequery) ) {
192             $GLOBALS['sugar_config']['save_query'] = $oldsavequery;
193         }
194     }
195
196     public function testShouldProcessWhenGlobalDisplayListViewIsFalseAndRequestClearQueryIsFalseAndModulesDoNotEqualAndQueryDoesNotEqualsMsi()
197     {
198         if ( isset($GLOBALS['sugar_config']['save_query']) ) {
199             $oldsavequery = $GLOBALS['sugar_config']['save_query'];
200         }
201         $GLOBALS['sugar_config']['save_query'] = 'populate_only';
202         $GLOBALS['displayListView'] = false;
203         $_REQUEST['clear_query'] = false;
204         $_REQUEST['module'] = 'foo';
205         $_REQUEST['query'] = 'xMSI';
206         $_SESSION['last_search_mod'] = '';
207
208         $this->assertTrue($this->_lvd->shouldProcess('foo'));
209         $this->assertTrue($this->_lvd->should_process);
210
211         if ( isset($oldsavequery) ) {
212             $GLOBALS['sugar_config']['save_query'] = $oldsavequery;
213         }
214     }
215
216     public function testShouldProcessWhenGlobalDisplayListViewIsFalseAndRequestClearQueryIsFalseAndModulesDoEqualAndLastSearchModEqualsModule()
217     {
218         if ( isset($GLOBALS['sugar_config']['save_query']) ) {
219             $oldsavequery = $GLOBALS['sugar_config']['save_query'];
220         }
221         $GLOBALS['sugar_config']['save_query'] = 'populate_only';
222         $GLOBALS['displayListView'] = false;
223         $_REQUEST['clear_query'] = false;
224         $_REQUEST['module'] = 'foo';
225         $_REQUEST['query'] = '';
226         $_SESSION['last_search_mod'] = 'foo';
227
228         //C.L. Because of fix to 40186, the following two tests are now set to assertFalse
229         $this->assertFalse($this->_lvd->shouldProcess('foo'), 'Assert that ListViewDisplay->shouldProcess is false even if module is the same because no query was specified');
230         $this->assertFalse($this->_lvd->should_process, 'Assert that ListViewDisplay->shouldProcess class variable is false');
231
232         if ( isset($oldsavequery) ) {
233             $GLOBALS['sugar_config']['save_query'] = $oldsavequery;
234         }
235     }
236
237     public function testShouldProcessWhenGlobalDisplayListViewIsFalseAndRequestClearQueryIsFalseAndModulesDoEqualAndLastSearchModDoesNotEqualsModule()
238     {
239         if ( isset($GLOBALS['sugar_config']['save_query']) ) {
240             $oldsavequery = $GLOBALS['sugar_config']['save_query'];
241         }
242         $GLOBALS['sugar_config']['save_query'] = 'populate_only';
243         $GLOBALS['displayListView'] = false;
244         $_REQUEST['clear_query'] = false;
245         $_REQUEST['module'] = 'foo';
246         $_REQUEST['query'] = '';
247         $_SESSION['last_search_mod'] = 'bar';
248
249         $this->assertFalse($this->_lvd->shouldProcess('foo'));
250         $this->assertFalse($this->_lvd->should_process);
251
252         if ( isset($oldsavequery) ) {
253             $GLOBALS['sugar_config']['save_query'] = $oldsavequery;
254         }
255     }
256
257     public function testProcess()
258     {
259         $data = array(
260             'data' => array(1,2,3),
261             'pageData' => array('bean' => array('moduleDir'=>'testmoduledir'))
262             );
263         $this->_lvd->process('foo',$data,'testmetestme');
264
265         $this->assertEquals(3,$this->_lvd->rowCount);
266         $this->assertEquals('testmoduledir2_TESTMETESTME_offset',$this->_lvd->moduleString);
267     }
268
269     public function testDisplayIfShouldNotProcess()
270     {
271         $this->_lvd->should_process = false;
272
273         $this->assertEmpty($this->_lvd->display());
274     }
275
276     public function testDisplayIfMultiSelectFalse()
277     {
278         $this->_lvd->should_process = true;
279         $this->_lvd->multiSelect = false;
280
281         $this->assertEmpty($this->_lvd->display());
282     }
283
284     public function testDisplayIfShowMassUpdateFormFalse()
285     {
286         $this->_lvd->should_process = true;
287         $this->_lvd->show_mass_update_form = false;
288
289         $this->assertEmpty($this->_lvd->display());
290     }
291
292     public function testDisplayIfShowMassUpdateFormTrueAndMultiSelectTrue()
293     {
294         $this->_lvd->should_process = true;
295         $this->_lvd->show_mass_update_form = true;
296         $this->_lvd->multiSelect = true;
297         $this->_lvd->multi_select_popup = true;
298         $this->_lvd->mass = $this->getMock('MassUpdate');
299         $this->_lvd->mass->expects($this->any())
300                          ->method('getDisplayMassUpdateForm')
301                          ->will($this->returnValue('foo'));
302         $this->_lvd->mass->expects($this->any())
303                          ->method('getMassUpdateFormHeader')
304                          ->will($this->returnValue('bar'));
305
306         $this->assertEquals('foobar',$this->_lvd->display());
307     }
308
309     public function testBuildSelectLink()
310     {
311         $output = $this->_lvd->buildSelectLink();
312         $output = implode($output['buttons'],"");
313         $this->assertContains("<a id='select_link'",$output);
314         $this->assertContains("sListView.check_all(document.MassUpdate, \"mass[]\", true, 0)",$output);
315         $this->assertContains("sListView.check_entire_list(document.MassUpdate, \"mass[]\",true,0);",$output);
316     }
317
318     public function testBuildSelectLinkWithParameters()
319     {
320         $output = $this->_lvd->buildSelectLink('testtest',1,2);
321         $output = implode($output['buttons'],"");
322         $this->assertContains("<a id='testtest'",$output);
323         $this->assertContains("sListView.check_all(document.MassUpdate, \"mass[]\", true, 2)",$output);
324         $this->assertContains("sListView.check_entire_list(document.MassUpdate, \"mass[]\",true,1);",$output);
325     }
326
327     public function testBuildSelectLinkWithPageTotalLessThanZero()
328     {
329         $output = $this->_lvd->buildSelectLink('testtest',1,-1);
330         $output = implode($output['buttons'],"");
331         $this->assertContains("<a id='testtest'",$output);
332         $this->assertContains("sListView.check_all(document.MassUpdate, \"mass[]\", true, 1)",$output);
333         $this->assertContains("sListView.check_entire_list(document.MassUpdate, \"mass[]\",true,1);",$output);
334     }
335
336     public function testBuildExportLink()
337     {
338         $this->_lvd->seed = new stdClass;
339         $this->_lvd->seed->module_dir = 'testtest';
340         $output = $this->_lvd->buildExportLink();
341
342         $this->assertContains("return sListView.send_form(true, 'testtest', 'index.php?entryPoint=export',",$output);
343     }
344
345     public function testBuildMassUpdateLink()
346     {
347         $output = $this->_lvd->buildMassUpdateLink();
348         
349         $this->assertRegExp("/.*document\.getElementById\(['\"]massupdate_form['\"]\)\.style\.display\s*=\s*['\"]['\"].*/", $output);
350     }
351
352     public function testComposeEmailIfFieldDefsNotAnArray()
353     {
354         $this->_lvd->seed = new stdClass;
355         $this->_lvd->seed->field_defs = false;
356         
357         $this->assertEmpty($this->_lvd->buildComposeEmailLink(0));
358     }
359
360     public function testComposeEmailIfFieldDefsAreAnEmptyArray()
361     {
362         $this->_lvd->seed = new stdClass;
363         $this->_lvd->seed->field_defs = array();
364
365         $this->assertEmpty($this->_lvd->buildComposeEmailLink(0));
366     }
367
368     public function testComposeEmailIfFieldDefsDoNotHaveAnEmailAddressesRelationship()
369     {
370         $this->_lvd->seed = new stdClass;
371         $this->_lvd->seed->object_name = 'foobar';
372         $this->_lvd->seed->field_defs = array(
373             'field1' => array(
374                 'type' => 'text',
375                 ),
376             );
377
378         $this->assertEmpty($this->_lvd->buildComposeEmailLink(0));
379     }
380
381     public function testComposeEmailIfFieldDefsIfUsingSugarEmailClient()
382     {
383         $this->_lvd->seed = new stdClass;
384         $this->_lvd->seed->object_name = 'foobar';
385         $this->_lvd->seed->module_dir = 'foobarfoobar';
386         $this->_lvd->seed->field_defs = array(
387             'field1' => array(
388                 'type' => 'link',
389                 'relationship' => 'foobar_emailaddresses',
390                 ),
391             );
392         $GLOBALS['dictionary']['foobar']['relationships']['foobar_emailaddresses']['rhs_module'] = 'EmailAddresses';
393         $GLOBALS['current_user']->setPreference('email_link_type','sugar');
394
395         $output = $this->_lvd->buildComposeEmailLink(5);
396
397         $this->assertContains(', \'foobarfoobar\', \'5\', ',$output);
398
399         unset($GLOBALS['dictionary']['foobar']);
400     }
401
402     public function testComposeEmailIfFieldDefsIfUsingExternalEmailClient()
403     {
404         $this->_lvd->seed = new stdClass;
405         $this->_lvd->seed->object_name = 'foobar';
406         $this->_lvd->seed->module_dir = 'foobarfoobar';
407         $_REQUEST['module'] = 'foobarfoobar';
408         $this->_lvd->seed->field_defs = array(
409             'field1' => array(
410                 'type' => 'link',
411                 'relationship' => 'foobar_emailaddresses',
412                 ),
413             );
414         $_REQUEST['module'] = 'foo';
415         
416         $GLOBALS['dictionary']['foobar']['relationships']['foobar_emailaddresses']['rhs_module'] = 'EmailAddresses';
417         $GLOBALS['current_user']->setPreference('email_link_type','mailto');
418
419         $output = $this->_lvd->buildComposeEmailLink(5);
420
421         $this->assertContains('sListView.use_external_mail_client',$output);
422
423         unset($GLOBALS['dictionary']['foobar']);
424         unset($_REQUEST['module']);
425     }
426
427     public function testBuildDeleteLink()
428     {
429         $output = $this->_lvd->buildDeleteLink();
430
431         $this->assertContains("return sListView.send_mass_update",$output);
432     }
433
434     public function testBuildSelectedObjectsSpan()
435     {
436         $output = $this->_lvd->buildSelectedObjectsSpan(1,1);
437
438         $this->assertContains("<input  style='border: 0px; background: transparent; font-size: inherit; color: inherit' type='text' id='selectCountTop' readonly name='selectCount[]' value='1' />",$output);
439     }
440
441     public function testBuildMergeDuplicatesLinkWithNoAccess()
442     {
443         $this->markTestIncomplete('This test has not been implemented yet.');
444     }
445
446     public function testBuildMergeDuplicatesLinkWhenModuleDoesNotHaveItEnabled()
447     {
448         $this->_lvd->seed = new stdClass;
449         $this->_lvd->seed->object_name = 'foobar';
450         $this->_lvd->seed->module_dir = 'foobarfoobar';
451         $GLOBALS['dictionary']['foobar']['duplicate_merge'] = false;
452         $GLOBALS['current_user']->is_admin = 1;
453
454         $this->assertEmpty($this->_lvd->buildMergeDuplicatesLink());
455     }
456
457     public function testBuildMergeDuplicatesLink()
458     {
459         $this->_lvd->seed = new stdClass;
460         $this->_lvd->seed->object_name = 'foobar';
461         $this->_lvd->seed->module_dir = 'foobarfoobar';
462         $GLOBALS['dictionary']['foobar']['duplicate_merge'] = true;
463         $GLOBALS['current_user']->is_admin = 1;
464
465         $output = $this->_lvd->buildMergeDuplicatesLink();
466
467         $this->assertContains("\"foobarfoobar\",\"\");}",$output);
468     }
469
470     public function testBuildMergeDuplicatesLinkBuildsReturnString()
471     {
472         $this->_lvd->seed = new stdClass;
473         $this->_lvd->seed->object_name = 'foobar';
474         $this->_lvd->seed->module_dir = 'foobarfoobar';
475         $GLOBALS['dictionary']['foobar']['duplicate_merge'] = true;
476         $GLOBALS['current_user']->is_admin = 1;
477         $_REQUEST['module'] = 'foo';
478         $_REQUEST['action'] = 'bar';
479         $_REQUEST['record'] = '1';
480
481         $output = $this->_lvd->buildMergeDuplicatesLink();
482
483         $this->assertContains("\"foobarfoobar\",\"&return_module=foo&return_action=bar&return_id=1\");}",$output);
484     }
485     public function testBuildMergeLinkWhenUserDisabledMailMerge()
486     {
487         $this->_lvd->seed = new stdClass;
488         $this->_lvd->seed->module_dir = 'foobarfoobar';
489         $GLOBALS['current_user']->setPreference('mailmerge_on','off');
490
491         $this->assertEmpty($this->_lvd->buildMergeLink());
492     }
493
494     public function testBuildMergeLinkWhenSystemDisabledMailMerge()
495     {
496         $this->_lvd->seed = new stdClass;
497         $this->_lvd->seed->module_dir = 'foobarfoobar';
498
499         $GLOBALS['current_user']->setPreference('mailmerge_on','on');
500
501         $settings_cache = sugar_cache_retrieve('admin_settings_cache');
502         if ( empty($settings_cache) ) {
503             $settings_cache = array();
504         }
505         $settings_cache['system_mailmerge_on'] = false;
506         sugar_cache_put('admin_settings_cache',$settings_cache);
507
508         $this->assertEmpty($this->_lvd->buildMergeLink());
509
510         sugar_cache_clear('admin_settings_cache');
511     }
512
513     public function testBuildMergeLinkWhenModuleNotInModulesArray()
514     {
515         $this->_lvd->seed = new stdClass;
516         $this->_lvd->seed->module_dir = 'foobarfoobar';
517
518         $GLOBALS['current_user']->setPreference('mailmerge_on','on');
519
520         $settings_cache = sugar_cache_retrieve('admin_settings_cache');
521         if ( empty($settings_cache) ) {
522             $settings_cache = array();
523         }
524         $settings_cache['system_mailmerge_on'] = true;
525         sugar_cache_put('admin_settings_cache',$settings_cache);
526
527         $this->assertEmpty($this->_lvd->buildMergeLink(array('foobar' => 'foobar')));
528
529         sugar_cache_clear('admin_settings_cache');
530     }
531
532     public function testBuildMergeLink()
533     {
534         $this->_lvd->seed = new stdClass;
535         $this->_lvd->seed->module_dir = 'foobarfoobar';
536
537         $GLOBALS['current_user']->setPreference('mailmerge_on','on');
538
539         $settings_cache = sugar_cache_retrieve('admin_settings_cache');
540         if ( empty($settings_cache) ) {
541             $settings_cache = array();
542         }
543         $settings_cache['system_mailmerge_on'] = true;
544         sugar_cache_put('admin_settings_cache',$settings_cache);
545
546         $output = $this->_lvd->buildMergeLink(array('foobarfoobar' => 'foobarfoobar'));
547         $this->assertContains("index.php?action=index&module=MailMerge&entire=true",$output);
548
549         sugar_cache_clear('admin_settings_cache');
550     }
551
552     public function testBuildTargetLink()
553     {
554         $_POST['module'] = 'foobar';
555         $this->_lvd->seed = new stdClass;
556         $this->_lvd->seed->module_dir = 'foobarfoobar';
557
558         $output = $this->_lvd->buildTargetList();
559
560         $this->assertContains("input.setAttribute ( 'name' , 'module' );                            input.setAttribute ( 'value' , 'foobarfoobar' );",$output);
561         $this->assertContains("input.setAttribute ( 'name' , 'current_query_by_page' );                     input.setAttribute ( 'value', '".base64_encode(serialize($_REQUEST))."' );",$output);
562     }
563
564     public function testDisplayEndWhenNotShowingMassUpdateForm()
565     {
566         $this->_lvd->show_mass_update_form = false;
567
568         $this->assertEmpty($this->_lvd->displayEnd());
569     }
570
571     public function testDisplayEndWhenShowingMassUpdateForm()
572     {
573         $this->_lvd->show_mass_update_form = true;
574         $this->_lvd->mass = $this->getMock('MassUpdate');
575         $this->_lvd->mass->expects($this->any())
576                          ->method('getMassUpdateForm')
577                          ->will($this->returnValue('foo'));
578         $this->_lvd->mass->expects($this->any())
579                          ->method('endMassUpdateForm')
580                          ->will($this->returnValue('bar'));
581
582         $this->assertEquals('foobar',$this->_lvd->displayEnd());
583     }
584
585     public function testGetMultiSelectData()
586     {
587         $this->_lvd->moduleString = 'foobar';
588
589         $output = $this->_lvd->getMultiSelectData();
590
591         $this->assertEquals($output, "<script>YAHOO.util.Event.addListener(window, \"load\", sListView.check_boxes);</script>\n".
592                                 "<textarea style='display: none' name='uid'></textarea>\n" .
593                                 "<input type='hidden' name='select_entire_list' value='0'>\n".
594                                 "<input type='hidden' name='foobar' value='0'>\n".
595                 "<input type='hidden' name='show_plus' value=''>\n",$output);
596     }
597
598     public function testGetMultiSelectDataWithRequestParameterUidSet()
599     {
600         $this->_lvd->moduleString = 'foobar';
601         $_REQUEST['uid'] = '1234';
602
603         $output = $this->_lvd->getMultiSelectData();
604
605         $this->assertEquals("<script>YAHOO.util.Event.addListener(window, \"load\", sListView.check_boxes);</script>\n".
606                                 "<textarea style='display: none' name='uid'>1234</textarea>\n" .
607                                 "<input type='hidden' name='select_entire_list' value='0'>\n".
608                                 "<input type='hidden' name='foobar' value='0'>\n" .
609                 "<input type='hidden' name='show_plus' value=''>\n",$output);        
610     }
611
612     public function testGetMultiSelectDataWithRequestParameterSelectEntireListSet()
613     {
614         $this->_lvd->moduleString = 'foobar';
615         $_REQUEST['select_entire_list'] = '1234';
616
617         $output = $this->_lvd->getMultiSelectData();
618
619         $this->assertEquals("<script>YAHOO.util.Event.addListener(window, \"load\", sListView.check_boxes);</script>\n".
620                                 "<textarea style='display: none' name='uid'></textarea>\n" .
621                                 "<input type='hidden' name='select_entire_list' value='1234'>\n".
622                                 "<input type='hidden' name='foobar' value='0'>\n" .
623                 "<input type='hidden' name='show_plus' value=''>\n",$output);        
624     }
625
626     public function testGetMultiSelectDataWithRequestParameterMassupdateSet()
627     {
628         $this->_lvd->moduleString = 'foobar';
629         $_REQUEST['uid'] = '1234';
630         $_REQUEST['select_entire_list'] = '5678';
631         $_REQUEST['massupdate'] = 'true';
632
633         $output = $this->_lvd->getMultiSelectData();
634
635         $this->assertEquals("<script>YAHOO.util.Event.addListener(window, \"load\", sListView.check_boxes);</script>\n".
636                                 "<textarea style='display: none' name='uid'></textarea>\n" .
637                                 "<input type='hidden' name='select_entire_list' value='0'>\n".
638                                 "<input type='hidden' name='foobar' value='0'>\n".
639                 "<input type='hidden' name='show_plus' value=''>\n",$output);        
640     }
641 }
642
643 class ListViewDisplayMock extends ListViewDisplay
644 {
645     public function buildExportLink()
646     {
647         return parent::buildExportLink();
648     }
649
650     public function buildMassUpdateLink()
651     {
652         return parent::buildMassUpdateLink();
653     }
654
655     public function buildComposeEmailLink($totalCount)
656     {
657         return parent::buildComposeEmailLink($totalCount);
658     }
659
660     public function buildDeleteLink()
661     {
662         return parent::buildDeleteLink();
663     }
664
665     public function buildMergeDuplicatesLink()
666     {
667         return parent::buildMergeDuplicatesLink();
668     }
669
670     public function buildMergeLink(array $modules_array = null)
671     {
672         return parent::buildMergeLink($modules_array);
673     }
674
675     public function buildTargetList()
676     {
677         return parent::buildTargetList();
678     }
679 }