0
0
Fork 0
mirror of https://github.com/salesagility/SuiteCRM.git synced 2025-02-22 13:08:39 +00:00
salesagility_SuiteCRM/tests/unit/phpunit/include/MVC/View/SugarViewTest.php
j.dang c8d74861b2 Replace explicit bean instantiations in files 71 - 80
- File: '... /install/performSetup.php'

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

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

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

- File: '... /install/UserDemoData.php'

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

- File: '... /tests/unit/phpunit/data/SugarBeanTest.php'

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

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

   - Replaced 3 occurrence(s) of 'new EmailAddress()'

- File: '... /tests/unit/phpunit/include/SubPanel/SubPanelTest.php'

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

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

- File: '... /tests/unit/phpunit/include/MVC/Controller/SugarControllerTest.php'

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

- File: '... /tests/unit/phpunit/include/MVC/View/SugarViewTest.php'

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

- File: '... /tests/unit/phpunit/include/MVC/View/views/view.listTest.php'

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

- File: '... /tests/unit/phpunit/include/MVC/View/views/view.htmlTest.php'

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

- File: '... /tests/unit/phpunit/include/MVC/View/views/view.detailTest.php'

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

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

- File: '... /tests/unit/phpunit/include/MVC/View/views/view.editTest.php'

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

   - Replaced 3 occurrence(s) of 'new User()'
2020-01-22 13:50:53 +00:00

278 lines
8.3 KiB
PHP

<?php
use SuiteCRM\Test\SuitePHPUnitFrameworkTestCase;
class SugarViewTest extends SuitePHPUnitFrameworkTestCase
{
public function setUp()
{
parent::setUp();
global $current_user;
get_sugar_config_defaults();
$current_user = BeanFactory::newBean('Users');
}
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($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
}
$this->assertTrue(true);
}
public function testprocess()
{
// test
$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($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
}
}
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->assertEmpty($errors, print_r($SugarView, true));
} catch (Exception $e) {
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
}
$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($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
}
$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($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
}
$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($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
}
}
public 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($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
}
$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($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
}
$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($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
}
}
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($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
}
}
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($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
} */
//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);
}
}