2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 require_once('service/v3/SugarWebServiceUtilv3.php');
39 require_once('tests/service/APIv3Helper.php');
42 class RESTAPI3Test extends Sugar_PHPUnit_Framework_TestCase
46 protected $_lastRawResponse;
48 private static $helperObject;
50 public function setUp()
52 //Reload langauge strings
53 $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
54 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
55 $GLOBALS['mod_strings'] = return_module_language($GLOBALS['current_language'], 'Accounts');
56 //Create an anonymous user for login purposes/
57 $this->_user = SugarTestUserUtilities::createAnonymousUser();
58 $this->_user->status = 'Active';
59 $this->_user->is_admin = 1;
61 $GLOBALS['current_user'] = $this->_user;
63 self::$helperObject = new APIv3Helper();
66 public function tearDown()
68 if(isset($GLOBALS['listViewDefs'])) unset($GLOBALS['listViewDefs']);
69 if(isset($GLOBALS['viewdefs'])) unset($GLOBALS['viewdefs']);
70 unset($GLOBALS['app_list_strings']);
71 unset($GLOBALS['app_strings']);
72 unset($GLOBALS['mod_strings']);
75 protected function _makeRESTCall($method,$parameters)
77 // specify the REST web service to interact with
78 $url = $GLOBALS['sugar_config']['site_url'].'/service/v3/rest.php';
79 // Open a curl session for making the call
80 $curl = curl_init($url);
81 // set URL and other appropriate options
82 curl_setopt($curl, CURLOPT_URL, $url);
83 curl_setopt($curl, CURLOPT_POST, 1);
84 curl_setopt($curl, CURLOPT_HEADER, 0);
85 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
86 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
87 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
88 curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
89 // build the request URL
90 $json = json_encode($parameters);
91 $postArgs = "method=$method&input_type=JSON&response_type=JSON&rest_data=$json";
92 curl_setopt($curl, CURLOPT_POSTFIELDS, $postArgs);
93 // Make the REST call, returning the result
94 $response = curl_exec($curl);
95 // Close the connection
98 $this->_lastRawResponse = $response;
100 // Convert the result from JSON format to a PHP array
101 return json_decode($response,true);
104 protected function _returnLastRawResponse()
106 return "Error in web services call. Response was: {$this->_lastRawResponse}";
109 protected function _login()
111 return $this->_makeRESTCall('login',
115 'user_name' => $this->_user->user_name,
116 'password' => $this->_user->user_hash,
119 'application_name' => 'SugarTestRunner',
120 'name_value_list' => array(),
125 public function testSearchByModule()
127 $result = $this->_login();
128 $session = $result['id'];
130 $seedData = self::$helperObject->populateSeedDataForSearchTest($this->_user->id);
132 $searchModules = array('Accounts','Contacts','Opportunities');
133 $searchString = "UNIT TEST";
137 $results = $this->_makeRESTCall('search_by_module',
139 'session' => $session,
140 'search' => $searchString,
141 'modules' => $searchModules,
143 'max' => $maxResults,
144 'user' => $this->_user->id)
147 $this->assertTrue( self::$helperObject->findBeanIdFromEntryList($results['entry_list'],$seedData[0]['id'],'Accounts') );
148 $this->assertFalse( self::$helperObject->findBeanIdFromEntryList($results['entry_list'],$seedData[1]['id'],'Accounts') );
149 $this->assertTrue( self::$helperObject->findBeanIdFromEntryList($results['entry_list'],$seedData[2]['id'],'Contacts') );
150 $this->assertTrue( self::$helperObject->findBeanIdFromEntryList($results['entry_list'],$seedData[3]['id'],'Opportunities') );
151 $this->assertFalse( self::$helperObject->findBeanIdFromEntryList($results['entry_list'],$seedData[4]['id'],'Opportunities') );
152 $GLOBALS['db']->query("DELETE FROM accounts WHERE name like 'UNIT TEST%' ");
153 $GLOBALS['db']->query("DELETE FROM opportunities WHERE name like 'UNIT TEST%' ");
154 $GLOBALS['db']->query("DELETE FROM contacts WHERE first_name like 'UNIT TEST%' ");
157 public function testSearchByModuleWithReturnFields()
159 $result = $this->_login();
160 $session = $result['id'];
162 $seedData = self::$helperObject->populateSeedDataForSearchTest($this->_user->id);
164 $returnFields = array('name','id','deleted');
165 $searchModules = array('Accounts','Contacts','Opportunities');
166 $searchString = "UNIT TEST";
170 $results = $this->_makeRESTCall('search_by_module',
172 'session' => $session,
173 'search' => $searchString,
174 'modules' => $searchModules,
176 'max' => $maxResults,
177 'user' => $this->_user->id,
178 'selectFields' => $returnFields)
182 $this->assertEquals($seedData[0]['fieldValue'], self::$helperObject->findFieldByNameFromEntryList($results['entry_list'],$seedData[0]['id'],'Accounts', $seedData[0]['fieldName']));
183 $this->assertFalse(self::$helperObject->findFieldByNameFromEntryList($results['entry_list'],$seedData[1]['id'],'Accounts', $seedData[1]['fieldName']));
184 $this->assertEquals($seedData[2]['fieldValue'], self::$helperObject->findFieldByNameFromEntryList($results['entry_list'],$seedData[2]['id'],'Contacts', $seedData[2]['fieldName']));
185 $this->assertEquals($seedData[3]['fieldValue'], self::$helperObject->findFieldByNameFromEntryList($results['entry_list'],$seedData[3]['id'],'Opportunities', $seedData[3]['fieldName']));
186 $this->assertFalse(self::$helperObject->findFieldByNameFromEntryList($results['entry_list'],$seedData[4]['id'],'Opportunities', $seedData[4]['fieldName']));
188 $GLOBALS['db']->query("DELETE FROM accounts WHERE name like 'UNIT TEST%' ");
189 $GLOBALS['db']->query("DELETE FROM opportunities WHERE name like 'UNIT TEST%' ");
190 $GLOBALS['db']->query("DELETE FROM contacts WHERE first_name like 'UNIT TEST%' ");
193 public function testGetServerInformation()
195 require('sugar_version.php');
197 $result = $this->_login();
198 $session = $result['id'];
200 $result = $this->_makeRESTCall('get_server_info',array());
202 $this->assertEquals($sugar_version, $result['version'],'Unable to get server information');
203 $this->assertEquals($sugar_flavor, $result['flavor'],'Unable to get server information');
206 public function testGetModuleList()
208 $result = $this->_login();
209 $session = $result['id'];
211 $account = new Account();
212 $account->id = uniqid();
213 $account->new_with_id = TRUE;
214 $account->name = "Test " . $account->id;
217 $whereClause = "accounts.name='{$account->name}'";
218 $module = 'Accounts';
221 $returnFields = array('name');
222 $result = $this->_makeRESTCall('get_entry_list', array($session, $module, $whereClause, $orderBy,$offset, $returnFields));
224 $this->assertEquals($account->id, $result['entry_list'][0]['id'],'Unable to retrieve account list during search.');
226 $GLOBALS['db']->query("DELETE FROM accounts WHERE id = '{$account->id}'");
230 public function testLogin()
232 $result = $this->_login();
233 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
236 public static function _multipleModuleLayoutProvider()
240 'module' => array('Accounts','Contacts'),
241 'type' => array('default'),
242 'view' => array('list'),
243 'expected_file' => array(
244 'Accounts' => array( 'default' => array('list' => 'modules/Accounts/metadata/listviewdefs.php')),
245 'Contacts' => array( 'default' => array('list' => 'modules/Contacts/metadata/listviewdefs.php')))
248 'module' => array('Accounts','Contacts'),
249 'type' => array('default'),
250 'view' => array('list','detail'),
251 'expected_file' => array(
254 'list' => 'modules/Accounts/metadata/listviewdefs.php',
255 'detail' => 'modules/Accounts/metadata/detailviewdefs.php')),
258 'list' => 'modules/Contacts/metadata/listviewdefs.php',
259 'detail' => 'modules/Contacts/metadata/detailviewdefs.php'))
265 * @dataProvider _multipleModuleLayoutProvider
267 public function testGetMultipleModuleLayout($a_module, $a_type, $a_view, $a_expected_file)
269 $result = $this->_login();
270 $session = $result['id'];
272 $results = $this->_makeRESTCall('get_module_layout',
274 'session' => $session,
275 'module' => $a_module,
280 foreach ($results as $module => $moduleResults )
282 foreach ($moduleResults as $type => $viewResults)
284 foreach ($viewResults as $view => $result)
286 $expected_file = $a_expected_file[$module][$type][$view];
287 if ( is_file('custom' . DIRECTORY_SEPARATOR . $expected_file) )
288 require('custom' . DIRECTORY_SEPARATOR . $expected_file);
290 require($expected_file);
293 $expectedResults = $listViewDefs[$module];
295 $expectedResults = $viewdefs[$module][ucfirst($view) .'View' ];
297 $this->assertEquals(md5(serialize($expectedResults)), md5(serialize($result)), "Unable to retrieve module layout: module {$module}, type $type, view $view");
303 public static function _moduleLayoutProvider()
306 array('module' => 'Accounts','type' => 'default', 'view' => 'list','expected_file' => 'modules/Accounts/metadata/listviewdefs.php' ),
307 array('module' => 'Accounts','type' => 'default', 'view' => 'edit','expected_file' => 'modules/Accounts/metadata/editviewdefs.php' ),
308 array('module' => 'Accounts','type' => 'default', 'view' => 'detail','expected_file' => 'modules/Accounts/metadata/detailviewdefs.php' ),
313 * @dataProvider _moduleLayoutProvider
315 public function testGetModuleLayout($module, $type, $view, $expected_file)
317 $result = $this->_login();
318 $session = $result['id'];
320 $result = $this->_makeRESTCall('get_module_layout',
322 'session' => $session,
323 'module' => array($module),
324 'type' => array($type),
325 'view' => array($view))
328 if ( is_file('custom' . DIRECTORY_SEPARATOR . $expected_file) )
329 require('custom' . DIRECTORY_SEPARATOR . $expected_file);
331 require($expected_file);
334 $expectedResults = $listViewDefs[$module];
336 $expectedResults = $viewdefs[$module][ucfirst($view) .'View' ];
338 $a_expectedResults = array();
339 $a_expectedResults[$module][$type][$view] = $expectedResults;
341 $this->assertEquals(md5(serialize($a_expectedResults)), md5(serialize($result)), "Unable to retrieve module layout: module {$module}, type $type, view $view");
345 * @dataProvider _moduleLayoutProvider
347 public function testGetModuleLayoutMD5($module, $type, $view, $expected_file)
349 $result = $this->_login();
350 $session = $result['id'];
352 $fullResult = $this->_makeRESTCall('get_module_layout_md5',
354 'session' => $session,
355 'module' => array($module),
356 'type' => array($type),
357 'view' => array($view) )
359 $result = $fullResult['md5'];
360 if ( is_file('custom' . DIRECTORY_SEPARATOR . $expected_file) )
361 require('custom' . DIRECTORY_SEPARATOR . $expected_file);
363 require($expected_file);
366 $expectedResults = $listViewDefs[$module];
368 $expectedResults = $viewdefs[$module][ucfirst($view) .'View' ];
370 $a_expectedResults = array();
371 $a_expectedResults[$module][$type][$view] = $expectedResults;
373 $this->assertEquals(md5(serialize($expectedResults)), $result[$module][$type][$view], "Unable to retrieve module layout md5: module {$module}, type $type, view $view");
377 public function testGetAvailableModules()
379 $this->markTestSkipped('Will be updated week of June 21, 2010');
381 $result = $this->_login();
382 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
383 $session = $result['id'];
385 $fullResult = $this->_makeRESTCall('get_available_modules', array('session' => $session, 'filter' => 'all' ));
386 $this->assertTrue(in_array('ACLFields', $fullResult['modules']), "Unable to get all available modules");
387 $this->assertTrue(in_array('Schedulers', $fullResult['modules']), "Unable to get all available modules");
388 $this->assertTrue(in_array('Roles', $fullResult['modules']), "Unable to get all available modules");
390 $sh = new SugarWebServiceUtilv3();
392 $mobileResult = $this->_makeRESTCall('get_available_modules', array('session' => $session, 'filter' => 'mobile' ));
393 $mobileResultExpected = $sh->get_visible_mobile_modules($fullResult['modules']);
394 $mobileResultExpected = md5(serialize(array('modules' => $mobileResultExpected)));
395 $mobileResult = md5(serialize($mobileResult));
396 $this->assertEquals($mobileResultExpected, $mobileResult, "Unable to get all visible mobile modules");
398 $defaultResult = $this->_makeRESTCall('get_available_modules', array('session' => $session, 'filter' => 'default' ));
399 $defaultResult = md5(serialize($defaultResult['modules']));
400 $defaultResultExpected = $sh->get_visible_modules($fullResult['modules']);
401 $defaultResultExpected = md5(serialize($defaultResultExpected));
402 $this->assertEquals($defaultResultExpected, $defaultResult, "Unable to get all visible default modules");
406 public function testGetVardefsMD5()
408 $GLOBALS['reload_vardefs'] = TRUE;
409 $result = $this->_login();
410 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
411 $session = $result['id'];
413 //Test a regular module
414 $fullResult = $this->_makeRESTCall('get_module_fields_md5', array('session' => $session, 'module' => 'Accounts' ));
415 $result = $fullResult['Accounts'];
417 $soapHelper = new SugarWebServiceUtilv3();
418 $actualVardef = $soapHelper->get_return_module_fields($a,'Accounts','');
419 $actualMD5 = md5(serialize($actualVardef));
420 $this->assertEquals($actualMD5, $result, "Unable to retrieve vardef md5.");
423 $result = $this->_makeRESTCall('get_module_fields_md5', array('session' => $session, 'module' => 'BadModule' ));
424 $this->assertTrue($result['name'] == 'Module Does Not Exist');
425 unset($GLOBALS['reload_vardefs']);
428 public function testAddNewAccountAndThenDeleteIt()
430 $result = $this->_login();
431 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
432 $session = $result['id'];
434 $result = $this->_makeRESTCall('set_entry',
436 'session' => $session,
437 'module' => 'Accounts',
438 'name_value_list' => array(
439 array('name' => 'name', 'value' => 'New Account'),
440 array('name' => 'description', 'value' => 'This is an account created from a REST web services call'),
445 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
447 $accountId = $result['id'];
449 // verify record was created
450 $result = $this->_makeRESTCall('get_entry',
452 'session' => $session,
453 'module' => 'Accounts',
458 $this->assertEquals($result['entry_list'][0]['id'],$accountId,$this->_returnLastRawResponse());
461 $result = $this->_makeRESTCall('set_entry',
463 'session' => $session,
464 'module' => 'Accounts',
465 'name_value_list' => array(
466 array('name' => 'id', 'value' => $accountId),
467 array('name' => 'deleted', 'value' => '1'),
472 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
474 // try to retrieve again to validate it is deleted
475 $result = $this->_makeRESTCall('get_entry',
477 'session' => $session,
478 'module' => 'Accounts',
483 $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$accountId}'");
485 $this->assertTrue(!empty($result['entry_list'][0]['id']) && $result['entry_list'][0]['id'] != -1,$this->_returnLastRawResponse());
486 $this->assertEquals($result['entry_list'][0]['name_value_list'][0]['name'],'warning',$this->_returnLastRawResponse());
487 $this->assertEquals($result['entry_list'][0]['name_value_list'][0]['value'],"Access to this object is denied since it has been deleted or does not exist",$this->_returnLastRawResponse());
488 $this->assertEquals($result['entry_list'][0]['name_value_list'][1]['name'],'deleted',$this->_returnLastRawResponse());
489 $this->assertEquals($result['entry_list'][0]['name_value_list'][1]['value'],1,$this->_returnLastRawResponse());
492 public function testRelateAccountToTwoContacts()
494 $result = $this->_login();
495 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
496 $session = $result['id'];
498 $result = $this->_makeRESTCall('set_entry',
500 'session' => $session,
501 'module' => 'Accounts',
502 'name_value_list' => array(
503 array('name' => 'name', 'value' => 'New Account'),
504 array('name' => 'description', 'value' => 'This is an account created from a REST web services call'),
509 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
511 $accountId = $result['id'];
513 $result = $this->_makeRESTCall('set_entry',
515 'session' => $session,
516 'module' => 'Contacts',
517 'name_value_list' => array(
518 array('name' => 'last_name', 'value' => 'New Contact 1'),
519 array('name' => 'description', 'value' => 'This is a contact created from a REST web services call'),
524 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
526 $contactId1 = $result['id'];
528 $result = $this->_makeRESTCall('set_entry',
530 'session' => $session,
531 'module' => 'Contacts',
532 'name_value_list' => array(
533 array('name' => 'last_name', 'value' => 'New Contact 2'),
534 array('name' => 'description', 'value' => 'This is a contact created from a REST web services call'),
539 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
541 $contactId2 = $result['id'];
543 // now relate them together
544 $result = $this->_makeRESTCall('set_relationship',
546 'session' => $session,
547 'module' => 'Accounts',
548 'module_id' => $accountId,
549 'link_field_name' => 'contacts',
550 'related_ids' => array($contactId1,$contactId2),
554 $this->assertEquals($result['created'],1,$this->_returnLastRawResponse());
556 // check the relationship
557 $result = $this->_makeRESTCall('get_relationships',
559 'session' => $session,
560 'module' => 'Accounts',
561 'module_id' => $accountId,
562 'link_field_name' => 'contacts',
563 'related_module_query' => '',
564 'related_fields' => array('last_name','description'),
565 'related_module_link_name_to_fields_array' => array(),
570 $returnedValues = array();
571 $returnedValues[] = $result['entry_list'][0]['name_value_list']['last_name']['value'];
572 $returnedValues[] = $result['entry_list'][1]['name_value_list']['last_name']['value'];
574 $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$accountId}'");
575 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$contactId1}'");
576 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$contactId2}'");
577 $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE account_id= '{$accountId}'");
579 $this->assertContains('New Contact 1',$returnedValues,$this->_returnLastRawResponse());
580 $this->assertContains('New Contact 2',$returnedValues,$this->_returnLastRawResponse());
586 public function testOrderByClauseOfGetRelationship()
588 $result = $this->_login();
589 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
590 $session = $result['id'];
592 $result = $this->_makeRESTCall('set_entry',
594 'session' => $session,
595 'module' => 'Accounts',
596 'name_value_list' => array(
597 array('name' => 'name', 'value' => 'New Account'),
598 array('name' => 'description', 'value' => 'This is an account created from a REST web services call'),
603 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
605 $accountId = $result['id'];
607 $result = $this->_makeRESTCall('set_entry',
609 'session' => $session,
610 'module' => 'Contacts',
611 'name_value_list' => array(
612 array('name' => 'last_name', 'value' => 'New Contact 1'),
613 array('name' => 'description', 'value' => 'This is a contact created from a REST web services call'),
618 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
620 $contactId1 = $result['id'];
622 $result = $this->_makeRESTCall('set_entry',
624 'session' => $session,
625 'module' => 'Contacts',
626 'name_value_list' => array(
627 array('name' => 'last_name', 'value' => 'New Contact 2'),
628 array('name' => 'description', 'value' => 'This is a contact created from a REST web services call'),
633 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
635 $contactId2 = $result['id'];
637 // now relate them together
638 $result = $this->_makeRESTCall('set_relationship',
640 'session' => $session,
641 'module' => 'Accounts',
642 'module_id' => $accountId,
643 'link_field_name' => 'contacts',
644 'related_ids' => array($contactId1,$contactId2),
648 $this->assertEquals($result['created'],1,$this->_returnLastRawResponse());
650 // check the relationship
651 $result = $this->_makeRESTCall('get_relationships',
653 'session' => $session,
654 'module' => 'Accounts',
655 'module_id' => $accountId,
656 'link_field_name' => 'contacts',
657 'related_module_query' => '',
658 'related_fields' => array('last_name','description'),
659 'related_module_link_name_to_fields_array' => array(),
661 'order_by' => 'last_name',
665 $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$accountId}'");
666 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$contactId1}'");
667 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$contactId2}'");
668 $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE account_id= '{$accountId}'");
670 $this->assertEquals($result['entry_list'][0]['name_value_list']['last_name']['value'],'New Contact 1',$this->_returnLastRawResponse());
671 $this->assertEquals($result['entry_list'][1]['name_value_list']['last_name']['value'],'New Contact 2',$this->_returnLastRawResponse());
674 public static function _subpanelLayoutProvider()
678 'module' => 'Contacts',
680 'view' => 'subpanel',
684 'type' => 'wireless',
685 'view' => 'subpanel',
691 * @dataProvider _subpanelLayoutProvider
693 public function testGetSubpanelLayout($module, $type, $view)
695 $result = $this->_login();
696 $session = $result['id'];
698 $results = $this->_makeRESTCall('get_module_layout',
700 'session' => $session,
701 'module' => array($module),
702 'type' => array($type),
703 'view' => array($view))
706 $this->assertTrue(isset($results[$module][$type][$view]), "Unable to get subpanel defs");
708 public function testGetUpcomingActivities()
710 $result = $this->_login();
711 $this->assertTrue(!empty($result['id']) && $result['id'] != -1,$this->_returnLastRawResponse());
712 $session = $result['id'];
713 $expected = $this->_createUpcomingActivities(); //Seed the data.
714 $results = $this->_makeRESTCall('get_upcoming_activities',
716 'session' => $session,
720 $this->assertEquals($expected[0] ,$results[0]['id'] , "Unable to get upcoming activities");
721 $this->assertEquals($expected[1] ,$results[1]['id'] , "Unable to get upcoming activities");
723 $this->_removeUpcomingActivities();
726 private function _removeUpcomingActivities()
728 $GLOBALS['db']->query("DELETE FROM calls where name = 'UNIT TEST'");
729 $GLOBALS['db']->query("DELETE FROM tasks where name = 'UNIT TEST'");
732 private function _createUpcomingActivities()
734 $GLOBALS['current_user']->setPreference('datef','Y-m-d') ;
735 $GLOBALS['current_user']->setPreference('timef','H:i') ;
737 $date1 = $GLOBALS['timedate']->to_display_date_time(gmdate("Y-m-d H:i:s", (gmmktime() + (3600 * 24 * 2) ) ),true,true, $GLOBALS['current_user']) ; //Two days from today
738 $date2 = $GLOBALS['timedate']->to_display_date_time(gmdate("Y-m-d H:i:s", (gmmktime() + (3600 * 24 * 4) ) ),true,true, $GLOBALS['current_user']) ; //Two days from today
743 $c->new_with_id = TRUE;
744 $c->status = 'Not Planned';
745 $c->date_start = $date1;
746 $c->name = "UNIT TEST";
747 $c->assigned_user_id = $this->_user->id;
753 $c->new_with_id = TRUE;
754 $c->status = 'Planned';
755 $c->date_start = $date1;
756 $c->name = "UNIT TEST";
757 $c->assigned_user_id = $this->_user->id;
763 $t->new_with_id = TRUE;
764 $t->status = 'Not Started';
765 $t->date_due = $date2;
766 $t->name = "UNIT TEST";
767 $t->assigned_user_id = $this->_user->id;
770 return array($callID, $taskID);