0
0
Fork 0
mirror of https://github.com/salesagility/SuiteCRM.git synced 2025-03-17 14:52:43 +00:00

Add a batch of tests.

This commit is contained in:
Haris Raheem 2016-02-22 10:29:34 +00:00 committed by Jim Mackin
parent f297b1ddd2
commit c1e1137212
20 changed files with 1584 additions and 0 deletions

View file

@ -0,0 +1,21 @@
<?php
class ControllerFactoryTest extends PHPUnit_Framework_TestCase
{
public function testgetController(){
//execute the method with invalid input
$controller = ControllerFactory::getController('');
$this->assertInstanceOf('SugarController',$controller);
//execute the method with valid input and check if it returns correct instance
$controller = ControllerFactory::getController('Users');
$this->assertInstanceOf('UsersController',$controller);
$this->assertInstanceOf('SugarController',$controller);
}
}
?>

View file

@ -0,0 +1,172 @@
<?php
class SugarControllerTest extends PHPUnit_Framework_TestCase
{
public function testsetup(){
$SugarController = new SugarController();
$default_module = $SugarController->module;
//first test with empty parameter and check for default values being used
$SugarController->setup('');
$this->assertAttributeEquals($default_module,'module', $SugarController);
$this->assertAttributeEquals(null,'target_module', $SugarController);
//secondly test with module name and check for correct assignment.
$SugarController->setup('Users');
$this->assertAttributeEquals('Users','module', $SugarController);
$this->assertAttributeEquals(null,'target_module', $SugarController);
}
public function testsetModule(){
$SugarController = new SugarController();
//first test with empty parameter
$SugarController->setModule('');
$this->assertAttributeEquals('','module', $SugarController);
//secondly test with module name and check for correct assignment.
$SugarController->setModule('Users');
$this->assertAttributeEquals('Users','module', $SugarController);
}
public function testloadBean()
{
$SugarController = new SugarController();
//first test with empty parameter and check for null. Default is Home but Home has no bean
$SugarController->setModule('');
$SugarController->loadBean();
$this->assertEquals(null,$SugarController->bean );
//secondly test with module name and check for correct bean class loaded.
$SugarController->setModule('Users');
$SugarController->loadBean();
$this->assertInstanceOf('User',$SugarController->bean);
}
public function testexecute()
{
$SugarController = new SugarController();
//execute the method and check if it works and doesn't throws an exception
try {
$SugarController->execute();
} catch (Exception $e) {
$this->fail();
}
$this->assertTrue(TRUE);
}
public function testprocess(){
$SugarController = new SugarController();
//execute the method and check if it works and doesn't throws an exception
try {
$SugarController->process();
} catch (Exception $e) {
$this->fail();
}
$this->assertTrue(TRUE);
}
public function testpre_save(){
$SugarController = new SugarController();
$SugarController->setModule('Users');
$SugarController->loadBean();
//execute the method and check if it either works or throws an mysql exception.
//Fail if it throws any other exception.
try {
$SugarController->pre_save();
} catch (Exception $e) {
$this->assertStringStartsWith('mysqli_query()', $e->getMessage());
}
$this->assertTrue(TRUE);
}
public function testaction_save(){
$SugarController = new SugarController();
$SugarController->setModule('Users');
$SugarController->loadBean();
//execute the method and check if it either works or throws an mysql exception.
//Fail if it throws any other exception.
try {
$SugarController->action_save();
} catch (Exception $e) {
$this->assertStringStartsWith('mysqli_query()', $e->getMessage());
}
$this->assertTrue(TRUE);
}
public function testaction_spot()
{
$SugarController = new SugarController();
//first check with default value of attribute
$this->assertAttributeEquals('classic','view', $SugarController);
//secondly check for attribute value change on method execution.
$SugarController->action_spot();
$this->assertAttributeEquals('spot','view', $SugarController);
}
public function testgetActionFilename() {
//first check with a invalid value
$action = SugarController::getActionFilename('');
$this->assertEquals('',$action );
//secondly check with a valid value
$action = SugarController::getActionFilename('editview');
$this->assertEquals('EditView',$action );
}
public function testcheckEntryPointRequiresAuth()
{
$SugarController = new SugarController();
//check with a invalid value
$result = $SugarController->checkEntryPointRequiresAuth('');
$this->assertTrue($result);
//cehck with a valid True value
$result = $SugarController->checkEntryPointRequiresAuth('download');
$this->assertTrue($result);
//cehck with a valid False value
$result = $SugarController->checkEntryPointRequiresAuth('GeneratePassword');
$this->assertFalse($result);
}
}
?>

