Update test bootstrapping (#5050)
This commit is contained in:
commit
d311005089
|
@ -16,6 +16,7 @@
|
|||
</rule>
|
||||
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
|
||||
<exclude-pattern>library/Icinga/Application/Cli.php</exclude-pattern>
|
||||
<exclude-pattern>library/Icinga/Application/Test.php</exclude-pattern>
|
||||
<exclude-pattern>library/Icinga/Application/StaticWeb.php</exclude-pattern>
|
||||
<exclude-pattern>library/Icinga/Application/EmbeddedWeb.php</exclude-pattern>
|
||||
<exclude-pattern>library/Icinga/Application/functions.php</exclude-pattern>
|
||||
|
|
|
@ -452,10 +452,15 @@ abstract class ApplicationBootstrap
|
|||
|
||||
protected function getAvailableModulePaths()
|
||||
{
|
||||
$paths = array();
|
||||
$configured = $this->config->get('global', 'module_path', $this->baseDir . '/modules');
|
||||
$paths = [];
|
||||
|
||||
$configured = getenv('ICINGAWEB_MODULES_DIR');
|
||||
if (! $configured) {
|
||||
$configured = $this->config->get('global', 'module_path', $this->baseDir . '/modules');
|
||||
}
|
||||
|
||||
$nextIsPhar = false;
|
||||
foreach (explode(':', $configured) as $path) {
|
||||
foreach (explode(PATH_SEPARATOR, $configured) as $path) {
|
||||
if ($path === 'phar') {
|
||||
$nextIsPhar = true;
|
||||
continue;
|
||||
|
|
|
@ -200,7 +200,7 @@ class Cli extends ApplicationBootstrap
|
|||
* @throws ProgrammingError
|
||||
* @return void
|
||||
*/
|
||||
private function assertRunningOnCli()
|
||||
protected function assertRunningOnCli()
|
||||
{
|
||||
if (Platform::isCli()) {
|
||||
return;
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Application;
|
||||
|
||||
use Icinga\Web\Request;
|
||||
use Icinga\Web\Response;
|
||||
|
||||
require_once __DIR__ . '/Cli.php';
|
||||
|
||||
class Test extends Cli
|
||||
{
|
||||
protected $isCli = false;
|
||||
|
||||
/** @var Request */
|
||||
private $request;
|
||||
|
||||
/** @var Response */
|
||||
private $response;
|
||||
|
||||
public function setRequest(Request $request): void
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function getRequest(): Request
|
||||
{
|
||||
assert(isset($this->request), 'BaseTestCase should have set the request');
|
||||
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
public function setResponse(Response $response): void
|
||||
{
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
public function getResponse(): Response
|
||||
{
|
||||
assert(isset($this->request), 'BaseTestCase should have set the response');
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
public function getFrontController()
|
||||
{
|
||||
return $this; // Callers are expected to only call getRequest or getResponse, hence the app should suffice
|
||||
}
|
||||
|
||||
protected function bootstrap()
|
||||
{
|
||||
$this->assertRunningOnCli();
|
||||
$this->setupLogging()
|
||||
->setupErrorHandling()
|
||||
->loadLibraries()
|
||||
->setupComposerAutoload()
|
||||
->loadConfig()
|
||||
->setupModuleAutoloaders()
|
||||
->setupTimezone()
|
||||
->prepareInternationalization()
|
||||
->setupInternationalization()
|
||||
->parseBasicParams()
|
||||
->setupLogger()
|
||||
->setupModuleManager()
|
||||
->setupUserBackendFactory()
|
||||
->setupFakeAuthentication();
|
||||
}
|
||||
|
||||
public function setupAutoloader()
|
||||
{
|
||||
parent::setupAutoloader();
|
||||
|
||||
if (($icingaLibDir = getenv('ICINGAWEB_ICINGA_LIB')) !== false) {
|
||||
$this->getLoader()->registerNamespace('Icinga', $icingaLibDir);
|
||||
}
|
||||
|
||||
// Conflicts with `Tests\Icinga\Module\...\Lib`. But it seems it's not needed anyway...
|
||||
//$this->getLoader()->registerNamespace('Tests', $this->getBaseDir('test/php/library'));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function detectTimezone()
|
||||
{
|
||||
return 'UTC';
|
||||
}
|
||||
|
||||
private function setupModuleAutoloaders(): self
|
||||
{
|
||||
$modulePaths = getenv('ICINGAWEB_MODULE_DIRS');
|
||||
|
||||
if ($modulePaths) {
|
||||
$modulePaths = preg_split('/:/', $modulePaths, -1, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
|
||||
if (! $modulePaths) {
|
||||
$modulePaths = [];
|
||||
foreach ($this->getAvailableModulePaths() as $path) {
|
||||
$candidates = array_flip(scandir($path));
|
||||
unset($candidates['.'], $candidates['..']);
|
||||
foreach ($candidates as $candidate => $_) {
|
||||
$modulePaths[] = "$path/$candidate";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($modulePaths as $path) {
|
||||
$module = basename($path);
|
||||
|
||||
$moduleNamespace = 'Icinga\\Module\\' . ucfirst($module);
|
||||
$moduleLibraryPath = "$path/library/" . ucfirst($module);
|
||||
|
||||
if (is_dir($moduleLibraryPath)) {
|
||||
$this->getLoader()->registerNamespace($moduleNamespace, $moduleLibraryPath, "$path/application");
|
||||
}
|
||||
|
||||
$moduleTestPath = "$path/test/php/Lib";
|
||||
if (is_dir($moduleTestPath)) {
|
||||
$this->getLoader()->registerNamespace('Tests\\' . $moduleNamespace . '\\Lib', $moduleTestPath);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function setupComposerAutoload(): self
|
||||
{
|
||||
$vendorAutoload = $this->getBaseDir('/vendor/autoload.php');
|
||||
if (file_exists($vendorAutoload)) {
|
||||
require_once $vendorAutoload;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -1,26 +1,11 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace {
|
||||
|
||||
if (!function_exists('t')) {
|
||||
function t()
|
||||
{
|
||||
return func_get_arg(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('mt')) {
|
||||
function mt()
|
||||
{
|
||||
return func_get_arg(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Icinga\Test {
|
||||
|
||||
use Exception;
|
||||
use Icinga\Web\Request;
|
||||
use Icinga\Web\Response;
|
||||
use ipl\I18n\NoopTranslator;
|
||||
use ipl\I18n\StaticTranslator;
|
||||
use RuntimeException;
|
||||
|
@ -39,6 +24,7 @@ namespace Icinga\Test {
|
|||
* Path to application/
|
||||
*
|
||||
* @var string
|
||||
* @deprecated Use Icinga::app()->getApplicationDir() instead
|
||||
*/
|
||||
public static $appDir;
|
||||
|
||||
|
@ -46,13 +32,15 @@ namespace Icinga\Test {
|
|||
* Path to library/Icinga
|
||||
*
|
||||
* @var string
|
||||
* @deprecated Use Icinga::app()->getLibraryDir('Icinga') instead
|
||||
*/
|
||||
public static $libDir;
|
||||
|
||||
/**
|
||||
* Path to etc/
|
||||
*
|
||||
* @var
|
||||
* @var string
|
||||
* @deprecated Use Icinga::app()->getBaseDir('etc') instead
|
||||
*/
|
||||
public static $etcDir;
|
||||
|
||||
|
@ -60,6 +48,7 @@ namespace Icinga\Test {
|
|||
* Path to test/php/
|
||||
*
|
||||
* @var string
|
||||
* @deprecated Use Icinga::app()->getBaseDir('test/php') instead
|
||||
*/
|
||||
public static $testDir;
|
||||
|
||||
|
@ -67,6 +56,7 @@ namespace Icinga\Test {
|
|||
* Path to share/icinga2-web
|
||||
*
|
||||
* @var string
|
||||
* @deprecated Unused
|
||||
*/
|
||||
public static $shareDir;
|
||||
|
||||
|
@ -74,6 +64,7 @@ namespace Icinga\Test {
|
|||
* Path to modules/
|
||||
*
|
||||
* @var string
|
||||
* @deprecated Use Icinga::app()->getModuleManager()->getModuleDirs() instead
|
||||
*/
|
||||
public static $moduleDir;
|
||||
|
||||
|
@ -103,45 +94,11 @@ namespace Icinga\Test {
|
|||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Setup the default timezone
|
||||
*/
|
||||
public static function setupTimezone()
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
/** @var Request */
|
||||
private $requestMock;
|
||||
|
||||
/**
|
||||
* Setup test path environment
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public static function setupDirectories()
|
||||
{
|
||||
$baseDir = getenv('ICINGAWEB_BASEDIR') ?: realpath(__DIR__ . '/../../../');
|
||||
if ($baseDir === false) {
|
||||
throw new RuntimeException('Application base dir not found');
|
||||
}
|
||||
|
||||
$libDir = getenv('ICINGAWEB_ICINGA_LIB') ?: realpath($baseDir . '/library/Icinga');
|
||||
if ($libDir === false) {
|
||||
throw new RuntimeException('Icinga library dir not found');
|
||||
}
|
||||
|
||||
self::$appDir = $baseDir . '/application';
|
||||
self::$libDir = $libDir;
|
||||
self::$etcDir = $baseDir . '/etc';
|
||||
self::$testDir = $baseDir . '/test/php';
|
||||
self::$shareDir = $baseDir . '/share/icinga2-web';
|
||||
|
||||
$modulesDir = getenv('ICINGAWEB_MODULES_DIR');
|
||||
if ($modulesDir && strpos($modulesDir, ':') !== false) {
|
||||
// Only use the env variable if it contains a single path
|
||||
$modulesDir = false;
|
||||
}
|
||||
|
||||
self::$moduleDir = $modulesDir ?: $baseDir . '/modules';
|
||||
}
|
||||
/** @var Response */
|
||||
private $responseMock;
|
||||
|
||||
/**
|
||||
* Setup MVC bootstrapping and ensure that the Icinga-Mock gets reinitialized
|
||||
|
@ -149,20 +106,16 @@ namespace Icinga\Test {
|
|||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->setupRequestMock();
|
||||
$this->setupResponseMock();
|
||||
|
||||
StaticTranslator::$instance = new NoopTranslator();
|
||||
$this->setupIcingaMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup mock object for the application's bootstrap
|
||||
*
|
||||
* @return Mockery\Mock
|
||||
*/
|
||||
protected function setupIcingaMock()
|
||||
private function setupRequestMock()
|
||||
{
|
||||
$requestMock = Mockery::mock('Icinga\Web\Request')->shouldDeferMissing();
|
||||
$requestMock->shouldReceive('getPathInfo')->andReturn('')->byDefault()
|
||||
$this->requestMock = Mockery::mock('Icinga\Web\Request')->shouldDeferMissing();
|
||||
$this->requestMock->shouldReceive('getPathInfo')->andReturn('')->byDefault()
|
||||
->shouldReceive('getBaseUrl')->andReturn('/')->byDefault()
|
||||
->shouldReceive('getQuery')->andReturn(array())->byDefault()
|
||||
->shouldReceive('getParam')->with(Mockery::type('string'), Mockery::type('string'))
|
||||
|
@ -170,43 +123,33 @@ namespace Icinga\Test {
|
|||
return $default;
|
||||
})->byDefault();
|
||||
|
||||
$responseMock = Mockery::mock('Icinga\Web\Response')->shouldDeferMissing();
|
||||
// Can't express this as demeter chains. See: https://github.com/padraic/mockery/issues/59
|
||||
$bootstrapMock = Mockery::mock('Icinga\Application\ApplicationBootstrap')->shouldDeferMissing();
|
||||
$libDir = dirname(self::$libDir);
|
||||
$bootstrapMock->shouldReceive('getFrontController')->andReturn($bootstrapMock)
|
||||
->shouldReceive('getApplicationDir')->andReturn(self::$appDir)
|
||||
->shouldReceive('getLibraryDir')->andReturnUsing(function ($subdir = null) use ($libDir) {
|
||||
if ($subdir !== null) {
|
||||
$libDir .= '/' . ltrim($subdir, '/');
|
||||
}
|
||||
return $libDir;
|
||||
})
|
||||
->shouldReceive('getRequest')->andReturn($requestMock)
|
||||
->shouldReceive('getResponse')->andReturn($responseMock);
|
||||
Icinga::app()->setRequest($this->requestMock);
|
||||
}
|
||||
|
||||
Icinga::setApp($bootstrapMock, true);
|
||||
return $bootstrapMock;
|
||||
private function setupResponseMock()
|
||||
{
|
||||
$this->responseMock = Mockery::mock('Icinga\Web\Response')->shouldDeferMissing();
|
||||
Icinga::app()->setResponse($this->responseMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the currently active request mock object
|
||||
*
|
||||
* @return Icinga\Web\Request
|
||||
* @return Request
|
||||
*/
|
||||
public function getRequestMock()
|
||||
{
|
||||
return Icinga::app()->getRequest();
|
||||
return $this->requestMock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the currently active response mock object
|
||||
*
|
||||
* @return Icinga\Web\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function getResponseMock()
|
||||
{
|
||||
return Icinga::app()->getFrontController()->getResponse();
|
||||
return $this->responseMock;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -362,7 +305,4 @@ namespace Icinga\Test {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
BaseTestCase::setupTimezone();
|
||||
BaseTestCase::setupDirectories();
|
||||
}
|
||||
|
|
|
@ -3,13 +3,22 @@
|
|||
|
||||
namespace Tests\Icinga\Module\Monitoring\Application\Views\Helpers;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Zend_View_Helper_MonitoringFlags;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
require_once realpath(BaseTestCase::$moduleDir . '/monitoring/application/views/helpers/MonitoringFlags.php');
|
||||
|
||||
class MonitoringFlagsTest extends BaseTestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
require_once realpath(
|
||||
Icinga::app()->getModuleManager()->getModuleDir('monitoring')
|
||||
. '/application/views/helpers/MonitoringFlags.php'
|
||||
);
|
||||
}
|
||||
|
||||
public function testHosts1()
|
||||
{
|
||||
$testArray = array(
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
|
||||
namespace Tests\Icinga\Module\Monitoring\Application\Views\Helpers;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Web\View;
|
||||
use Zend_View_Helper_PluginOutput;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
require_once realpath(BaseTestCase::$moduleDir . '/monitoring/application/views/helpers/PluginOutput.php');
|
||||
|
||||
class PluginOutputTest extends BaseTestCase
|
||||
{
|
||||
/** @var Zend_View_Helper_PluginOutput */
|
||||
|
@ -24,6 +23,11 @@ class PluginOutputTest extends BaseTestCase
|
|||
{
|
||||
parent::setUp();
|
||||
|
||||
require_once realpath(
|
||||
Icinga::app()->getModuleManager()->getModuleDir('monitoring')
|
||||
. '/application/views/helpers/PluginOutput.php'
|
||||
);
|
||||
|
||||
$this->helper = $h = new Zend_View_Helper_PluginOutput;
|
||||
$h->setView(new View());
|
||||
}
|
||||
|
|
|
@ -7,8 +7,6 @@ use Mockery;
|
|||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Module\Monitoring\Object\Macro;
|
||||
|
||||
require_once realpath(BaseTestCase::$moduleDir . '/monitoring/library/Monitoring/Object/Macro.php');
|
||||
|
||||
class MacroTest extends BaseTestCase
|
||||
{
|
||||
public function testHostMacros()
|
||||
|
|
|
@ -28,6 +28,7 @@ class PhpCommand extends Command
|
|||
* --verbose Be more verbose.
|
||||
* --build Enable reporting.
|
||||
* --include Pattern to use for including files/test cases.
|
||||
* --phpunit Path to the phpunit executable
|
||||
*
|
||||
* EXAMPLES
|
||||
*
|
||||
|
@ -42,11 +43,15 @@ class PhpCommand extends Command
|
|||
*/
|
||||
public function unitAction()
|
||||
{
|
||||
$build = $this->params->shift('build');
|
||||
$build = (bool) $this->params->shift('build', false);
|
||||
$include = $this->params->shift('include');
|
||||
$phpUnit = $this->params->shift('phpunit');
|
||||
|
||||
$phpUnit = exec('which phpunit');
|
||||
if (!file_exists($phpUnit)) {
|
||||
if (! $phpUnit) {
|
||||
$phpUnit = exec('which phpunit');
|
||||
}
|
||||
|
||||
if (! file_exists($phpUnit)) {
|
||||
$this->fail('PHPUnit not found. Please install PHPUnit to be able to run the unit-test suites.');
|
||||
}
|
||||
|
||||
|
@ -75,7 +80,7 @@ class PhpCommand extends Command
|
|||
$temp->create('phpunit.xml', $phpunitXml->saveXML());
|
||||
|
||||
chdir($baseDir);
|
||||
$command = $this->getEnvironmentVariables()
|
||||
$command = $this->getEnvironmentVariables($build)
|
||||
. $phpUnit
|
||||
. " -c {$temp->resolvePath('phpunit.xml')}"
|
||||
. ' ' . join(' ', array_merge($options, $this->params->getAllStandalone()));
|
||||
|
@ -182,7 +187,7 @@ class PhpCommand extends Command
|
|||
/**
|
||||
* Setup some required environment variables
|
||||
*/
|
||||
protected function getEnvironmentVariables()
|
||||
protected function getEnvironmentVariables(bool $build)
|
||||
{
|
||||
$modulePaths = [];
|
||||
foreach (Icinga::app()->getModuleManager()->getModuleInfo() as $module) {
|
||||
|
@ -197,10 +202,14 @@ class PhpCommand extends Command
|
|||
$vars[] = sprintf('ICINGAWEB_MODULE_DIRS=%s', implode(':', $modulePaths));
|
||||
|
||||
// Disabled as the bootstrap.php for PHPUnit and class BaseTestCase can't handle multiple paths yet
|
||||
/*$vars[] = sprintf(
|
||||
$vars[] = sprintf(
|
||||
'ICINGAWEB_MODULES_DIR=%s',
|
||||
implode(PATH_SEPARATOR, $this->app->getModuleManager()->getModuleDirs())
|
||||
);*/
|
||||
);
|
||||
|
||||
if ($build) {
|
||||
$vars[] = 'XDEBUG_MODE=coverage';
|
||||
}
|
||||
|
||||
return join(' ', $vars) . ' ';
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ class AuthenticationBackendReorderFormTest extends BaseTestCase
|
|||
)
|
||||
);
|
||||
|
||||
Icinga::app()->shouldReceive('getModuleManager->getLoadedModules')->andReturn([]);
|
||||
$this->getRequestMock()->shouldReceive('getMethod')->andReturn('POST')
|
||||
->shouldReceive('isPost')->andReturn(true)
|
||||
->shouldReceive('getPost')->andReturn(array('backend_newpos' => 'test3|1'));
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Tests\Icinga\Views\Helper;
|
||||
|
||||
use Mockery;
|
||||
use Zend_View_Helper_DateFormat;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
|
||||
require_once BaseTestCase::$appDir . '/views/helpers/DateFormat.php';
|
||||
|
||||
class DateFormatTest extends BaseTestCase
|
||||
{
|
||||
public function tearDown(): void
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => date_default_timezone_get()));
|
||||
}
|
||||
|
||||
public function testFormatReturnsCorrectDateWithTimezoneApplied()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => 'Europe/Berlin'));
|
||||
$helper = new Zend_View_Helper_DateFormat($this->getRequestMock());
|
||||
|
||||
$this->assertEquals(
|
||||
'12:05',
|
||||
$helper->format(1397729100, 'H:i'),
|
||||
'Zend_View_Helper_DateFormat::format does not return a valid' .
|
||||
' formatted time or does not apply the user\'s timezone'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatDateReturnsCorrectDate()
|
||||
{
|
||||
$helper = new Zend_View_Helper_DateFormat($this->getRequestMock('d_m_y'));
|
||||
|
||||
$this->assertEquals(
|
||||
'17_04_14',
|
||||
$helper->formatDate(1397729100),
|
||||
'Zend_View_Helper_DateFormat::formatDate does not return a valid formatted date'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatTimeReturnsCorrectTime()
|
||||
{
|
||||
$helper = new Zend_View_Helper_DateFormat($this->getRequestMock(null, 'H:i'));
|
||||
|
||||
$this->assertEquals(
|
||||
'10:05',
|
||||
$helper->formatTime(1397729100),
|
||||
'Zend_View_Helper_DateFormat::formatTime does not return a valid formatted time'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatDatetimeReturnsCorrectDatetime()
|
||||
{
|
||||
$helper = new Zend_View_Helper_DateFormat($this->getRequestMock('d m Y', 'H:i a'));
|
||||
|
||||
$this->assertEquals(
|
||||
'17 04 2014 10:05 am',
|
||||
$helper->formatDateTime(1397729100),
|
||||
'Zend_View_Helper_DateFormat::formatDateTime does not return a valid formatted date and time'
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetDateFormatReturnsCorrectFormat()
|
||||
{
|
||||
$helper = new Zend_View_Helper_DateFormat($this->getRequestMock('d/m-y'));
|
||||
|
||||
$this->assertEquals(
|
||||
'd/m-y',
|
||||
$helper->getDateFormat(),
|
||||
'Zend_View_Helper_DateFormat::getDateFormat does not return the user\'s date format'
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetTimeFormatReturnsCorrectFormat()
|
||||
{
|
||||
$helper = new Zend_View_Helper_DateFormat($this->getRequestMock(null, 'H.i A'));
|
||||
|
||||
$this->assertEquals(
|
||||
'H.i A',
|
||||
$helper->getTimeFormat(),
|
||||
'Zend_View_Helper_DateFormat::getTimeFormat does not return the user\'s time format'
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetDatetimeFormatReturnsCorrectFormat()
|
||||
{
|
||||
$helper = new Zend_View_Helper_DateFormat($this->getRequestMock('d/m-y', 'H.i A'));
|
||||
|
||||
$this->assertEquals(
|
||||
'd/m-y H.i A',
|
||||
$helper->getDateTimeFormat(),
|
||||
'Zend_View_Helper_DateFormat::getDateTimeFormat does not return the user\'s date and time format'
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetDateFormatReturnsFormatFromConfig()
|
||||
{
|
||||
$helper = new Zend_View_Helper_DateFormat($this->getRequestMock());
|
||||
|
||||
$this->assertEquals(
|
||||
'd-m-y',
|
||||
$helper->getDateFormat(),
|
||||
'Zend_View_Helper_DateFormat::getDateFormat does not return the format set' .
|
||||
' in the global configuration if the user\'s preferences do not provide one'
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetTimeFormatReturnsFormatFromConfig()
|
||||
{
|
||||
$helper = new Zend_View_Helper_DateFormat($this->getRequestMock());
|
||||
|
||||
$this->assertEquals(
|
||||
'G:i a',
|
||||
$helper->getTimeFormat(),
|
||||
'Zend_View_Helper_DateFormat::getTimeFormat does not return the format set' .
|
||||
' in the global configuration if the user\'s preferences do not provide one'
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetDatetimeFormatReturnsFormatFromConfig()
|
||||
{
|
||||
$helper = new Zend_View_Helper_DateFormat($this->getRequestMock());
|
||||
|
||||
$this->assertEquals(
|
||||
'd-m-y G:i a',
|
||||
$helper->getDateTimeFormat(),
|
||||
'Zend_View_Helper_DateFormat::getDateTimeFormat does not return the format set' .
|
||||
' in the global configuration if the user\'s preferences do not provide one'
|
||||
);
|
||||
}
|
||||
|
||||
protected function getRequestMock($dateFormat = null, $timeFormat = null)
|
||||
{
|
||||
return Mockery::mock('\Zend_Controller_Request_Abstract');
|
||||
}
|
||||
}
|
|
@ -1,117 +1,14 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
||||
|
||||
$basePath = getenv('ICINGAWEB_BASEDIR') ?: realpath(dirname(__FILE__) . '/../..');
|
||||
$applicationPath = $basePath . '/application';
|
||||
$modulePath = getenv('ICINGAWEB_MODULES_DIR') ?: ($basePath . '/modules');
|
||||
$icingaLibPath = getenv('ICINGAWEB_ICINGA_LIB') ?: ($basePath . '/library/Icinga');
|
||||
$libraryPath = $basePath . '/library';
|
||||
$testLibraryPath = realpath(dirname(__FILE__) . '/library');
|
||||
$configPath = $basePath . '/../config';
|
||||
namespace Icinga\Test {
|
||||
|
||||
// Is usually done in the application's bootstrap and is used by some of our internals
|
||||
if (!defined('ICINGAWEB_APPDIR')) {
|
||||
define('ICINGAWEB_APPDIR', $applicationPath);
|
||||
use Icinga\Application\Test;
|
||||
|
||||
$basePath = getenv('ICINGAWEB_BASEDIR') ?: realpath(dirname(__FILE__) . '/../..');
|
||||
$libraryPath = getenv('ICINGAWEB_ICINGA_LIB') ?: ($basePath . '/library/Icinga');
|
||||
$configPath = $basePath . '/test/config';
|
||||
|
||||
require $libraryPath . '/Application/Test.php';
|
||||
Test::start($basePath, $configPath);
|
||||
}
|
||||
if (!defined('ICINGA_LIBDIR')) {
|
||||
define('ICINGA_LIBDIR', $libraryPath);
|
||||
}
|
||||
|
||||
// This is needed to get the Zend Plugin loader working
|
||||
set_include_path(implode(PATH_SEPARATOR, [
|
||||
$libraryPath,
|
||||
$basePath . DIRECTORY_SEPARATOR . 'vendor',
|
||||
get_include_path()
|
||||
]));
|
||||
|
||||
$vendorAutoload = $basePath . '/vendor/autoload.php';
|
||||
if (file_exists($vendorAutoload)) {
|
||||
require_once $vendorAutoload;
|
||||
}
|
||||
|
||||
require_once($icingaLibPath . '/Test/ClassLoader.php');
|
||||
|
||||
$loader = new Icinga\Test\ClassLoader();
|
||||
$loader->registerNamespace('Tests', $testLibraryPath);
|
||||
$loader->registerNamespace('Icinga', $icingaLibPath);
|
||||
$loader->registerNamespace('Icinga\\Forms', $applicationPath . '/forms');
|
||||
|
||||
$libraryPaths = getenv('ICINGAWEB_LIBDIR');
|
||||
if ($libraryPaths !== false) {
|
||||
$libraryPaths = array_filter(array_map(
|
||||
'realpath',
|
||||
explode(':', $libraryPaths)
|
||||
), 'is_dir');
|
||||
} else {
|
||||
$libraryPaths = is_dir('/usr/share/icinga-php')
|
||||
? ['/usr/share/icinga-php']
|
||||
: [];
|
||||
}
|
||||
|
||||
foreach ($libraryPaths as $externalLibraryPath) {
|
||||
$libPaths = array_flip(scandir($externalLibraryPath));
|
||||
unset($libPaths['.']);
|
||||
unset($libPaths['..']);
|
||||
$libPaths = array_keys($libPaths);
|
||||
foreach ($libPaths as $libPath) {
|
||||
$libPath = join(DIRECTORY_SEPARATOR, [$externalLibraryPath, $libPath]);
|
||||
if (is_dir(realpath($libPath))) {
|
||||
$libAutoLoader = join(DIRECTORY_SEPARATOR, [$libPath, 'vendor', 'autoload.php']);
|
||||
if (file_exists($libAutoLoader)) {
|
||||
require_once $libAutoLoader;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$modulePaths = getenv('ICINGAWEB_MODULE_DIRS');
|
||||
|
||||
if ($modulePaths) {
|
||||
$modulePaths = preg_split('/:/', $modulePaths, -1, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
|
||||
if (! $modulePaths) {
|
||||
$modulePaths = [];
|
||||
foreach (preg_split('/:/', $modulePath, -1, PREG_SPLIT_NO_EMPTY) as $path) {
|
||||
$candidates = array_flip(scandir($path));
|
||||
unset($candidates['.'], $candidates['..']);
|
||||
foreach ($candidates as $candidate => $_) {
|
||||
$modulePaths[] = "$path/$candidate";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($modulePaths as $path) {
|
||||
$module = basename($path);
|
||||
|
||||
$moduleNamespace = 'Icinga\\Module\\' . ucfirst($module);
|
||||
$moduleLibraryPath = "$path/library/" . ucfirst($module);
|
||||
|
||||
if (is_dir($moduleLibraryPath)) {
|
||||
$loader->registerNamespace($moduleNamespace, $moduleLibraryPath);
|
||||
}
|
||||
|
||||
$moduleTestPath = "$path/test/php/Lib";
|
||||
if (is_dir($moduleTestPath)) {
|
||||
$loader->registerNamespace('Tests\\' . $moduleNamespace . '\\Lib', $moduleTestPath);
|
||||
}
|
||||
|
||||
$moduleFormPath = "$path/application/forms";
|
||||
if (is_dir($moduleFormPath)) {
|
||||
$loader->registerNamespace($moduleNamespace . '\\Forms', $moduleFormPath);
|
||||
}
|
||||
}
|
||||
|
||||
$loader->register();
|
||||
|
||||
set_include_path(
|
||||
implode(
|
||||
PATH_SEPARATOR,
|
||||
array($libraryPath . '/vendor', get_include_path())
|
||||
)
|
||||
);
|
||||
|
||||
require_once 'Zend/Loader/Autoloader.php';
|
||||
\Zend_Loader_Autoloader::getInstance();
|
||||
|
||||
Icinga\Application\Config::$configDir = $configPath;
|
||||
|
|
|
@ -245,7 +245,7 @@ class ConfigTest extends BaseTestCase
|
|||
*/
|
||||
public function testWhetherItIsPossibleToRetrieveApplicationConfiguration()
|
||||
{
|
||||
$config = Config::app();
|
||||
$config = Config::app('config', true);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
|
|
|
@ -3,14 +3,23 @@
|
|||
|
||||
namespace Tests\Icinga\Web\Paginator\ScrollingStyle;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Mockery;
|
||||
use Zend_Paginator;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
require_once realpath(BaseTestCase::$libDir . '/Web/Paginator/ScrollingStyle/SlidingWithBorder.php');
|
||||
|
||||
class SlidingwithborderTest extends BaseTestCase
|
||||
class SlidingWithborderTest extends BaseTestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
require_once realpath(
|
||||
Icinga::app()->getLibraryDir('Icinga')
|
||||
. '/Web/Paginator/ScrollingStyle/SlidingWithBorder.php'
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetPages2()
|
||||
{
|
||||
$scrollingStyle = new \Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder();
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
namespace Tests\Icinga\Web;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Authentication\Role;
|
||||
use Mockery;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\User;
|
||||
use Icinga\Web\Widget\SearchDashboard;
|
||||
|
@ -13,23 +13,12 @@ class SearchDashboardTest extends BaseTestCase
|
|||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
$moduleMock = Mockery::mock('Icinga\Application\Modules\Module');
|
||||
$searchUrl = (object) array(
|
||||
'title' => 'Hosts',
|
||||
'url' => 'monitoring/list/hosts?sort=host_severity&limit=10'
|
||||
);
|
||||
$moduleMock->shouldReceive('getSearchUrls')->andReturn(array(
|
||||
$searchUrl
|
||||
));
|
||||
$moduleMock->shouldReceive('getName')->andReturn('test');
|
||||
parent::setUp();
|
||||
|
||||
$moduleManagerMock = Mockery::mock('Icinga\Application\Modules\Manager');
|
||||
$moduleManagerMock->shouldReceive('getLoadedModules')->andReturn(array(
|
||||
'test-module' => $moduleMock
|
||||
));
|
||||
|
||||
$bootstrapMock = $this->setupIcingaMock();
|
||||
$bootstrapMock->shouldReceive('getModuleManager')->andReturn($moduleManagerMock);
|
||||
Icinga::app()->getModuleManager()
|
||||
->loadModule('test-module', '/tmp')
|
||||
->getModule('test-module')
|
||||
->provideSearchUrl('Hosts', 'monitoring/list/hosts?sort=host_severity&limit=10');
|
||||
}
|
||||
|
||||
public function testWhetherRenderThrowsAnExceptionWhenHasNoDashlets()
|
||||
|
|
Loading…
Reference in New Issue