parent
927772578d
commit
4c8428423e
|
@ -43,14 +43,6 @@ use Icinga\Application\Icinga;
|
|||
*/
|
||||
class Url
|
||||
{
|
||||
/**
|
||||
* Rather dirty hack as the ApplicationBootstrap isn't an interface right now and can't be mocked
|
||||
* overwrite this to use a specific request for all Urls (so only in tests)
|
||||
*
|
||||
* @var null
|
||||
*/
|
||||
public static $overwrittenRequest = null;
|
||||
|
||||
/**
|
||||
* An array of all parameters stored in this Url
|
||||
*
|
||||
|
@ -123,9 +115,6 @@ class Url
|
|||
*/
|
||||
private static function getRequest()
|
||||
{
|
||||
if (self::$overwrittenRequest) {
|
||||
return self::$overwrittenRequest;
|
||||
}
|
||||
return Icinga::app()->getFrontController()->getRequest();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Tests\Icinga\Modules\Monitoring\Application\Views\Helpers;
|
||||
|
||||
use \stdClass;
|
||||
use \Mockery;
|
||||
use \Zend_View_Helper_ResolveMacros;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
|
@ -16,7 +16,7 @@ class ResolveMacrosTest extends BaseTestCase
|
|||
{
|
||||
public function testHostMacros()
|
||||
{
|
||||
$hostMock = new stdClass();
|
||||
$hostMock = Mockery::mock('host');
|
||||
$hostMock->host_name = 'test';
|
||||
$hostMock->host_address = '1.1.1.1';
|
||||
|
||||
|
@ -27,7 +27,7 @@ class ResolveMacrosTest extends BaseTestCase
|
|||
|
||||
public function testServiceMacros()
|
||||
{
|
||||
$svcMock = new stdClass();
|
||||
$svcMock = Mockery::mock('service');
|
||||
$svcMock->host_name = 'test';
|
||||
$svcMock->host_address = '1.1.1.1';
|
||||
$svcMock->service_description = 'a service';
|
||||
|
@ -40,7 +40,7 @@ class ResolveMacrosTest extends BaseTestCase
|
|||
|
||||
public function testCustomvars()
|
||||
{
|
||||
$objectMock = new stdClass();
|
||||
$objectMock = Mockery::mock('object');
|
||||
$objectMock->customvars = array(
|
||||
'CUSTOMVAR' => 'test'
|
||||
);
|
||||
|
@ -51,7 +51,7 @@ class ResolveMacrosTest extends BaseTestCase
|
|||
|
||||
public function testFaultyMacros()
|
||||
{
|
||||
$hostMock = new stdClass();
|
||||
$hostMock = Mockery::mock('host');
|
||||
$hostMock->host_name = 'test';
|
||||
$hostMock->customvars = array(
|
||||
'HOST' => 'te',
|
||||
|
@ -67,7 +67,7 @@ class ResolveMacrosTest extends BaseTestCase
|
|||
|
||||
public function testMacrosWithSpecialCharacters()
|
||||
{
|
||||
$objectMock = new stdClass();
|
||||
$objectMock = Mockery::mock('object');
|
||||
$objectMock->customvars = array(
|
||||
'V€RY_SP3C|@L' => 'not too special!'
|
||||
);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Tests\Icinga\Module\Monitoring\Library\Filter;
|
||||
|
||||
use Icinga\Filter\Filterable;
|
||||
use \Mockery;
|
||||
use Icinga\Module\Monitoring\Filter\Type\StatusFilter;
|
||||
use Icinga\Filter\Query\Node;
|
||||
use Icinga\Filter\Filter;
|
||||
|
@ -13,36 +13,19 @@ use Icinga\Filter\FilterAttribute;
|
|||
use Icinga\Module\Monitoring\Filter\UrlViewFilter;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
class FilterMock implements Filterable
|
||||
{
|
||||
public function isValidFilterTarget($field)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getMappedField($field)
|
||||
{
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function applyFilter()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function clearFilter()
|
||||
{
|
||||
// TODO: Implement clearFilter() method.
|
||||
}
|
||||
|
||||
public function addFilter($filter)
|
||||
{
|
||||
// TODO: Implement addFilter() method.
|
||||
}
|
||||
}
|
||||
|
||||
class UrlViewFilterTest extends BaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->filterMock = Mockery::mock('Icinga\Filter\Filterable');
|
||||
$this->filterMock->shouldReceive('isValidFilterTarget')->with(Mockery::any())->andReturn(true)
|
||||
->shouldReceive('getMappedField')->andReturnUsing(function ($f) { return $f; })
|
||||
->shouldReceive('applyFilter')->andReturn(true)
|
||||
->shouldReceive('clearFilter')->andReturnNull()
|
||||
->shouldReceive('addFilter')->with(Mockery::any())->andReturnNull();
|
||||
}
|
||||
|
||||
public function testUrlParamCreation()
|
||||
{
|
||||
$this->markTestSkipped('Or queries are disabled');
|
||||
|
@ -71,7 +54,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
. ' and attr5 is UP';
|
||||
|
||||
$tree = $searchEngine->createQueryTreeForFilter($query);
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$uri = $filterFactory->fromTree($tree);
|
||||
$this->assertEquals(
|
||||
'attr1!=Hans+wurst|attr2=%2Asomething%2A&attr3=bla%2A|attr4=1&host_last_state_change>=yesterday&attr5=0',
|
||||
|
@ -82,7 +65,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
|
||||
public function testTreeFromSimpleKeyValueUrlCreation()
|
||||
{
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$tree = $filterFactory->parseUrl('attr1!=Hans+Wurst');
|
||||
$this->assertEquals(
|
||||
$tree->root->type,
|
||||
|
@ -110,7 +93,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
{
|
||||
$this->markTestSkipped("OR queries are disabled");
|
||||
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$query = 'attr1!=Hans+Wurst&test=test123|bla=1';
|
||||
$tree = $filterFactory->parseUrl($query);
|
||||
$this->assertEquals($tree->root->type, Node::TYPE_AND, 'Assert the root of the filter tree to be an AND node');
|
||||
|
@ -120,7 +103,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
public function testImplicitConjunctionInUrl()
|
||||
{
|
||||
$this->markTestSkipped("OR queries are disabled");
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$query = 'attr1!=Hans+Wurst&test=test123|bla=1|2|3';
|
||||
$tree = $filterFactory->parseUrl($query);
|
||||
$this->assertEquals($tree->root->type, Node::TYPE_AND, 'Assert the root of the filter tree to be an AND node');
|
||||
|
@ -133,7 +116,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
|
||||
public function testMissingValuesInQueries()
|
||||
{
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$queryStr = 'attr1!=Hans+Wurst&test=';
|
||||
$tree = $filterFactory->parseUrl($queryStr);
|
||||
$query = $filterFactory->fromTree($tree);
|
||||
|
@ -142,7 +125,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
|
||||
public function testErrorInQueries()
|
||||
{
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$queryStr = 'test=&attr1!=Hans+Wurst';
|
||||
$tree = $filterFactory->parseUrl($queryStr);
|
||||
$query = $filterFactory->fromTree($tree);
|
||||
|
@ -151,7 +134,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
|
||||
public function testSenselessConjunctions()
|
||||
{
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$queryStr = 'test=&|/5/|&attr1!=Hans+Wurst';
|
||||
$tree = $filterFactory->parseUrl($queryStr);
|
||||
$query = $filterFactory->fromTree($tree);
|
||||
|
@ -161,7 +144,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
public function testRandomString()
|
||||
{
|
||||
$filter = '';
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
|
||||
for ($i=0; $i<10;$i++) {
|
||||
$filter .= str_shuffle('&|ds& wra =!<>|dsgs=,-G');
|
||||
|
|
|
@ -4,16 +4,22 @@
|
|||
|
||||
namespace Tests\Icinga\Form\Config;
|
||||
|
||||
use \Mockery;
|
||||
use \Zend_Config;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Tests\Icinga\Web\RequestMock;
|
||||
|
||||
/**
|
||||
* Test for the authentication provider form
|
||||
*/
|
||||
class AuthenticationFormTest extends BaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->viewMock = Mockery::mock('\Zend_View');
|
||||
$this->viewMock->shouldReceive('icon')->andReturn('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the ldap provider form population from config
|
||||
*/
|
||||
|
@ -87,16 +93,13 @@ class AuthenticationFormTest extends BaseTestCase
|
|||
|
||||
/**
|
||||
* Test whether order modifications via 'priority' are considered
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function testModifyOrder()
|
||||
{
|
||||
$this->markTestSkipped('ReorderForm is broken');
|
||||
Url::$overwrittenRequest = new RequestMock();
|
||||
$form = $this->createForm('Icinga\Form\Config\Authentication\ReorderForm');
|
||||
$form->setAuthenticationBackend('backend2');
|
||||
$form->setCurrentOrder(array('backend1', 'backend2', 'backend3', 'backend4'));
|
||||
$form->setView($this->viewMock);
|
||||
|
||||
$form->create();
|
||||
$this->assertSame(
|
||||
|
@ -127,17 +130,14 @@ class AuthenticationFormTest extends BaseTestCase
|
|||
|
||||
/**
|
||||
* Test whether the reorder form doesn't display senseless ordering (like moving the uppermost element up or
|
||||
* the lowermose down)
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
* the lowermost down)
|
||||
*/
|
||||
public function testInvalidOrderingNotShown()
|
||||
{
|
||||
$this->markTestSkipped('ReorderForm is broken');
|
||||
Url::$overwrittenRequest = new RequestMock();
|
||||
$form = $this->createForm('Icinga\Form\Config\Authentication\ReorderForm');
|
||||
$form->setAuthenticationBackend('backend1');
|
||||
$form->setCurrentOrder(array('backend1', 'backend2', 'backend3', 'backend4'));
|
||||
$form->setView($this->viewMock);
|
||||
|
||||
$form->create();
|
||||
$this->assertSame(
|
||||
|
|
|
@ -8,16 +8,22 @@ namespace Tests\Icinga\Form\Config;
|
|||
require_once realpath(ICINGA_APPDIR . '/views/helpers/DateFormat.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \DateTimeZone;
|
||||
use \Mockery;
|
||||
use \DOMDocument;
|
||||
use \Zend_Config;
|
||||
use \Zend_View;
|
||||
use \Zend_View_Helper_DateFormat;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
class GeneralFormTest extends BaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->viewMock = Mockery::mock('\Zend_View');
|
||||
$this->viewMock->shouldReceive('icon')->andReturn('');
|
||||
}
|
||||
|
||||
private function isHiddenElement($value, $htmlString)
|
||||
{
|
||||
$html = new DOMDocument();
|
||||
|
@ -36,13 +42,9 @@ class GeneralFormTest extends BaseTestCase
|
|||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public function testCorrectFieldPopulation()
|
||||
{
|
||||
$this->markTestSkipped('GeneralForm uses the url view helper (icon helper function). Set a view mock with setView!');
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
$form = $this->createForm('Icinga\Form\Config\GeneralForm');
|
||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||
$form->setConfiguration(
|
||||
|
@ -72,8 +74,10 @@ class GeneralFormTest extends BaseTestCase
|
|||
)
|
||||
);
|
||||
$form->setConfigDir('/tmp');
|
||||
$form->setView($this->viewMock);
|
||||
|
||||
$form->create();
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$form->getValue('environment'),
|
||||
|
@ -118,8 +122,6 @@ class GeneralFormTest extends BaseTestCase
|
|||
|
||||
public function testCorrectConditionalIniFieldRendering()
|
||||
{
|
||||
$this->markTestSkipped('GeneralForm uses the url view helper (icon helper function). Set a view mock with setView!');
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
$form = $this->createForm('Icinga\Form\Config\GeneralForm');
|
||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||
$form->setConfiguration(
|
||||
|
@ -140,8 +142,9 @@ class GeneralFormTest extends BaseTestCase
|
|||
)
|
||||
)
|
||||
);
|
||||
$form->create();
|
||||
$form->setView($this->viewMock);
|
||||
|
||||
$form->create();
|
||||
$view = new Zend_View();
|
||||
|
||||
$this->assertFalse(
|
||||
|
@ -156,8 +159,6 @@ class GeneralFormTest extends BaseTestCase
|
|||
|
||||
public function testCorrectConditionalDbFieldRendering()
|
||||
{
|
||||
$this->markTestSkipped('GeneralForm uses the url view helper (icon helper function). Set a view mock with setView!');
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
$form = $this->createForm('Icinga\Form\Config\GeneralForm');
|
||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||
$form->setConfiguration(
|
||||
|
@ -179,6 +180,8 @@ class GeneralFormTest extends BaseTestCase
|
|||
)
|
||||
)
|
||||
);
|
||||
$form->setView($this->viewMock);
|
||||
|
||||
$form->create();
|
||||
$view = new Zend_View();
|
||||
|
||||
|
|
|
@ -8,11 +8,9 @@ namespace Tests\Icinga\Form\Preference;
|
|||
require_once realpath(ICINGA_APPDIR . '/views/helpers/DateFormat.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \DateTimeZone;
|
||||
use \Zend_View_Helper_DateFormat;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
|
||||
/**
|
||||
* Test for general form, mainly testing enable/disable behaviour
|
||||
|
@ -24,7 +22,6 @@ class GeneralFormTest extends BaseTestCase
|
|||
*/
|
||||
public function testDisableFormIfUsingDefault()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
$form = $this->createForm('Icinga\Form\Preference\GeneralForm');
|
||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||
$form->setRequest($this->getRequest());
|
||||
|
@ -41,7 +38,6 @@ class GeneralFormTest extends BaseTestCase
|
|||
*/
|
||||
public function testEnableFormIfUsingPreference()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
$form = $this->createForm('Icinga\Form\Preference\GeneralForm');
|
||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||
$form->setRequest($this->getRequest());
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Application;
|
||||
|
||||
/**
|
||||
* Partially emulate the functionality of Zend_Db
|
||||
*/
|
||||
class ZendDbMock
|
||||
{
|
||||
/**
|
||||
* The config that was used in the last call of the factory function
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private static $config;
|
||||
|
||||
/**
|
||||
* Name of the adapter class that was used in the last call of the factory function
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private static $adapter;
|
||||
|
||||
/**
|
||||
* Mock the factory-method of Zend_Db and save the given parameters
|
||||
*
|
||||
* @param $adapter String name of base adapter class, or Zend_Config object
|
||||
* @param $config mixed OPTIONAL; an array or Zend_Config object with adapter
|
||||
* parameters
|
||||
*
|
||||
* @return stdClass Empty object
|
||||
*/
|
||||
public static function factory($adapter, $config)
|
||||
{
|
||||
self::$config = $config;
|
||||
self::$adapter = $adapter;
|
||||
return new \stdClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the adapter class that was used in the last call
|
||||
* of the factory function
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static function getAdapter()
|
||||
{
|
||||
return self::$adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config that was used in the last call of the factory function
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
return self::$config;
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@
|
|||
namespace Tests\Icinga\Authentication;
|
||||
|
||||
use \PDO;
|
||||
use \Zend_Config;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Data\Db\Connection;
|
||||
use Icinga\Authentication\Backend\DbUserBackend;
|
||||
|
@ -56,22 +55,6 @@ class DbUserBackendTest extends BaseTestCase
|
|||
)
|
||||
);
|
||||
|
||||
private function createDbConnection($resource, $name = null)
|
||||
{
|
||||
if ($name === null) {
|
||||
$name = 'TestDbUserBackend-' . uniqid();
|
||||
}
|
||||
|
||||
$config = new Zend_Config(
|
||||
array(
|
||||
'name' => $name,
|
||||
'resource' => $resource
|
||||
)
|
||||
);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the authentication functions of the DbUserBackend using PostgreSQL as backend.
|
||||
*
|
||||
|
|
|
@ -71,7 +71,7 @@ class LdapUserBackendTest extends BaseTestCase
|
|||
}
|
||||
}
|
||||
|
||||
private function insertTestdata($connection)
|
||||
private function insertTestData($connection)
|
||||
{
|
||||
foreach ($this->baseOu as $ou => $info) {
|
||||
if (ldap_add($connection, $ou, $info) === false) {
|
||||
|
|
|
@ -4,42 +4,30 @@
|
|||
|
||||
namespace Tests\Icinga\Filter;
|
||||
|
||||
use \Mockery;
|
||||
use Icinga\Filter\Query\Node;
|
||||
use Icinga\Filter\FilterAttribute;
|
||||
use Icinga\Filter\Type\FilterType;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
class TypeMock extends FilterType
|
||||
{
|
||||
public function isValidQuery($query)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function createTreeNode($query, $leftOperand)
|
||||
{
|
||||
$node = new Node();
|
||||
$node->left = $leftOperand;
|
||||
return $node;
|
||||
}
|
||||
|
||||
public function getProposalsForQuery($query)
|
||||
{
|
||||
return $this->getOperators();
|
||||
}
|
||||
|
||||
public function getOperators()
|
||||
{
|
||||
return array('op1', 'is better than', 'is worse than');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class QueryHandlerTest extends BaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$typeMock = Mockery::mock('Icinga\Filter\Type\FilterType');
|
||||
$typeMock->shouldReceive('isValidQuery')->with(Mockery::type('string'))->andReturn(true)
|
||||
->shouldReceive('getOperators')->andReturn(array('op1', 'is better than', 'is worse than'))
|
||||
->shouldReceive('getProposalsForQuery')->with(Mockery::type('string'))->andReturnUsing(
|
||||
function ($query) use ($typeMock) { return $typeMock->getOperators(); }
|
||||
)->shouldReceive('createTreeNode')->with(Mockery::type('string'), Mockery::any())->andReturnUsing(
|
||||
function ($query, $leftOperand) { $node = new Node(); $node->left = $leftOperand; return $node; }
|
||||
);
|
||||
$this->typeMock = $typeMock;
|
||||
}
|
||||
|
||||
public function testQueryHandlerSetup()
|
||||
{
|
||||
$handler = new FilterAttribute(new TypeMock());
|
||||
$handler = new FilterAttribute($this->typeMock);
|
||||
$handler->setField('current_status');
|
||||
$handler->setHandledAttributes('State', 'Status', 'Current State');
|
||||
$this->assertTrue(
|
||||
|
@ -58,7 +46,7 @@ class QueryHandlerTest extends BaseTestCase
|
|||
|
||||
public function testQueryProposal()
|
||||
{
|
||||
$handler = new FilterAttribute(new TypeMock());
|
||||
$handler = new FilterAttribute($this->typeMock);
|
||||
|
||||
$handler->setField('current_status');
|
||||
$handler->setHandledAttributes('Status', 'State', 'Current State');
|
||||
|
@ -84,7 +72,7 @@ class QueryHandlerTest extends BaseTestCase
|
|||
|
||||
public function testOperatorProposal()
|
||||
{
|
||||
$handler = new FilterAttribute(new TypeMock());
|
||||
$handler = new FilterAttribute($this->typeMock);
|
||||
$handler->setField('current_status')
|
||||
->setHandledAttributes('status', 'state', 'current state');
|
||||
$this->assertEquals(
|
||||
|
@ -96,7 +84,7 @@ class QueryHandlerTest extends BaseTestCase
|
|||
|
||||
public function testAttributeRecognition()
|
||||
{
|
||||
$handler = new FilterAttribute(new TypeMock());
|
||||
$handler = new FilterAttribute($this->typeMock);
|
||||
$handler->setField('current_status')
|
||||
->setHandledAttributes('status', 'state', 'current state');
|
||||
$node = $handler->convertToTreeNode('status is not \’some kind of magic\'');
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
namespace Tests\Icinga\Protocol\Statusdat\Component;
|
||||
|
||||
use \Zend_Config;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Protocol\Statusdat\Exceptions;
|
||||
|
||||
class ParsingException extends RuntimeException
|
||||
{
|
||||
}
|
|
@ -4,36 +4,25 @@
|
|||
|
||||
namespace Tests\Icinga\Web\Hook\Configuration;
|
||||
|
||||
use \Mockery;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Web\Hook\Configuration\ConfigurationTab;
|
||||
use Icinga\Web\Hook\Configuration\ConfigurationTabBuilder;
|
||||
use Icinga\Web\Hook;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\Tabs;
|
||||
|
||||
class RequestMock
|
||||
{
|
||||
public function getBaseUrl()
|
||||
{
|
||||
return "/";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ConfigurationTabBuilderTest extends BaseTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Hook::clean();
|
||||
Url::$overwrittenRequest = new RequestMock();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
Hook::clean();
|
||||
Url::$overwrittenRequest = null;
|
||||
}
|
||||
|
||||
public function testDefaultTabs()
|
||||
|
@ -74,7 +63,7 @@ class ConfigurationTabBuilderTest extends BaseTestCase
|
|||
$widget = new Tabs();
|
||||
$builder = new ConfigurationTabBuilder($widget);
|
||||
|
||||
$tab = new \stdClass();
|
||||
$tab = Mockery::mock('Tab');
|
||||
Hook::registerObject(ConfigurationTabBuilder::HOOK_NAMESPACE, 'misc', $tab);
|
||||
$builder->build();
|
||||
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Web;
|
||||
|
||||
/**
|
||||
* Request mock that implements all methods required by the Url class
|
||||
*/
|
||||
class RequestMock
|
||||
{
|
||||
/**
|
||||
* The path of the request
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $path = "";
|
||||
|
||||
/**
|
||||
* The baseUrl of the request
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $baseUrl = '/';
|
||||
|
||||
/**
|
||||
* An array of query parameters that the request should resemble
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $query = array();
|
||||
|
||||
/**
|
||||
* Returns the path set for the request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPathInfo()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the baseUrl set for the request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseUrl()
|
||||
{
|
||||
return $this->baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query set for the request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
}
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
namespace Tests\Icinga\Web;
|
||||
|
||||
use \Mockery;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Tests\Icinga\Web\RequestMock;
|
||||
|
||||
/**
|
||||
* Tests for the Icinga\Web\Url class that provides convenient access to Url manipulation method
|
||||
|
@ -18,7 +18,7 @@ class UrlTest extends BaseTestCase
|
|||
*/
|
||||
function testFromStringWithoutQuery()
|
||||
{
|
||||
$url = Url::fromPath('http://myHost/my/test/url.html', array(), new RequestMock());
|
||||
$url = Url::fromPath('http://myHost/my/test/url.html');
|
||||
$this->assertEquals(
|
||||
'/my/test/url.html',
|
||||
$url->getPath(),
|
||||
|
@ -36,7 +36,7 @@ class UrlTest extends BaseTestCase
|
|||
*/
|
||||
function testFromUrlWithBasePath()
|
||||
{
|
||||
$url = Url::fromPath('my/test/url.html', array(), new RequestMock());
|
||||
$url = Url::fromPath('my/test/url.html');
|
||||
$url->setBaseUrl('the/path/to');
|
||||
$this->assertEquals(
|
||||
'/the/path/to/my/test/url.html',
|
||||
|
@ -50,7 +50,7 @@ class UrlTest extends BaseTestCase
|
|||
*/
|
||||
function testFromUrlWithKeyValueQuery()
|
||||
{
|
||||
$url = Url::fromPath('/my/test/url.html?param1=%25arg1¶m2=arg2', array(), new RequestMock());
|
||||
$url = Url::fromPath('/my/test/url.html?param1=%25arg1¶m2=arg2');
|
||||
$this->assertEquals(
|
||||
'/my/test/url.html',
|
||||
$url->getPath(),
|
||||
|
@ -71,7 +71,7 @@ class UrlTest extends BaseTestCase
|
|||
*/
|
||||
function testFromUrlWithArrayInQuery()
|
||||
{
|
||||
$url = Url::fromPath('/my/test/url.html?param[]=%25val1¶m[]=%40val2', array(), new RequestMock());
|
||||
$url = Url::fromPath('/my/test/url.html?param[]=%25val1¶m[]=%40val2');
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'param' => array('%val1', '@val2')
|
||||
|
@ -86,11 +86,7 @@ class UrlTest extends BaseTestCase
|
|||
*/
|
||||
function testFromUrlWithAssociativeArrayInQuery()
|
||||
{
|
||||
$url = Url::fromPath(
|
||||
'/my/test/url.html?param[value]=%25val1¶m[value2]=%40val2',
|
||||
array(),
|
||||
new RequestMock()
|
||||
);
|
||||
$url = Url::fromPath('/my/test/url.html?param[value]=%25val1¶m[value2]=%40val2');
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'param' => array(
|
||||
|
@ -113,8 +109,7 @@ class UrlTest extends BaseTestCase
|
|||
array(
|
||||
'param1' => 'val1',
|
||||
'param2' => 'val2'
|
||||
),
|
||||
new RequestMock()
|
||||
)
|
||||
);
|
||||
$url->setBaseUrl('path/to');
|
||||
$this->assertEquals(
|
||||
|
@ -135,8 +130,7 @@ class UrlTest extends BaseTestCase
|
|||
array(
|
||||
'param1' => 'val1',
|
||||
'param2' => 'val2'
|
||||
),
|
||||
new RequestMock()
|
||||
)
|
||||
);
|
||||
$url->setBaseUrl('path/to');
|
||||
$this->assertEquals(
|
||||
|
@ -156,8 +150,7 @@ class UrlTest extends BaseTestCase
|
|||
array(
|
||||
'flatarray' => array('val1', 'val2'),
|
||||
'param' => array('value1'=>'val1', 'value2' => 'val2')
|
||||
),
|
||||
new RequestMock()
|
||||
)
|
||||
);
|
||||
$url->setBaseUrl('path/to');
|
||||
$this->assertEquals(
|
||||
|
@ -175,10 +168,11 @@ class UrlTest extends BaseTestCase
|
|||
*/
|
||||
function testUrlFromRequestWithoutQuery()
|
||||
{
|
||||
$request = new RequestMock();
|
||||
$request->baseUrl = 'path/to';
|
||||
$request->path = 'my/test/url.html';
|
||||
$request->query = array();
|
||||
$request = Mockery::mock('RequestWithoutQuery');
|
||||
$request->shouldReceive('getPathInfo')->andReturn('my/test/url.html')
|
||||
->shouldReceive('getBaseUrl')->andReturn('path/to')
|
||||
->shouldReceive('getQuery')->andReturn(array());
|
||||
|
||||
$url = Url::fromRequest(array(), $request);
|
||||
$this->assertEquals(
|
||||
'/path/to/my/test/url.html',
|
||||
|
@ -192,13 +186,15 @@ class UrlTest extends BaseTestCase
|
|||
*/
|
||||
function testUrlFromRequestWithQuery()
|
||||
{
|
||||
$request = new RequestMock();
|
||||
$request->baseUrl = 'path/to';
|
||||
$request->path = 'my/test/url.html';
|
||||
$request->query = array(
|
||||
'param1' => 'value1',
|
||||
'param2' => array('key1' => 'value1', 'key2' => 'value2')
|
||||
$request = Mockery::mock('RequestWithoutQuery');
|
||||
$request->shouldReceive('getPathInfo')->andReturn('my/test/url.html')
|
||||
->shouldReceive('getBaseUrl')->andReturn('path/to')
|
||||
->shouldReceive('getQuery')->andReturn(array(
|
||||
'param1' => 'value1',
|
||||
'param2' => array('key1' => 'value1', 'key2' => 'value2')
|
||||
)
|
||||
);
|
||||
|
||||
$url = Url::fromRequest(array(), $request);
|
||||
$this->assertEquals(
|
||||
'/path/to/my/test/url.html?param1=value1&'.
|
||||
|
@ -214,7 +210,7 @@ class UrlTest extends BaseTestCase
|
|||
*/
|
||||
function testGetParameterByName()
|
||||
{
|
||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2', array(), new RequestMock());
|
||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2');
|
||||
$this->assertEquals(
|
||||
"val",
|
||||
$url->getParam("param", "wrongval"),
|
||||
|
@ -237,7 +233,7 @@ class UrlTest extends BaseTestCase
|
|||
*/
|
||||
function testRemoveSingleParameter()
|
||||
{
|
||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2', array(), new RequestMock());
|
||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2');
|
||||
$url->remove("param");
|
||||
$this->assertEquals(
|
||||
"val2",
|
||||
|
@ -256,7 +252,7 @@ class UrlTest extends BaseTestCase
|
|||
*/
|
||||
function testRemoveMultipleParameters()
|
||||
{
|
||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2¶m3=val3', array(), new RequestMock());
|
||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2¶m3=val3');
|
||||
$url->remove(array("param", "param2"));
|
||||
$this->assertEquals(
|
||||
"val3",
|
||||
|
@ -280,7 +276,7 @@ class UrlTest extends BaseTestCase
|
|||
*/
|
||||
function testWithoutCall()
|
||||
{
|
||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2¶m3=val3', array(), new RequestMock());
|
||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2¶m3=val3');
|
||||
$url2 = $url->getUrlWithout(array("param"));
|
||||
$this->assertNotEquals(
|
||||
$url,
|
||||
|
@ -299,7 +295,7 @@ class UrlTest extends BaseTestCase
|
|||
|
||||
function testAddParamAfterCreation()
|
||||
{
|
||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2¶m3=val3', array(), new RequestMock());
|
||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2¶m3=val3');
|
||||
$url->addParams(array(
|
||||
"param4" => "val4",
|
||||
"param3" => "newval3"
|
||||
|
@ -321,7 +317,7 @@ class UrlTest extends BaseTestCase
|
|||
*/
|
||||
function testToString()
|
||||
{
|
||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2¶m3=val3', array(), new RequestMock());
|
||||
$url = Url::fromPath('/my/test/url.html?param=val¶m2=val2¶m3=val3');
|
||||
$this->assertEquals(
|
||||
$url->getAbsoluteUrl(),
|
||||
(string) $url,
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
namespace Tests\Icinga\Web\Widget;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Tests\Icinga\Web\RequestMock;
|
||||
use Tests\Icinga\Web\ViewMock;
|
||||
use Icinga\Web\Widget\Tab;
|
||||
use Icinga\Web\Url;
|
||||
|
@ -64,7 +63,7 @@ class TabTest extends BaseTestCase
|
|||
array(
|
||||
"name" => "tab",
|
||||
"title" => "Title text",
|
||||
"url" => Url::fromPath("my/url", array(), new RequestMock())
|
||||
"url" => Url::fromPath("my/url")
|
||||
)
|
||||
);
|
||||
$html = $tab->render(new ViewMock());
|
||||
|
@ -88,7 +87,7 @@ class TabTest extends BaseTestCase
|
|||
array(
|
||||
"name" => "tab",
|
||||
"title" => "Title text",
|
||||
"icon" => Url::fromPath("my/url", array(), new RequestMock())
|
||||
"icon" => Url::fromPath("my/url")
|
||||
)
|
||||
);
|
||||
$html = $tab->render(new ViewMock());
|
||||
|
|
Loading…
Reference in New Issue