View file

@ -0,0 +1,329 @@
<?php
class SugarViewTest extends PHPUnit_Framework_TestCase
{
public function testinit()
{
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$SugarView = new SugarView();
//execute the method and check if it works and doesn't throws an exception
try {
$SugarView->init();
} catch (Exception $e) {
$this->fail();
}
$this->assertTrue(TRUE);
}
public function testprocess()
{
$SugarView = new SugarView();
$SugarView->module = "Users";
$GLOBALS['app'] = new SugarApplication();
//execute the method and check if it works and doesn't throws an exception
//secondly check if it outputs any content to browser
try {
ob_start();
$SugarView->process();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
} catch (Exception $e) {
$this->fail();
}
}
public function testdisplayErrors()
{
$SugarView = new SugarView();
//execute the method and check if it works and doesn't throws an exception
try {
$errors = $SugarView->displayErrors();
$this->assertSame(NULL,$errors);
} catch (Exception $e) {
$this->fail();
}
$this->assertTrue(TRUE);
}
public function testpreDisplay()
{
$SugarView = new SugarView();
//execute the method and check if it works and doesn't throws an exception
try {
$SugarView->preDisplay();
} catch (Exception $e) {
$this->fail();
}
$this->assertTrue(TRUE);
}
public function testdisplay()
{
$SugarView = new SugarView();
//execute the method and check if it works and doesn't throws an exception
try {
$SugarView->display();
} catch (Exception $e) {
$this->fail();
}
$this->assertTrue(TRUE);
}
public function testdisplayHeader()
{
$SugarView = new SugarView();
$SugarView->module = "Users";
$GLOBALS['app'] = new SugarApplication();
//execute the method and check if it works and doesn't throws an exception
//secondly check if it outputs any content to browser
try {
ob_start();
$SugarView->displayHeader();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
} catch (Exception $e) {
$this->fail();
}
}
function testgetModuleMenuHTML()
{
$SugarView = new SugarView();
//execute the method and check if it works and doesn't throws an exception
try {
$SugarView->getModuleMenuHTML();
} catch (Exception $e) {
$this->fail();
}
$this->assertTrue(TRUE);
}
public function testincludeClassicFile()
{
$SugarView = new SugarView();
//execute the method and check if it works and doesn't throws an exception
//use any valid file path, we just need to avoid failing require_once
try {
$SugarView->includeClassicFile('config.php');
} catch (Exception $e) {
$this->fail();
}
$this->assertTrue(TRUE);
}
public function testgetJavascriptValidation()
{
//check if it returns any text i-e JS code
$js = SugarView::getJavascriptValidation();
$this->assertGreaterThan(0,strlen($js));
}
public function testdisplayFooter()
{
$SugarView = new SugarView();
//execute the method and check if it works and doesn't throws an exception
//secondly check if it outputs any content to browser
try {
ob_start();
$SugarView->displayFooter();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
} catch (Exception $e) {
$this->fail();
}
}
public function testrenderJavascript()
{
$SugarView = new SugarView();
//execute the method and check if it works and doesn't throws an exception
//secondly check if it outputs any content to browser
try {
ob_start();
$SugarView->renderJavascript();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
} catch (Exception $e) {
$this->fail();
}
}
public function testgetMenu()
{
//error_reporting(E_ALL);
$SugarView = new SugarView();
//execute the method and check if it works and throws an exception if no module is provided
//it creates memory Fatal errors which causes PHPunit to crash so we will skip this scenario
/*
try {
//check first with invalid value and test if it throws an exception
$menu = $SugarView->getMenu();
//$this->assertTrue(is_array($menu));
} catch (Exception $e) {
$this->assertTrue(TRUE);
//$this->fail();
} */
//check with valid value and check if it returns an array.
$menu = $SugarView->getMenu('Users');
$this->assertTrue(is_array($menu));
}
public function testgetModuleTitle()
{
$SugarView = new SugarView();
//first execute the method with default value
$moduleTitle = $SugarView->getModuleTitle();
$this->assertGreaterThan(0,strlen($moduleTitle));
//second execute the method with true value
$moduleTitle = $SugarView->getModuleTitle(true);
$this->assertGreaterThan(0,strlen($moduleTitle));
//third execute the method with false value
$moduleTitle = $SugarView->getModuleTitle(false);
$this->assertGreaterThan(0,strlen($moduleTitle));
}
public function testgetMetaDataFile()
{
$SugarView = new SugarView();
//first execute the method with missing attributes. it should return Null.
$metaDataFile = $SugarView->getMetaDataFile();
$this->assertEquals(NULL,$metaDataFile);
//second execute the method with valid attributes set. it should return a file path string.
$SugarView->type ='detail' ;
$SugarView->module = 'Users';
$metaDataFile = $SugarView->getMetaDataFile();
$this->assertGreaterThan(0,strlen($metaDataFile));
}
public function testgetBrowserTitle()
{
$SugarView = new SugarView();
//execute the method. it should return a title string.
$browserTitle = $SugarView->getBrowserTitle();
$this->assertGreaterThan(0,strlen($browserTitle));
}
public function testgetBreadCrumbSymbol()
{
$SugarView = new SugarView();
//execute the method. it should return a string.
$breadCrumbSymbol = $SugarView->getBreadCrumbSymbol();
$this->assertGreaterThan(0,strlen($breadCrumbSymbol));
}
public function testcheckPostMaxSizeError(){
$SugarView = new SugarView();
//execute the method. it should return False because Request parameters are not available.
$postMaxSizeError = $SugarView->checkPostMaxSizeError();
$this->assertFalse($postMaxSizeError);
}
}

