0
0
Fork 0
mirror of https://github.com/salesagility/SuiteCRM.git synced 2025-03-17 06:42:43 +00:00
salesagility_SuiteCRM/tests/unit/codecept/include/MVC/View/SugarViewTest.php

381 lines
10 KiB
PHP
Raw Normal View History

2016-02-22 10:29:34 +00:00
<?php
2018-08-31 09:54:26 +00:00
class SugarViewTest extends SuiteCRM\StateCheckerUnitAbstract
2016-02-22 10:29:34 +00:00
{
2018-03-26 14:35:40 +00:00
public function setUp()
{
parent::setUp();
global $current_user;
get_sugar_config_defaults();
$current_user = new User();
}
2016-02-22 10:29:34 +00:00
public function testinit()
{
$state = new SuiteCRM\StateSaver();
2018-08-20 10:22:37 +00:00
//error_reporting(E_ERROR | E_WARNING | E_PARSE);
2016-03-18 16:33:43 +00:00
$SugarView = new SugarView();
//execute the method and check if it works and doesn't throws an exception
try {
$SugarView->init();
} catch (Exception $e) {
2018-04-03 13:51:04 +00:00
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
$this->assertTrue(true);
// clean up
2018-08-20 10:22:37 +00:00
2016-02-22 10:29:34 +00:00
}
public function testprocess()
{
2018-08-20 10:22:37 +00:00
// save state
2018-04-10 15:59:49 +00:00
$state = new \SuiteCRM\StateSaver();
$state->pushTable('tracker');
2018-04-03 14:00:59 +00:00
$state->pushGlobals();
2018-04-10 15:59:49 +00:00
2018-08-20 10:22:37 +00:00
// test
2018-06-19 19:35:10 +00:00
2018-08-20 10:22:37 +00:00
//error_reporting(E_ERROR | E_PARSE);
2018-03-30 12:22:37 +00:00
2016-03-18 16:33:43 +00:00
$SugarView = new SugarView();
$SugarView->module = 'Users';
$GLOBALS['app'] = new SugarApplication();
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
//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) {
2018-04-03 13:51:04 +00:00
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
2018-03-30 12:22:37 +00:00
// clean up
2018-04-03 14:00:59 +00:00
$state->popGlobals();
2018-04-10 15:59:49 +00:00
$state->popTable('tracker');
2016-02-22 10:29:34 +00:00
}
public function testdisplayErrors()
{
$state = new SuiteCRM\StateSaver();
2018-08-20 10:22:37 +00:00
//error_reporting(E_ERROR | E_PARSE);
2016-03-18 16:33:43 +00:00
$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));
2016-03-18 16:33:43 +00:00
} catch (Exception $e) {
2018-04-03 13:51:04 +00:00
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
$this->assertTrue(true);
// clean up
2018-08-20 10:22:37 +00:00
2016-02-22 10:29:34 +00:00
}
public function testpreDisplay()
{
$state = new SuiteCRM\StateSaver();
2018-08-20 10:22:37 +00:00
//error_reporting(E_ERROR | E_PARSE);
2016-03-18 16:33:43 +00:00
$SugarView = new SugarView();
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
//execute the method and check if it works and doesn't throws an exception
try {
$SugarView->preDisplay();
} catch (Exception $e) {
2018-04-03 13:51:04 +00:00
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
$this->assertTrue(true);
// clean up
2018-08-20 10:22:37 +00:00
2016-03-18 16:33:43 +00:00
}
2016-02-22 10:29:34 +00:00
public function testdisplay()
{
$state = new SuiteCRM\StateSaver();
2018-08-20 10:22:37 +00:00
//error_reporting(E_ERROR | E_PARSE);
2016-03-18 16:33:43 +00:00
$SugarView = new SugarView();
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
//execute the method and check if it works and doesn't throws an exception
try {
$SugarView->display();
} catch (Exception $e) {
2018-04-03 13:51:04 +00:00
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
$this->assertTrue(true);
// clean up
2018-08-20 10:22:37 +00:00
2016-02-22 10:29:34 +00:00
}
public function testdisplayHeader()
{
$state = new SuiteCRM\StateSaver();
2018-08-20 10:22:37 +00:00
//error_reporting(E_ERROR | E_PARSE);
2016-03-18 16:33:43 +00:00
$SugarView = new SugarView();
$SugarView->module = 'Users';
$GLOBALS['app'] = new SugarApplication();
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
//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) {
2018-04-03 13:51:04 +00:00
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
// clean up
2018-08-20 10:22:37 +00:00
2016-02-22 10:29:34 +00:00
}
2016-03-18 16:33:43 +00:00
public function testgetModuleMenuHTML()
2016-02-22 10:29:34 +00:00
{
$state = new SuiteCRM\StateSaver();
2018-08-20 10:22:37 +00:00
//error_reporting(E_ERROR | E_PARSE);
2016-03-18 16:33:43 +00:00
$SugarView = new SugarView();
//execute the method and check if it works and doesn't throws an exception
try {
$SugarView->getModuleMenuHTML();
} catch (Exception $e) {
2018-04-03 13:51:04 +00:00
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
$this->assertTrue(true);
// clean up
2018-08-20 10:22:37 +00:00
2016-02-22 10:29:34 +00:00
}
public function testincludeClassicFile()
{
$state = new SuiteCRM\StateSaver();
2018-08-20 10:22:37 +00:00
//error_reporting(E_ERROR | E_PARSE);
2016-03-18 16:33:43 +00:00
$SugarView = new SugarView();
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
//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) {
2018-04-03 13:51:04 +00:00
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
$this->assertTrue(true);
// clean up
2018-08-20 10:22:37 +00:00
2016-03-18 16:33:43 +00:00
}
2016-02-22 10:29:34 +00:00
public function testgetJavascriptValidation()
{
2018-08-20 10:22:37 +00:00
//check if it returns any text i-e JS code
2016-03-18 16:33:43 +00:00
$js = SugarView::getJavascriptValidation();
$this->assertGreaterThan(0, strlen($js));
2016-02-22 10:29:34 +00:00
}
public function testdisplayFooter()
{
$state = new SuiteCRM\StateSaver();
2018-08-20 10:22:37 +00:00
//error_reporting(E_ERROR | E_PARSE);
2016-03-18 16:33:43 +00:00
$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) {
2018-04-03 13:51:04 +00:00
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
// clean up
2018-08-20 10:22:37 +00:00
2016-02-22 10:29:34 +00:00
}
public function testrenderJavascript()
{
$state = new SuiteCRM\StateSaver();
2018-08-20 10:22:37 +00:00
//error_reporting(E_ERROR | E_PARSE);
2016-03-18 16:33:43 +00:00
$SugarView = new SugarView();
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
//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) {
2018-04-03 13:51:04 +00:00
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
// clean up
2018-08-20 10:22:37 +00:00
2016-02-22 10:29:34 +00:00
}
public function testgetMenu()
{
2018-08-20 10:22:37 +00:00
////error_reporting(E_ALL);
2016-03-18 16:33:43 +00:00
$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
/*
2016-02-22 10:29:34 +00:00
try {
//check first with invalid value and test if it throws an exception
$menu = $SugarView->getMenu();
2018-08-20 10:22:37 +00:00
//$this->assertTrue(is_array($menu));
2016-02-22 10:29:34 +00:00
} catch (Exception $e) {
$this->assertTrue(TRUE);
2018-08-20 10:22:37 +00:00
//$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
} */
//check with valid value and check if it returns an array.
$menu = $SugarView->getMenu('Users');
$this->assertTrue(is_array($menu));
2016-02-22 10:29:34 +00:00
}
public function testgetModuleTitle()
{
2016-03-18 16:33:43 +00:00
$SugarView = new SugarView();
//first execute the method with default value
$moduleTitle = $SugarView->getModuleTitle();
$this->assertGreaterThan(0, strlen($moduleTitle));
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
//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));
}
2016-02-22 10:29:34 +00:00
public function testgetMetaDataFile()
{
2016-03-18 16:33:43 +00:00
$SugarView = new SugarView();
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
//first execute the method with missing attributes. it should return Null.
$metaDataFile = $SugarView->getMetaDataFile();
$this->assertEquals(null, $metaDataFile);
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
//second execute the method with valid attributes set. it should return a file path string.
$SugarView->type = 'detail';
$SugarView->module = 'Users';
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
$metaDataFile = $SugarView->getMetaDataFile();
$this->assertGreaterThan(0, strlen($metaDataFile));
2016-02-22 10:29:34 +00:00
}
public function testgetBrowserTitle()
{
2016-03-18 16:33:43 +00:00
$SugarView = new SugarView();
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
//execute the method. it should return a title string.
$browserTitle = $SugarView->getBrowserTitle();
$this->assertGreaterThan(0, strlen($browserTitle));
2016-02-22 10:29:34 +00:00
}
public function testgetBreadCrumbSymbol()
{
2016-03-18 16:33:43 +00:00
$SugarView = new SugarView();
2016-02-22 10:29:34 +00:00
2016-03-18 16:33:43 +00:00
//execute the method. it should return a string.
$breadCrumbSymbol = $SugarView->getBreadCrumbSymbol();
$this->assertGreaterThan(0, strlen($breadCrumbSymbol));
2016-02-22 10:29:34 +00:00
}
2016-03-18 16:33:43 +00:00
public function testcheckPostMaxSizeError()
{
2018-07-19 10:23:31 +00:00
$SugarView = new SugarView();
2018-08-20 10:22:37 +00:00
2016-03-18 16:33:43 +00:00
//execute the method. it should return False because Request parameters are not available.
$postMaxSizeError = $SugarView->checkPostMaxSizeError();
$this->assertFalse($postMaxSizeError);
2016-02-22 10:29:34 +00:00
}
}