Get tests to not fail if DB is missing - we skip the ones that need a DB

This commit is contained in:
nathangray 2017-02-07 16:02:06 -07:00
parent eeecc2eecd
commit d83a929254
5 changed files with 51 additions and 17 deletions

View File

@ -302,6 +302,9 @@ class SchemaTest extends LoggedInTest {
));
}
/**
* @depends testInsertMoreContent
*/
public function testDropTable()
{
foreach(self::$adodb->MetaTables() as $table)

View File

@ -22,9 +22,21 @@ use PHPUnit_Framework_TestCase as TestCase;
class SecurityTest extends TestCase {
public function setUp()
{
// _check_script_tag uses HtmLawed, which calls GLOBALS['egw']->link()
$GLOBALS['egw'] = $this->getMockBuilder('Egw')
->disableOriginalConstructor()
->setMethods(['link', 'setup'])
->getMock();
}
public function tearDown()
{
unset($GLOBALS['egw_inset_vars']);
// Must remember to clear this, or other tests may break
unset($GLOBALS['egw']);
}
/**
@ -105,10 +117,17 @@ class SecurityTest extends TestCase {
// we currently fail 44 of 140 tests, thought they seem not to apply to our use case, as we check request data
'https://html5sec.org/' => call_user_func(function() {
$payloads = $items = null;
if (!($items_js = file_get_contents('https://html5sec.org/items.js')) ||
!preg_match_all("|^\s+'data'\s+:\s+'(.*)',$|m", $items_js, $items, PREG_PATTERN_ORDER) ||
!($payload_js = file_get_contents('https://html5sec.org/payloads.js')) ||
!preg_match_all("|^\s+'([^']+)'\s+:\s+'(.*)',$|m", $payload_js, $payloads, PREG_PATTERN_ORDER))
try
{
if (!($items_js = file_get_contents('https://html5sec.org/items.js')) ||
!preg_match_all("|^\s+'data'\s+:\s+'(.*)',$|m", $items_js, $items, PREG_PATTERN_ORDER) ||
!($payload_js = file_get_contents('https://html5sec.org/payloads.js')) ||
!preg_match_all("|^\s+'([^']+)'\s+:\s+'(.*)',$|m", $payload_js, $payloads, PREG_PATTERN_ORDER))
{
return false;
}
}
catch (Exception $e)
{
return false;
}

View File

@ -40,6 +40,9 @@ class DateTimeTest extends TestCase {
{
// Reset
DateTime::setUserPrefs(static::$usertime->getName());
unset($GLOBALS['egw']);
parent::tearDownAfterClass();
}
/**

View File

@ -45,9 +45,6 @@ abstract class LoggedInTest extends TestCase
// These globals pulled from the test config (phpunit.xml)
static::load_egw($GLOBALS['EGW_USER'],$GLOBALS['EGW_PASSWORD'], $GLOBALS['EGW_DOMAIN']);
// Re-init config, since it doesn't get handled by loading Egw
Api\Config::init_static();
if($GLOBALS['egw']->db)
{
$GLOBALS['egw']->db->connect();
@ -57,11 +54,14 @@ abstract class LoggedInTest extends TestCase
static::markTestSkipped('No $GLOBALS[egw]->db');
die();
}
// Re-init config, since it doesn't get handled by loading Egw
Api\Config::init_static();
}
catch(Exception $e)
{
static::markTestSkipped('Unable to connect to Egroupware');
throw $e;
static::markTestSkipped('Unable to connect to Egroupware - ' . $e->getMessage());
return;
}
// Do some checks to make sure things we expect are there
@ -101,7 +101,7 @@ abstract class LoggedInTest extends TestCase
}
/**
* Start the eGW session, exits on wrong credentials
* Start the eGW session, skips the test if there are problems connecting
*
* @param string $user
* @param string $passwd
@ -125,13 +125,23 @@ abstract class LoggedInTest extends TestCase
'flags' => array(
'currentapp' => 'api',
'noheader' => true,
'autocreate_session_callback' => __NAMESPACE__ . '\AppTest::create_session',
'autocreate_session_callback' => __CLASS__ .'::create_session',
'no_exception_handler' => 'cli',
'noapi' => false,
)
);
include(realpath(__DIR__ . '/../../../header.inc.php'));
try
{
include(realpath(__DIR__ . '/../../../header.inc.php'));
}
catch (Exception $e)
{
// Something went wrong setting up egw environment - don't try
// to do the test
static::markTestSkipped($e->getMessage());
return;
}
require_once realpath(__DIR__.'/../loader/common.php'); // autoloader & check_load_extension

View File

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Run tests using phpunit -c doc/phpunit.xml -->
<phpunit
colors="true">
colors="true"
backupGlobals="false"
>
<php>
<var name="EGW_DOMAIN" value="default" />
<var name="EGW_USER" value="demo" />
@ -10,10 +12,7 @@
<testsuites>
<testsuite name="Api tests">
<directory>../api/src/test/</directory>
<exclude>
<!-- This runs fine on its own, but fails in a group if there's no DB -->
<file>../api/src/Mail/test/CredentialsTest.php</file>
</exclude>
<directory>../api/src/*/test/</directory>
</testsuite>
<testsuite name="Apps with test directory">
<directory>../*/test/</directory>