View file

@ -0,0 +1,79 @@
<?php
class ViewFactoryTest extends PHPUnit_Framework_TestCase{
public function testloadView(){
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//check with invalid input. must return sugaview instance
$view = ViewFactory::loadView('default','');
$this->assertInstanceOf('SugarView',$view);
//check with a valid module without a specific view, must return sugarview instance
$view = ViewFactory::loadView('default','Users');
$this->assertInstanceOf('SugarView',$view);
//check with a valid module and specific view, must reutern speciifc view instance
$view = ViewFactory::loadView('list','Users');
$this->assertInstanceOf('UsersViewList',$view);
}
public function test_loadConfig(){
//check with a invalid module, method must not change the view options.
$view = ViewFactory::loadView('default','');
$options = $view->options;
ViewFactory::_loadConfig($view, 'default');
$this->assertSame($options,$view->options);
//check with a valid module which does not implement it's own view config. method must not change the view options.
$view = ViewFactory::loadView('detail','Users');
$options = $view->options;
ViewFactory::_loadConfig($view, 'detail');
$this->assertSame($options,$view->options);
//check with a valid module which implement it's own view config. method still must not change the view options because it needs.
$view = ViewFactory::loadView('area_detail_map','jjwg_Areas');
$view->module = 'jjwg_Areas';
$options = $view->options;
ViewFactory::_loadConfig($view, 'area_detail_map');
$this->assertSame($options,$view->options);
}
public function test_buildFromFile(){
//checck with valid values and test if it returns correct view instance
$type = 'list';
$target_module = 'Users';
$bean = Null;
$view = ViewFactory::_buildFromFile('modules/' . $target_module . '/views/view.'.$type.'.php', $bean, array(), $type, $target_module);
$this->assertInstanceOf('UsersViewList',$view);
//checck with valid values and test if it returns correct view instance
$type = 'detail';
$target_module = 'Users';
$bean = Null;
$view = ViewFactory::_buildFromFile('modules/' . $target_module . '/views/view.'.$type.'.php', $bean, array(), $type, $target_module);
$this->assertInstanceOf('UsersViewDetail',$view);
}
public function test_buildClass(){
//checck with valid values and test if it returns correct view instance
$view = ViewFactory::_buildClass('UsersViewList', Null, array());
$this->assertInstanceOf('UsersViewList',$view);
//checck with valid values and test if it returns correct view instance
$view = ViewFactory::_buildClass('UsersViewDetail', Null, array());
$this->assertInstanceOf('UsersViewDetail',$view);
}
}
?>

