0
0
Fork 0
mirror of https://github.com/salesagility/SuiteCRM.git synced 2025-02-21 20:56:08 +00:00
salesagility_SuiteCRM/tests/unit/phpunit/modules/SavedSearch/SavedSearchTest.php
j.dang b5fb31441f Replace explicit bean instantiations in files 111 - 120
- File: '... /tests/unit/phpunit/modules/MergeRecords/MergeRecordTest.php'

   - Replaced 1 occurrence(s) of 'new User()'

   - Replaced 18 occurrence(s) of 'new MergeRecord()'

- File: '... /tests/unit/phpunit/modules/ProspectLists/ProspectListTest.php'

   - Replaced 17 occurrence(s) of 'new ProspectList()'

   - Replaced 1 occurrence(s) of 'new User()'

- File: '... /tests/unit/phpunit/modules/Notes/NoteTest.php'

   - Replaced 11 occurrence(s) of 'new Note()'

   - Replaced 1 occurrence(s) of 'new User()'

- File: '... /tests/unit/phpunit/modules/FP_events/FP_eventsTest.php'

   - Replaced 2 occurrence(s) of 'new FP_events()'

- File: '... /tests/unit/phpunit/modules/Users/UserTest.php'

   - Replaced 2 occurrence(s) of 'new Contact()'

   - Replaced 2 occurrence(s) of 'new Account()'

   - Replaced 55 occurrence(s) of 'new User()'

- File: '... /tests/unit/phpunit/modules/FP_Event_Locations/FP_Event_LocationsTest.php'

   - Replaced 1 occurrence(s) of 'new FP_Event_Locations()'

- File: '... /tests/unit/phpunit/modules/AM_TaskTemplates/AM_TaskTemplatesTest.php'

   - Replaced 1 occurrence(s) of 'new AM_TaskTemplates()'

- File: '... /tests/unit/phpunit/modules/SavedSearch/SavedSearchTest.php'

   - Replaced 1 occurrence(s) of 'new Lead()'

   - Replaced 1 occurrence(s) of 'new User()'

   - Replaced 9 occurrence(s) of 'new SavedSearch()'

- File: '... /tests/unit/phpunit/modules/Meetings/MeetingTest.php'

   - Replaced 1 occurrence(s) of 'new Lead()'

   - Replaced 1 occurrence(s) of 'new Contact()'

   - Replaced 18 occurrence(s) of 'new Meeting()'

   - Replaced 4 occurrence(s) of 'new User()'

   - Replaced 1 occurrence(s) of 'new Administration()'

- File: '... /tests/unit/phpunit/modules/AOS_PDF_Templates/AOS_PDF_TemplatesTest.php'

   - Replaced 1 occurrence(s) of 'new User()'

   - Replaced 1 occurrence(s) of 'new AOS_PDF_Templates()'
2020-01-22 13:50:58 +00:00

175 lines
6 KiB
PHP