View file

@ -0,0 +1,15 @@
<?php
class ViewAjaxTest extends PHPUnit_Framework_TestCase
{
public function testViewAjax()
{
//execute the contructor and check for the Object type and attributes
$view = new ViewAjax();
$this->assertInstanceOf('ViewAjax',$view);
$this->assertInstanceOf('SugarView',$view);
$this->assertTrue( is_array($view->options));
}
}

View file

@ -0,0 +1,30 @@
<?php
class ViewAjaxUITest extends PHPUnit_Framework_TestCase
{
public function test__construct()
{
//execute the contructor and check for the Object type and type attribute
$view = new ViewAjaxUI();
$this->assertInstanceOf('ViewAjaxUI',$view);
$this->assertInstanceOf('SugarView',$view);
$this->assertTrue( is_array($view->options));
}
public function testdisplay()
{
$view = new ViewAjaxUI();
//execute the method and test if it works and does not throws an exception other than headers output exception.
try {
$view->display();
} catch (Exception $e) {
$this->assertStringStartsWith('Cannot modify header information',$e->getMessage());
}
}
}

View file

@ -0,0 +1,69 @@
<?php
class ViewClassicTest extends PHPUnit_Framework_TestCase
{
public function test__construct( )
{
//execute the contructor and check for the Object type and type attribute
//test with no paramerters
$view = new ViewClassic();
$this->assertInstanceOf('ViewClassic',$view);
$this->assertInstanceOf('SugarView',$view);
$this->assertAttributeEquals('','type', $view);
//test with bean parameter;
$bean = new User();
$view = new ViewClassic($bean);
$this->assertInstanceOf('ViewClassic',$view);
$this->assertInstanceOf('SugarView',$view);
$this->assertAttributeEquals('','type', $view);
}
public function testdisplay()
{
error_reporting(E_ERROR | E_PARSE);
//test with a valid module but invalid action. it should return false.
$view = new ViewClassic();
$view->module = "Home";
$view->action = "";
$ret = $view->display();
$this->assertFalse($ret);
//test with a valid module and uncustomized action. it should return true
$view = new ViewClassic();
$view->module = "Home";
$view->action = "About";
ob_start();
$ret = $view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
$this->assertTrue($ret);
//test with a valid module and customized action. it should return true
$view = new ViewClassic();
$view->module = "Home";
$view->action = "index";
ob_start();
$ret = $view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
$this->assertTrue($ret);
}
}

View file

@ -0,0 +1,60 @@
<?php
class ViewDetailTest extends PHPUnit_Framework_TestCase
{
public function testViewDetail()
{
//execute the contructor and check for the Object type and type attribute
$view = new ViewDetail();
$this->assertInstanceOf('ViewDetail',$view);
$this->assertInstanceOf('SugarView',$view);
$this->assertAttributeEquals('detail','type', $view);
}
public function testpreDisplay()
{
//execute the method with required attributes preset, it will initialize the dv(detail view) attribute.
$view = new ViewDetail();
$view->module = "Users";
$view->bean = new User();
$view->ss = new Sugar_Smarty();
$view->preDisplay();
$this->assertInstanceOf('DetailView2',$view->dv);
$this->asserttrue(is_array($view->dv->defs));
//execute the method again for a different module with required attributes preset, it will initialize the dv(detail view) attribute.
$view = new ViewDetail();
$view->module = "Meetings";
$view->bean = new Meeting();
$view->ss = new Sugar_Smarty();
$view->preDisplay();
$this->assertInstanceOf('DetailView2',$view->dv);
$this->asserttrue(is_array($view->dv->defs));
}
public function testdisplay()
{
error_reporting(E_ERROR | E_PARSE);
//execute the method with essential parameters set. it should return some html.
$view = new ViewDetail();
$view->module = "Users";
$view->bean = new User();
$view->bean->id = 1;
$view->ss = new Sugar_Smarty();
$view->preDisplay();
ob_start();
$view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
}
}

View file

@ -0,0 +1,61 @@
<?php
class ViewEditTest extends PHPUnit_Framework_TestCase
{
public function testViewEdit(){
//execute the contructor and check for the Object type and attributes
$view = new ViewEdit();
$this->assertInstanceOf('ViewEdit',$view);
$this->assertInstanceOf('SugarView',$view);
$this->assertAttributeEquals('edit','type', $view);
$this->assertAttributeEquals(false,'useForSubpanel', $view);
$this->assertAttributeEquals(false,'useModuleQuickCreateTemplate', $view);
$this->assertAttributeEquals(true,'showTitle', $view);
}
public function testpreDisplay()
{
error_reporting(E_ERROR | E_PARSE);
//execute the method with required attributes preset, it will initialize the ev(edit view) attribute.
$view = new ViewEdit();
$view->module = "Users";
$view->bean = new User();
$view->preDisplay();
$this->assertInstanceOf('EditView',$view->ev);
//execute the method again for a different module with required attributes preset, it will initialize the ev(edit view) attribute.
$view = new ViewEdit();
$view->module = "Meetings";
$view->bean = new Meeting();
$view->preDisplay();
$this->assertInstanceOf('EditView',$view->ev);
}
public function testdisplay(){
//execute the method with essential parameters set. it should return some html.
$view = new ViewEdit();
$view->module = "Users";
$view->bean = new User();
$view->preDisplay();
$view->ev->ss = new Sugar_Smarty();
ob_start();
$view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
}
}

View file

@ -0,0 +1,30 @@
<?php
class ViewHtmlTest extends PHPUnit_Framework_TestCase
{
public function testViewHtml(){
//execute the contructor and check for the Object type
$view = new ViewHtml();
$this->assertInstanceOf('ViewHtml',$view);
$this->assertInstanceOf('SugarView',$view);
}
public function testdisplay(){
$view = new ViewHtml();
//execute the method and test if it works and does not throws an exception.
try {
$view->display();
} catch (Exception $e) {
$this->fail();
}
}
}
?>

View file

@ -0,0 +1,180 @@
<?php
class ViewListTest extends PHPUnit_Framework_TestCase
{
public function testViewList()
{
//execute the contructor and check for the Object type and type attribute
$view = new ViewList();
$this->assertInstanceOf('ViewList',$view);
$this->assertInstanceOf('SugarView',$view);
$this->assertAttributeEquals('list','type', $view);
}
public function testoldSearch()
{
$view = new ViewList();
//execute the method and test if it works and does not throws an exception.
try {
$view->oldSearch();
} catch (Exception $e) {
$this->fail();
}
}
public function testnewSearch()
{
$view = new ViewList();
//execute the method and test if it works and does not throws an exception.
try {
$view->newSearch();
} catch (Exception $e) {
$this->fail();
}
}
public function testlistViewPrepare()
{
error_reporting(E_ERROR | E_PARSE);
//test without setting parameters. it should return some html
$view = new ViewList();
$view->module = "Users";
ob_start();
$view->listViewPrepare();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
//test with some REQUEST parameters preset. it should return some html and set the REQUEST key we provided in current_query_by_page REQUEST Param.
$view = new ViewList();
$view->module = "Users";
$GLOBALS['module']= "Users";
$_REQUEST["Users2_USER_offset"]= 1;
$_REQUEST['current_query_by_page'] = base64_encode(serialize(Array("key"=>"value")));
$view->bean = New User();
ob_start();
$view->listViewPrepare();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
$this->assertEquals('value',$_REQUEST['key']);
}
public function testlistViewProcess()
{
//execute the method and call methods to get the required child objects set. it should return some html.
$view = new ViewList();
$view->seed = new User();
$view->prepareSearchForm();
$view->preDisplay();
ob_start();
$view->listViewProcess();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
}
public function testprepareSearchForm()
{
//test without any REQUEST parameters set. it will set searchform attribute to a searchform object.
$view1 = new ViewList();
$view1->module = "Users";
$view1->prepareSearchForm();
$this->assertInstanceOf('SearchForm',$view1->searchForm);
//test with REQUEST parameters set. it will set searchform attribute to a searchform object.
$view2 = new ViewList();
$view2->module = "Users";
$_REQUEST['search_form'] = true;
$_REQUEST['searchFormTab'] = 'advanced_search';
$view2->prepareSearchForm();
$this->assertInstanceOf('SearchForm',$view2->searchForm);
}
public function testprocessSearchForm()
{
//test without use_old_search. it should return html.
$view = new ViewList();
$view->prepareSearchForm();
ob_start();
$view->processSearchForm();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
//test with use_old_search = true. there is a $view variable which is never set so it doesn't returns anything.
$view = new ViewList();
$view->prepareSearchForm();
$view->use_old_search = true;
ob_start();
$view->processSearchForm();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertEquals(0,strlen($renderedContent));
}
public function testpreDisplay()
{
//execute the method and test if it sets the lv attribute to ListViewSmarty object.
$view = new ViewList();
$view->preDisplay();
$this->assertInstanceOf('ListViewSmarty',$view->lv);
}
public function testdisplay()
{
$view = new ViewList();
//test without setting bean attibute. it shuold return no access html.
ob_start();
$view->display();
$renderedContent1 = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent1));
//test with bean, seed and other arrtibutes set. it shuold return html.
$view->bean = new User();
$view->seed = new User();
$view->module = "Users";
$view->prepareSearchForm();
$view->preDisplay();
ob_start();
$view->display();
$renderedContent2 = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent2));
}
}
?>