<?php
use SuiteCRM\Test\SuitePHPUnitFrameworkTestCase;
class SavedSearchTest extends SuitePHPUnitFrameworkTestCase
{
public function setUp()
{
parent::setUp();
global $current_user;
get_sugar_config_defaults();
$current_user = BeanFactory::newBean('Users');
}
public function testSavedSearch()
{
// Execute the constructor and check for the Object type and attributes
$savedSearch = BeanFactory::newBean('SavedSearch');
$this->assertInstanceOf('SavedSearch', $savedSearch);
$this->assertInstanceOf('SugarBean', $savedSearch);
$this->assertAttributeEquals('saved_search', 'table_name', $savedSearch);
$this->assertAttributeEquals('SavedSearch', 'module_dir', $savedSearch);
$this->assertAttributeEquals('SavedSearch', 'object_name', $savedSearch);
//test with parameters
$savedSearch = new SavedSearch(array('id', 'name'), 'id', 'ASC');
$this->assertAttributeEquals(array('id', 'name'), 'columns', $savedSearch);
$this->assertAttributeEquals('id', 'orderBy', $savedSearch);
$this->assertAttributeEquals('ASC', 'sortOrder', $savedSearch);
}
public function testgetForm()
{
$savedSearch = new SavedSearch(array('id', 'name'), 'id', 'ASC');
$result = $savedSearch->getForm('Leads');
$this->assertGreaterThan(0, strlen($result));
}
public function testgetSelect()
{
$savedSearch = new SavedSearch(array('id', 'name'), 'id', 'ASC');
$result = $savedSearch->getSelect('Leads');
$this->assertGreaterThan(0, strlen($result));
}
// public function testMain()
// {
// $savedSearch = BeanFactory::newBean('SavedSearch');
//
// $savedSearch->name = 'test';
// $savedSearch->search_module = 'Leads';
// $savedSearch->save();
//
// //test for record ID to verify that record is saved
// $this->assertTrue(isset($savedSearch->id));
// $this->assertEquals(36, strlen($savedSearch->id));
//
//
// // Where is the unit test?
// // Where is the main method?
// // Why is this combined?
// // TODO: TASK: UNDEFINED - build the tests for the following methods.
// $this->markTestIncomplete('');
//// //test handleSave method
//// $this->handleSaveAndRetrieveSavedSearch($savedSearch->id);
////
//// //test returnSavedSearch method
//// $this->returnSavedSearch($savedSearch->id);
////
//// //test returnSavedSearchContents method
//// $this->returnSavedSearchContents($savedSearch->id);
////
//// //test handleDelete method
//// $this->handleDelete($savedSearch->id);
// }
public function handleSaveAndRetrieveSavedSearch($id)
{
$savedSearch = BeanFactory::newBean('SavedSearch');
$searchModuleBean = BeanFactory::newBean('Leads');
$_REQUEST['search_module'] = 'Leads';
$_REQUEST['description'] = 'test description';
$_REQUEST['test_content'] = 'test text';
$expected = array('search_module' => 'Leads', 'description' => 'test description', 'test_content' => 'test text', 'advanced' => true);
//execute the method and then retrieve back to verify contents attribute
$savedSearch->handleSave('', false, false, $id, $searchModuleBean);
$savedSearch->retrieveSavedSearch($id);
$this->assertSame($expected, $savedSearch->contents);
}
public function handleDelete($id)
{
$savedSearch = BeanFactory::newBean('SavedSearch');
$savedSearch->handleDelete($id);
$result = $savedSearch->retrieve($id);
$this->assertEquals(null, $result);
}
public function returnSavedSearch($id)
{
$savedSearch = BeanFactory::newBean('SavedSearch');
// Execute the method and test that it works and doesn't throw an exception.
try {
$savedSearch->returnSavedSearch($id);
$this->assertTrue(true);
} catch (Exception $e) {
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
}
}
public function returnSavedSearchContents($id)
{
$savedSearch = BeanFactory::newBean('SavedSearch');
// Execute the method and test that it works and doesn't throw an exception.
try {
$result = $savedSearch->returnSavedSearchContents($id);
$this->assertTrue(true);
} catch (Exception $e) {
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
}
}
public function testhandleRedirect()
{
$savedSearch = BeanFactory::newBean('SavedSearch');
$search_query = '&orderBy=&sortOrder=&query=&searchFormTab=&showSSDIV=';
//$savedSearch->handleRedirect("Leads", $search_query, 1, 'true');
$this->markTestIncomplete('method uses die');
}
public function testfill_in_additional_list_fields()
{
$savedSearch = BeanFactory::newBean('SavedSearch');
$savedSearch->assigned_user_id = 1;
$savedSearch->contents = array('search_module' => 'Leads');
$savedSearch->fill_in_additional_list_fields();
$this->assertEquals('Leads', $savedSearch->search_module);
$this->assertEquals('Administrator', $savedSearch->assigned_user_name);
}
public function testpopulateRequest()
{
$savedSearch = BeanFactory::newBean('SavedSearch');
$savedSearch->contents = array('search_module' => 'Accounts',
'description' => 'test text',
'test_content' => 'some content',
'advanced' => true, );
$savedSearch->populateRequest();
// verify that Request parameters are set
$this->assertEquals('Accounts', $_REQUEST['search_module']);
$this->assertEquals('test text', $_REQUEST['description']);
$this->assertEquals('some content', $_REQUEST['test_content']);
}
}