View file

@ -0,0 +1,196 @@
<?php
class ViewMetadataTest extends PHPUnit_Framework_TestCase
{
public function testdisplayCheckBoxes(){
$view = new ViewMetadata();
//check with empty values array. it should return html sting
ob_start();
$values = Array();
$view->displayCheckBoxes('test',$values);
$renderedContent1 = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent1));
//check with prefilled values array. it should return html sting longer than earlier
ob_start();
$values = Array('option1','option2');
$view->displayCheckBoxes('test',$values);
$renderedContent2 = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(strlen($renderedContent1),strlen($renderedContent2));
}
public function testdisplaySelect(){
$view = new ViewMetadata();
//check with empty values array. it should return html sting
ob_start();
$values = Array();
$view->displaySelect('test',$values);
$renderedContent1 = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent1));
//check with prefilled values array. it should return html sting longer than earlier
ob_start();
$values = Array('option1','option2');
$view->displaySelect('test',$values);
$renderedContent2 = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(strlen($renderedContent1),strlen($renderedContent2));
}
public function testdisplayTextBoxes(){
$view = new ViewMetadata();
//check with empty values array. it should return html sting
ob_start();
$values = Array();
$view->displayTextBoxes($values);
$renderedContent1 = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent1));
//check with prefilled values array. it should return html sting longer than earlier
ob_start();
$values = Array('option1','option2');
$view->displayTextBoxes($values);
$renderedContent2 = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(strlen($renderedContent1),strlen($renderedContent2));
}
public function testprintValue(){
$view = new ViewMetadata();
ob_start();
$values = Array('option1','option2');
$view->printValue($values);
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
}
public function testdisplay(){
error_reporting(E_ERROR | E_PARSE);
$view = new ViewMetadata();
//test without setting REQUEST parameters
ob_start();
$view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
//test with REQUEST parameters set
$_REQUEST['modules'] = Array('Calls','Meetings');
ob_start();
$view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
}
public function testgetModules(){
//execute the method and test if it returns a array.
$modules = VardefBrowser::getModules();
$this->assertTrue(is_array($modules));
}
public function testfindFieldsWithAttributes(){
//check with emptty attributes array
$attributes = Array();
$fields1 = VardefBrowser::findFieldsWithAttributes($attributes);
$this->assertTrue(is_array($fields1));
//check with a very common attribute
$attributes = Array('id');
$fields2 = VardefBrowser::findFieldsWithAttributes($attributes);
$this->assertTrue(is_array($fields2));
//check with a very specific attribute
$attributes = Array('category');
$fields3 = VardefBrowser::findFieldsWithAttributes($attributes);
$this->assertTrue(is_array($fields3));
//check that all three arrays returned, are not same.
$this->assertNotSame($fields1,$fields2);
$this->assertNotSame($fields1,$fields3);
$this->assertNotSame($fields2,$fields3);
}
public function testfindVardefs(){
//check with empty modules array
$modules = Array();
$defs1 = VardefBrowser::findVardefs($modules);
$this->assertTrue(is_array($defs1));
//check with modules array set.
$modules = Array('Calls');
$defs2 = VardefBrowser::findVardefs($modules);
$this->assertTrue(is_array($defs2));
//check that two arrays returned, are not same.
$this->assertNotSame($defs1,$defs2);
}
public function testfindFieldAttributes(){
//check with emptty attributes array
$attributes = Array();
$fields1 = VardefBrowser::findFieldAttributes();
$this->assertTrue(is_array($fields1));
//check with emptty attributes array and prefilled modules array.
$attributes = Array();
$modules = Array('Users');
$fields2 = VardefBrowser::findFieldAttributes($attributes,$modules,true,true);
$this->assertTrue(is_array($fields2));
//check with a very specific attribute and empty modules array.
$attributes = Array('category');
$fields3 = VardefBrowser::findFieldAttributes($attributes);
$this->assertTrue(is_array($fields3));
//check that all three arrays returned, are not same.
$this->assertNotSame($fields1,$fields2);
$this->assertNotSame($fields1,$fields3);
$this->assertNotSame($fields2,$fields3);
}
}

View file

@ -0,0 +1,32 @@
<?php
class ViewModulelistmenuTest extends PHPUnit_Framework_TestCase
{
public function test__construct()
{
//execute the contructor and check for the Object type and options attribute
$view = new ViewModulelistmenu();
$this->assertInstanceOf('ViewModulelistmenu',$view);
$this->assertInstanceOf('SugarView',$view);
$this->assertTrue(is_array($view->options));
}
public function testdisplay()
{
//execute the method with required child objects preset. it should return some html.
$view = new ViewModulelistmenu();
$view->ss = new Sugar_Smarty();
ob_start();
$view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
$this->assertEquals(false,is_array($renderedContent));
}
}
?>

View file

@ -0,0 +1,56 @@
<?php
class ViewMultieditTest extends PHPUnit_Framework_TestCase{
function testViewMultiedit(){
//execute the contructor and check for the Object type and type attribute
$view = new ViewMultiedit();
$this->assertInstanceOf('ViewMultiedit',$view);
$this->assertInstanceOf('SugarView',$view);
$this->assertAttributeEquals('edit','type', $view);
}
function testdisplay(){
//test without action value and modules list in REQUEST object
$view = new ViewMultiedit();
ob_start();
$view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertEquals(0,strlen($renderedContent));
//test with valid action value to get link in return
$view = new ViewMultiedit();
$view->action = 'AjaxFormSave';
$view->module = 'Users';
$view->bean = new User();
$view->bean->id =1;
ob_start();
$view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
//Fails with a fatal error, method creates editview without properly setting it up causing fatal errors.
/*
//test only with modules list in REQUEST object
$view = new ViewMultiedit();
$GLOBALS['current_language']= 'en_us';
$_REQUEST['modules']= Array('Calls','Accounts');
ob_start();
$view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
*/
}
}
?>

View file

@ -0,0 +1,24 @@
<?php
class ViewNoaccessTest extends PHPUnit_Framework_TestCase
{
public function testdisplay()
{
//executet the method and check for default attributes and check that it returns some html.
$view = new ViewNoaccess();
ob_start();
$view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertAttributeEquals('noaccess','type', $view);
$this->assertGreaterThan(0,strlen($renderedContent));
$this->assertEquals(False,json_decode($renderedContent)); //check that it doesn't return json.
}
}

View file

@ -0,0 +1,40 @@
<?php
class ViewQuickTest extends PHPUnit_Framework_TestCase{
public function testViewQuick(){
//execute the contructor and check for the Object type and type attribute
$view = new ViewQuick();
$this->assertInstanceOf('ViewQuick',$view);
$this->assertInstanceOf('ViewDetail',$view);
$this->assertAttributeEquals('detail','type', $view);
$this->assertTrue(is_array($view->options));
}
public function testdisplay(){
$view = new ViewQuick();
//execute the method with required child objects preset. it will return some html.
$view->dv = new DetailView2();
$view->dv->ss = new Sugar_Smarty();
$view->dv->module = "Users";
$view->bean= new User();
$view->bean->id =1;
$view->dv->setup("Users",$view->bean);
ob_start();
$view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
$this->assertNotEquals(False,json_decode($renderedContent));
}
}

View file

@ -0,0 +1,56 @@
<?php
class ViewQuickcreateTest extends PHPUnit_Framework_TestCase
{
public function testpreDisplay()
{
//check without setting any values, it should execute without any issues.
$view = new ViewQuickcreate();
$view->preDisplay();
$this->assertEquals(0,count($_REQUEST));
//check with values preset but without a valid bean id, it sould not change Request parameters
$_REQUEST['source_module'] = "Users";
$_REQUEST['module']= 'Users';
$_REQUEST['record'] = '';
$request = $_REQUEST;
$view->preDisplay();
$this->assertSame($request,$_REQUEST);
//check with values preset, it sould set some addiiotnal Request parameters
$_REQUEST['record'] = 1;
$view->preDisplay();
$this->assertNotSame($request,$_REQUEST);
}
public function testdisplay()
{
error_reporting(E_ERROR | E_PARSE);
//execute the method with required child objects and parameters preset. it will return some html.
$view = new ViewQuickcreate();
$_REQUEST['module']= 'Accounts';
$view->bean = new Account();
ob_start();
$view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
$this->assertEquals(False,json_decode($renderedContent)); //check that it doesn't return json.
}
}

View file

@ -0,0 +1,69 @@
<?php
class ViewQuickeditTest extends PHPUnit_Framework_TestCase
{
public function testpreDisplay()
{
//check without setting any values, it should execute without any issues.
$view = new ViewQuickedit();
$view->preDisplay();
$this->assertEquals(0,count($_REQUEST));
//check with values preset but without a valid bean id, it sould not change Request parameters
$_REQUEST['source_module'] = "Users";
$_REQUEST['module']= 'Users';
$_REQUEST['record'] = '';
$request = $_REQUEST;
$view->preDisplay();
$this->assertSame($request,$_REQUEST);
//check with values preset, it sould set some addiiotnal Request parameters
$_REQUEST['record'] = 1;
$view->preDisplay();
$this->assertNotSame($request,$_REQUEST);
}
public function testdisplay()
{
error_reporting(E_ALL);
//error_reporting(E_ERROR | E_PARSE |E_NOTICE);
//execute the method with required child objects and paramerers preset. it will rteturn some html.
$view = new ViewQuickedit();
$_REQUEST['module'] = 'Accounts';
$_REQUEST['action'] = 'SubpanelCreates';
try{
$view->bean = new Account();
}
Catch(Exception $e){
$this->assertStringStartsWith('mysqli_query()',$e->getMessage());
}
try{
ob_start();
$view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
$this->assertNotEquals(False,json_decode($renderedContent));
}
Catch(Exception $e){
$this->assertStringStartsWith('mysqli_query()',$e->getMessage());
}
}
}

View file

@ -0,0 +1,28 @@
<?php
class ViewVcardTest extends PHPUnit_Framework_TestCase
{
public function testdisplay()
{
//execute the method with required child objects preset and check for the Object type and type attribute
$view = new ViewVcard();
$view->module = "Contacts";
$view->bean = new Contact();
//execute the method and test if it works and does not throws an exception other than headers output exception.
try {
$view->display();
} catch (Exception $e) {
$this->assertStringStartsWith('Cannot modify header information',$e->getMessage());
}
$this->assertInstanceOf('ViewVcard',$view);
$this->assertInstanceOf('SugarView',$view);
$this->assertAttributeEquals('detail','type', $view);
}
}
?>

View file

@ -0,0 +1,37 @@
<?php
class ViewXMLTest extends PHPUnit_Framework_TestCase {
function testViewXML(){
//execute the contructor and check for the Object type and type attribute
$view = new ViewXML();
$this->assertInstanceOf('ViewXML',$view);
$this->assertInstanceOf('SugarView',$view);
$this->assertAttributeEquals('detail','type', $view);
}
function testdisplay(){
//execute the method and check for rexcetions. it should return some html.
$view = new ViewXML();
try {
ob_start();
$view->display();
$renderedContent = ob_get_contents();
ob_end_clean();
$this->assertGreaterThan(0,strlen($renderedContent));
} catch (Exception $e) {
$this->fail();
}
}
}
?>