mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 23:34:08 +02:00
parent
927772578d
commit
4c8428423e
@ -43,14 +43,6 @@ use Icinga\Application\Icinga;
|
|||||||
*/
|
*/
|
||||||
class Url
|
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
|
* An array of all parameters stored in this Url
|
||||||
*
|
*
|
||||||
@ -123,9 +115,6 @@ class Url
|
|||||||
*/
|
*/
|
||||||
private static function getRequest()
|
private static function getRequest()
|
||||||
{
|
{
|
||||||
if (self::$overwrittenRequest) {
|
|
||||||
return self::$overwrittenRequest;
|
|
||||||
}
|
|
||||||
return Icinga::app()->getFrontController()->getRequest();
|
return Icinga::app()->getFrontController()->getRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
namespace Tests\Icinga\Modules\Monitoring\Application\Views\Helpers;
|
namespace Tests\Icinga\Modules\Monitoring\Application\Views\Helpers;
|
||||||
|
|
||||||
use \stdClass;
|
use \Mockery;
|
||||||
use \Zend_View_Helper_ResolveMacros;
|
use \Zend_View_Helper_ResolveMacros;
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ class ResolveMacrosTest extends BaseTestCase
|
|||||||
{
|
{
|
||||||
public function testHostMacros()
|
public function testHostMacros()
|
||||||
{
|
{
|
||||||
$hostMock = new stdClass();
|
$hostMock = Mockery::mock('host');
|
||||||
$hostMock->host_name = 'test';
|
$hostMock->host_name = 'test';
|
||||||
$hostMock->host_address = '1.1.1.1';
|
$hostMock->host_address = '1.1.1.1';
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ class ResolveMacrosTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testServiceMacros()
|
public function testServiceMacros()
|
||||||
{
|
{
|
||||||
$svcMock = new stdClass();
|
$svcMock = Mockery::mock('service');
|
||||||
$svcMock->host_name = 'test';
|
$svcMock->host_name = 'test';
|
||||||
$svcMock->host_address = '1.1.1.1';
|
$svcMock->host_address = '1.1.1.1';
|
||||||
$svcMock->service_description = 'a service';
|
$svcMock->service_description = 'a service';
|
||||||
@ -40,7 +40,7 @@ class ResolveMacrosTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testCustomvars()
|
public function testCustomvars()
|
||||||
{
|
{
|
||||||
$objectMock = new stdClass();
|
$objectMock = Mockery::mock('object');
|
||||||
$objectMock->customvars = array(
|
$objectMock->customvars = array(
|
||||||
'CUSTOMVAR' => 'test'
|
'CUSTOMVAR' => 'test'
|
||||||
);
|
);
|
||||||
@ -51,7 +51,7 @@ class ResolveMacrosTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testFaultyMacros()
|
public function testFaultyMacros()
|
||||||
{
|
{
|
||||||
$hostMock = new stdClass();
|
$hostMock = Mockery::mock('host');
|
||||||
$hostMock->host_name = 'test';
|
$hostMock->host_name = 'test';
|
||||||
$hostMock->customvars = array(
|
$hostMock->customvars = array(
|
||||||
'HOST' => 'te',
|
'HOST' => 'te',
|
||||||
@ -67,7 +67,7 @@ class ResolveMacrosTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testMacrosWithSpecialCharacters()
|
public function testMacrosWithSpecialCharacters()
|
||||||
{
|
{
|
||||||
$objectMock = new stdClass();
|
$objectMock = Mockery::mock('object');
|
||||||
$objectMock->customvars = array(
|
$objectMock->customvars = array(
|
||||||
'V€RY_SP3C|@L' => 'not too special!'
|
'V€RY_SP3C|@L' => 'not too special!'
|
||||||
);
|
);
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
namespace Tests\Icinga\Module\Monitoring\Library\Filter;
|
namespace Tests\Icinga\Module\Monitoring\Library\Filter;
|
||||||
|
|
||||||
use Icinga\Filter\Filterable;
|
use \Mockery;
|
||||||
use Icinga\Module\Monitoring\Filter\Type\StatusFilter;
|
use Icinga\Module\Monitoring\Filter\Type\StatusFilter;
|
||||||
use Icinga\Filter\Query\Node;
|
use Icinga\Filter\Query\Node;
|
||||||
use Icinga\Filter\Filter;
|
use Icinga\Filter\Filter;
|
||||||
@ -13,36 +13,19 @@ use Icinga\Filter\FilterAttribute;
|
|||||||
use Icinga\Module\Monitoring\Filter\UrlViewFilter;
|
use Icinga\Module\Monitoring\Filter\UrlViewFilter;
|
||||||
use Icinga\Test\BaseTestCase;
|
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
|
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()
|
public function testUrlParamCreation()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped('Or queries are disabled');
|
$this->markTestSkipped('Or queries are disabled');
|
||||||
@ -71,7 +54,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||||||
. ' and attr5 is UP';
|
. ' and attr5 is UP';
|
||||||
|
|
||||||
$tree = $searchEngine->createQueryTreeForFilter($query);
|
$tree = $searchEngine->createQueryTreeForFilter($query);
|
||||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||||
$uri = $filterFactory->fromTree($tree);
|
$uri = $filterFactory->fromTree($tree);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'attr1!=Hans+wurst|attr2=%2Asomething%2A&attr3=bla%2A|attr4=1&host_last_state_change>=yesterday&attr5=0',
|
'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()
|
public function testTreeFromSimpleKeyValueUrlCreation()
|
||||||
{
|
{
|
||||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||||
$tree = $filterFactory->parseUrl('attr1!=Hans+Wurst');
|
$tree = $filterFactory->parseUrl('attr1!=Hans+Wurst');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$tree->root->type,
|
$tree->root->type,
|
||||||
@ -110,7 +93,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||||||
{
|
{
|
||||||
$this->markTestSkipped("OR queries are disabled");
|
$this->markTestSkipped("OR queries are disabled");
|
||||||
|
|
||||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||||
$query = 'attr1!=Hans+Wurst&test=test123|bla=1';
|
$query = 'attr1!=Hans+Wurst&test=test123|bla=1';
|
||||||
$tree = $filterFactory->parseUrl($query);
|
$tree = $filterFactory->parseUrl($query);
|
||||||
$this->assertEquals($tree->root->type, Node::TYPE_AND, 'Assert the root of the filter tree to be an AND node');
|
$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()
|
public function testImplicitConjunctionInUrl()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped("OR queries are disabled");
|
$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';
|
$query = 'attr1!=Hans+Wurst&test=test123|bla=1|2|3';
|
||||||
$tree = $filterFactory->parseUrl($query);
|
$tree = $filterFactory->parseUrl($query);
|
||||||
$this->assertEquals($tree->root->type, Node::TYPE_AND, 'Assert the root of the filter tree to be an AND node');
|
$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()
|
public function testMissingValuesInQueries()
|
||||||
{
|
{
|
||||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||||
$queryStr = 'attr1!=Hans+Wurst&test=';
|
$queryStr = 'attr1!=Hans+Wurst&test=';
|
||||||
$tree = $filterFactory->parseUrl($queryStr);
|
$tree = $filterFactory->parseUrl($queryStr);
|
||||||
$query = $filterFactory->fromTree($tree);
|
$query = $filterFactory->fromTree($tree);
|
||||||
@ -142,7 +125,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testErrorInQueries()
|
public function testErrorInQueries()
|
||||||
{
|
{
|
||||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||||
$queryStr = 'test=&attr1!=Hans+Wurst';
|
$queryStr = 'test=&attr1!=Hans+Wurst';
|
||||||
$tree = $filterFactory->parseUrl($queryStr);
|
$tree = $filterFactory->parseUrl($queryStr);
|
||||||
$query = $filterFactory->fromTree($tree);
|
$query = $filterFactory->fromTree($tree);
|
||||||
@ -151,7 +134,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testSenselessConjunctions()
|
public function testSenselessConjunctions()
|
||||||
{
|
{
|
||||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||||
$queryStr = 'test=&|/5/|&attr1!=Hans+Wurst';
|
$queryStr = 'test=&|/5/|&attr1!=Hans+Wurst';
|
||||||
$tree = $filterFactory->parseUrl($queryStr);
|
$tree = $filterFactory->parseUrl($queryStr);
|
||||||
$query = $filterFactory->fromTree($tree);
|
$query = $filterFactory->fromTree($tree);
|
||||||
@ -161,7 +144,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||||||
public function testRandomString()
|
public function testRandomString()
|
||||||
{
|
{
|
||||||
$filter = '';
|
$filter = '';
|
||||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||||
|
|
||||||
for ($i=0; $i<10;$i++) {
|
for ($i=0; $i<10;$i++) {
|
||||||
$filter .= str_shuffle('&|ds& wra =!<>|dsgs=,-G');
|
$filter .= str_shuffle('&|ds& wra =!<>|dsgs=,-G');
|
||||||
|
@ -4,16 +4,22 @@
|
|||||||
|
|
||||||
namespace Tests\Icinga\Form\Config;
|
namespace Tests\Icinga\Form\Config;
|
||||||
|
|
||||||
|
use \Mockery;
|
||||||
use \Zend_Config;
|
use \Zend_Config;
|
||||||
use Icinga\Web\Url;
|
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
use Tests\Icinga\Web\RequestMock;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for the authentication provider form
|
* Test for the authentication provider form
|
||||||
*/
|
*/
|
||||||
class AuthenticationFormTest extends BaseTestCase
|
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
|
* Test the ldap provider form population from config
|
||||||
*/
|
*/
|
||||||
@ -87,16 +93,13 @@ class AuthenticationFormTest extends BaseTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether order modifications via 'priority' are considered
|
* Test whether order modifications via 'priority' are considered
|
||||||
*
|
|
||||||
* @backupStaticAttributes enabled
|
|
||||||
*/
|
*/
|
||||||
public function testModifyOrder()
|
public function testModifyOrder()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped('ReorderForm is broken');
|
|
||||||
Url::$overwrittenRequest = new RequestMock();
|
|
||||||
$form = $this->createForm('Icinga\Form\Config\Authentication\ReorderForm');
|
$form = $this->createForm('Icinga\Form\Config\Authentication\ReorderForm');
|
||||||
$form->setAuthenticationBackend('backend2');
|
$form->setAuthenticationBackend('backend2');
|
||||||
$form->setCurrentOrder(array('backend1', 'backend2', 'backend3', 'backend4'));
|
$form->setCurrentOrder(array('backend1', 'backend2', 'backend3', 'backend4'));
|
||||||
|
$form->setView($this->viewMock);
|
||||||
|
|
||||||
$form->create();
|
$form->create();
|
||||||
$this->assertSame(
|
$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
|
* Test whether the reorder form doesn't display senseless ordering (like moving the uppermost element up or
|
||||||
* the lowermose down)
|
* the lowermost down)
|
||||||
*
|
|
||||||
* @backupStaticAttributes enabled
|
|
||||||
*/
|
*/
|
||||||
public function testInvalidOrderingNotShown()
|
public function testInvalidOrderingNotShown()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped('ReorderForm is broken');
|
|
||||||
Url::$overwrittenRequest = new RequestMock();
|
|
||||||
$form = $this->createForm('Icinga\Form\Config\Authentication\ReorderForm');
|
$form = $this->createForm('Icinga\Form\Config\Authentication\ReorderForm');
|
||||||
$form->setAuthenticationBackend('backend1');
|
$form->setAuthenticationBackend('backend1');
|
||||||
$form->setCurrentOrder(array('backend1', 'backend2', 'backend3', 'backend4'));
|
$form->setCurrentOrder(array('backend1', 'backend2', 'backend3', 'backend4'));
|
||||||
|
$form->setView($this->viewMock);
|
||||||
|
|
||||||
$form->create();
|
$form->create();
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
|
@ -8,16 +8,22 @@ namespace Tests\Icinga\Form\Config;
|
|||||||
require_once realpath(ICINGA_APPDIR . '/views/helpers/DateFormat.php');
|
require_once realpath(ICINGA_APPDIR . '/views/helpers/DateFormat.php');
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
|
||||||
use \DateTimeZone;
|
use \Mockery;
|
||||||
use \DOMDocument;
|
use \DOMDocument;
|
||||||
use \Zend_Config;
|
use \Zend_Config;
|
||||||
use \Zend_View;
|
use \Zend_View;
|
||||||
use \Zend_View_Helper_DateFormat;
|
use \Zend_View_Helper_DateFormat;
|
||||||
use Icinga\Util\DateTimeFactory;
|
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
|
|
||||||
class GeneralFormTest extends 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)
|
private function isHiddenElement($value, $htmlString)
|
||||||
{
|
{
|
||||||
$html = new DOMDocument();
|
$html = new DOMDocument();
|
||||||
@ -36,13 +42,9 @@ class GeneralFormTest extends BaseTestCase
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function testCorrectFieldPopulation()
|
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 = $this->createForm('Icinga\Form\Config\GeneralForm');
|
||||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||||
$form->setConfiguration(
|
$form->setConfiguration(
|
||||||
@ -72,8 +74,10 @@ class GeneralFormTest extends BaseTestCase
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
$form->setConfigDir('/tmp');
|
$form->setConfigDir('/tmp');
|
||||||
|
$form->setView($this->viewMock);
|
||||||
|
|
||||||
$form->create();
|
$form->create();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
1,
|
1,
|
||||||
$form->getValue('environment'),
|
$form->getValue('environment'),
|
||||||
@ -118,8 +122,6 @@ class GeneralFormTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testCorrectConditionalIniFieldRendering()
|
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 = $this->createForm('Icinga\Form\Config\GeneralForm');
|
||||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||||
$form->setConfiguration(
|
$form->setConfiguration(
|
||||||
@ -140,8 +142,9 @@ class GeneralFormTest extends BaseTestCase
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$form->create();
|
$form->setView($this->viewMock);
|
||||||
|
|
||||||
|
$form->create();
|
||||||
$view = new Zend_View();
|
$view = new Zend_View();
|
||||||
|
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
@ -156,8 +159,6 @@ class GeneralFormTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testCorrectConditionalDbFieldRendering()
|
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 = $this->createForm('Icinga\Form\Config\GeneralForm');
|
||||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||||
$form->setConfiguration(
|
$form->setConfiguration(
|
||||||
@ -179,6 +180,8 @@ class GeneralFormTest extends BaseTestCase
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$form->setView($this->viewMock);
|
||||||
|
|
||||||
$form->create();
|
$form->create();
|
||||||
$view = new Zend_View();
|
$view = new Zend_View();
|
||||||
|
|
||||||
|
@ -8,11 +8,9 @@ namespace Tests\Icinga\Form\Preference;
|
|||||||
require_once realpath(ICINGA_APPDIR . '/views/helpers/DateFormat.php');
|
require_once realpath(ICINGA_APPDIR . '/views/helpers/DateFormat.php');
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
|
||||||
use \DateTimeZone;
|
|
||||||
use \Zend_View_Helper_DateFormat;
|
use \Zend_View_Helper_DateFormat;
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
use Icinga\User\Preferences;
|
use Icinga\User\Preferences;
|
||||||
use Icinga\Util\DateTimeFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for general form, mainly testing enable/disable behaviour
|
* Test for general form, mainly testing enable/disable behaviour
|
||||||
@ -24,7 +22,6 @@ class GeneralFormTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
public function testDisableFormIfUsingDefault()
|
public function testDisableFormIfUsingDefault()
|
||||||
{
|
{
|
||||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
|
||||||
$form = $this->createForm('Icinga\Form\Preference\GeneralForm');
|
$form = $this->createForm('Icinga\Form\Preference\GeneralForm');
|
||||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||||
$form->setRequest($this->getRequest());
|
$form->setRequest($this->getRequest());
|
||||||
@ -41,7 +38,6 @@ class GeneralFormTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
public function testEnableFormIfUsingPreference()
|
public function testEnableFormIfUsingPreference()
|
||||||
{
|
{
|
||||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
|
||||||
$form = $this->createForm('Icinga\Form\Preference\GeneralForm');
|
$form = $this->createForm('Icinga\Form\Preference\GeneralForm');
|
||||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||||
$form->setRequest($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;
|
namespace Tests\Icinga\Authentication;
|
||||||
|
|
||||||
use \PDO;
|
use \PDO;
|
||||||
use \Zend_Config;
|
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
use Icinga\Data\Db\Connection;
|
use Icinga\Data\Db\Connection;
|
||||||
use Icinga\Authentication\Backend\DbUserBackend;
|
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.
|
* 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) {
|
foreach ($this->baseOu as $ou => $info) {
|
||||||
if (ldap_add($connection, $ou, $info) === false) {
|
if (ldap_add($connection, $ou, $info) === false) {
|
||||||
|
@ -4,42 +4,30 @@
|
|||||||
|
|
||||||
namespace Tests\Icinga\Filter;
|
namespace Tests\Icinga\Filter;
|
||||||
|
|
||||||
|
use \Mockery;
|
||||||
use Icinga\Filter\Query\Node;
|
use Icinga\Filter\Query\Node;
|
||||||
use Icinga\Filter\FilterAttribute;
|
use Icinga\Filter\FilterAttribute;
|
||||||
use Icinga\Filter\Type\FilterType;
|
|
||||||
use Icinga\Test\BaseTestCase;
|
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
|
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()
|
public function testQueryHandlerSetup()
|
||||||
{
|
{
|
||||||
$handler = new FilterAttribute(new TypeMock());
|
$handler = new FilterAttribute($this->typeMock);
|
||||||
$handler->setField('current_status');
|
$handler->setField('current_status');
|
||||||
$handler->setHandledAttributes('State', 'Status', 'Current State');
|
$handler->setHandledAttributes('State', 'Status', 'Current State');
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
@ -58,7 +46,7 @@ class QueryHandlerTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testQueryProposal()
|
public function testQueryProposal()
|
||||||
{
|
{
|
||||||
$handler = new FilterAttribute(new TypeMock());
|
$handler = new FilterAttribute($this->typeMock);
|
||||||
|
|
||||||
$handler->setField('current_status');
|
$handler->setField('current_status');
|
||||||
$handler->setHandledAttributes('Status', 'State', 'Current State');
|
$handler->setHandledAttributes('Status', 'State', 'Current State');
|
||||||
@ -84,7 +72,7 @@ class QueryHandlerTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testOperatorProposal()
|
public function testOperatorProposal()
|
||||||
{
|
{
|
||||||
$handler = new FilterAttribute(new TypeMock());
|
$handler = new FilterAttribute($this->typeMock);
|
||||||
$handler->setField('current_status')
|
$handler->setField('current_status')
|
||||||
->setHandledAttributes('status', 'state', 'current state');
|
->setHandledAttributes('status', 'state', 'current state');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -96,7 +84,7 @@ class QueryHandlerTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testAttributeRecognition()
|
public function testAttributeRecognition()
|
||||||
{
|
{
|
||||||
$handler = new FilterAttribute(new TypeMock());
|
$handler = new FilterAttribute($this->typeMock);
|
||||||
$handler->setField('current_status')
|
$handler->setField('current_status')
|
||||||
->setHandledAttributes('status', 'state', 'current state');
|
->setHandledAttributes('status', 'state', 'current state');
|
||||||
$node = $handler->convertToTreeNode('status is not \’some kind of magic\'');
|
$node = $handler->convertToTreeNode('status is not \’some kind of magic\'');
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
namespace Tests\Icinga\Protocol\Statusdat;
|
namespace Tests\Icinga\Protocol\Statusdat\Component;
|
||||||
|
|
||||||
use \Zend_Config;
|
use \Zend_Config;
|
||||||
use Icinga\Test\BaseTestCase;
|
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;
|
namespace Tests\Icinga\Web\Hook\Configuration;
|
||||||
|
|
||||||
|
use \Mockery;
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
use Icinga\Web\Hook\Configuration\ConfigurationTab;
|
use Icinga\Web\Hook\Configuration\ConfigurationTab;
|
||||||
use Icinga\Web\Hook\Configuration\ConfigurationTabBuilder;
|
use Icinga\Web\Hook\Configuration\ConfigurationTabBuilder;
|
||||||
use Icinga\Web\Hook;
|
use Icinga\Web\Hook;
|
||||||
use Icinga\Web\Url;
|
|
||||||
use Icinga\Web\Widget\Tabs;
|
use Icinga\Web\Widget\Tabs;
|
||||||
|
|
||||||
class RequestMock
|
|
||||||
{
|
|
||||||
public function getBaseUrl()
|
|
||||||
{
|
|
||||||
return "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class ConfigurationTabBuilderTest extends BaseTestCase
|
class ConfigurationTabBuilderTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
protected function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
Hook::clean();
|
Hook::clean();
|
||||||
Url::$overwrittenRequest = new RequestMock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
Hook::clean();
|
Hook::clean();
|
||||||
Url::$overwrittenRequest = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultTabs()
|
public function testDefaultTabs()
|
||||||
@ -74,7 +63,7 @@ class ConfigurationTabBuilderTest extends BaseTestCase
|
|||||||
$widget = new Tabs();
|
$widget = new Tabs();
|
||||||
$builder = new ConfigurationTabBuilder($widget);
|
$builder = new ConfigurationTabBuilder($widget);
|
||||||
|
|
||||||
$tab = new \stdClass();
|
$tab = Mockery::mock('Tab');
|
||||||
Hook::registerObject(ConfigurationTabBuilder::HOOK_NAMESPACE, 'misc', $tab);
|
Hook::registerObject(ConfigurationTabBuilder::HOOK_NAMESPACE, 'misc', $tab);
|
||||||
$builder->build();
|
$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;
|
namespace Tests\Icinga\Web;
|
||||||
|
|
||||||
|
use \Mockery;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
use Tests\Icinga\Web\RequestMock;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the Icinga\Web\Url class that provides convenient access to Url manipulation method
|
* 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()
|
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(
|
$this->assertEquals(
|
||||||
'/my/test/url.html',
|
'/my/test/url.html',
|
||||||
$url->getPath(),
|
$url->getPath(),
|
||||||
@ -36,7 +36,7 @@ class UrlTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
function testFromUrlWithBasePath()
|
function testFromUrlWithBasePath()
|
||||||
{
|
{
|
||||||
$url = Url::fromPath('my/test/url.html', array(), new RequestMock());
|
$url = Url::fromPath('my/test/url.html');
|
||||||
$url->setBaseUrl('the/path/to');
|
$url->setBaseUrl('the/path/to');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'/the/path/to/my/test/url.html',
|
'/the/path/to/my/test/url.html',
|
||||||
@ -50,7 +50,7 @@ class UrlTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
function testFromUrlWithKeyValueQuery()
|
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(
|
$this->assertEquals(
|
||||||
'/my/test/url.html',
|
'/my/test/url.html',
|
||||||
$url->getPath(),
|
$url->getPath(),
|
||||||
@ -71,7 +71,7 @@ class UrlTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
function testFromUrlWithArrayInQuery()
|
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(
|
$this->assertEquals(
|
||||||
array(
|
array(
|
||||||
'param' => array('%val1', '@val2')
|
'param' => array('%val1', '@val2')
|
||||||
@ -86,11 +86,7 @@ class UrlTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
function testFromUrlWithAssociativeArrayInQuery()
|
function testFromUrlWithAssociativeArrayInQuery()
|
||||||
{
|
{
|
||||||
$url = Url::fromPath(
|
$url = Url::fromPath('/my/test/url.html?param[value]=%25val1¶m[value2]=%40val2');
|
||||||
'/my/test/url.html?param[value]=%25val1¶m[value2]=%40val2',
|
|
||||||
array(),
|
|
||||||
new RequestMock()
|
|
||||||
);
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
array(
|
||||||
'param' => array(
|
'param' => array(
|
||||||
@ -113,8 +109,7 @@ class UrlTest extends BaseTestCase
|
|||||||
array(
|
array(
|
||||||
'param1' => 'val1',
|
'param1' => 'val1',
|
||||||
'param2' => 'val2'
|
'param2' => 'val2'
|
||||||
),
|
)
|
||||||
new RequestMock()
|
|
||||||
);
|
);
|
||||||
$url->setBaseUrl('path/to');
|
$url->setBaseUrl('path/to');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -135,8 +130,7 @@ class UrlTest extends BaseTestCase
|
|||||||
array(
|
array(
|
||||||
'param1' => 'val1',
|
'param1' => 'val1',
|
||||||
'param2' => 'val2'
|
'param2' => 'val2'
|
||||||
),
|
)
|
||||||
new RequestMock()
|
|
||||||
);
|
);
|
||||||
$url->setBaseUrl('path/to');
|
$url->setBaseUrl('path/to');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -156,8 +150,7 @@ class UrlTest extends BaseTestCase
|
|||||||
array(
|
array(
|
||||||
'flatarray' => array('val1', 'val2'),
|
'flatarray' => array('val1', 'val2'),
|
||||||
'param' => array('value1'=>'val1', 'value2' => 'val2')
|
'param' => array('value1'=>'val1', 'value2' => 'val2')
|
||||||
),
|
)
|
||||||
new RequestMock()
|
|
||||||
);
|
);
|
||||||
$url->setBaseUrl('path/to');
|
$url->setBaseUrl('path/to');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -175,10 +168,11 @@ class UrlTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
function testUrlFromRequestWithoutQuery()
|
function testUrlFromRequestWithoutQuery()
|
||||||
{
|
{
|
||||||
$request = new RequestMock();
|
$request = Mockery::mock('RequestWithoutQuery');
|
||||||
$request->baseUrl = 'path/to';
|
$request->shouldReceive('getPathInfo')->andReturn('my/test/url.html')
|
||||||
$request->path = 'my/test/url.html';
|
->shouldReceive('getBaseUrl')->andReturn('path/to')
|
||||||
$request->query = array();
|
->shouldReceive('getQuery')->andReturn(array());
|
||||||
|
|
||||||
$url = Url::fromRequest(array(), $request);
|
$url = Url::fromRequest(array(), $request);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'/path/to/my/test/url.html',
|
'/path/to/my/test/url.html',
|
||||||
@ -192,13 +186,15 @@ class UrlTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
function testUrlFromRequestWithQuery()
|
function testUrlFromRequestWithQuery()
|
||||||
{
|
{
|
||||||
$request = new RequestMock();
|
$request = Mockery::mock('RequestWithoutQuery');
|
||||||
$request->baseUrl = 'path/to';
|
$request->shouldReceive('getPathInfo')->andReturn('my/test/url.html')
|
||||||
$request->path = 'my/test/url.html';
|
->shouldReceive('getBaseUrl')->andReturn('path/to')
|
||||||
$request->query = array(
|
->shouldReceive('getQuery')->andReturn(array(
|
||||||
'param1' => 'value1',
|
'param1' => 'value1',
|
||||||
'param2' => array('key1' => 'value1', 'key2' => 'value2')
|
'param2' => array('key1' => 'value1', 'key2' => 'value2')
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$url = Url::fromRequest(array(), $request);
|
$url = Url::fromRequest(array(), $request);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'/path/to/my/test/url.html?param1=value1&'.
|
'/path/to/my/test/url.html?param1=value1&'.
|
||||||
@ -214,7 +210,7 @@ class UrlTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
function testGetParameterByName()
|
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(
|
$this->assertEquals(
|
||||||
"val",
|
"val",
|
||||||
$url->getParam("param", "wrongval"),
|
$url->getParam("param", "wrongval"),
|
||||||
@ -237,7 +233,7 @@ class UrlTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
function testRemoveSingleParameter()
|
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");
|
$url->remove("param");
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
"val2",
|
"val2",
|
||||||
@ -256,7 +252,7 @@ class UrlTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
function testRemoveMultipleParameters()
|
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"));
|
$url->remove(array("param", "param2"));
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
"val3",
|
"val3",
|
||||||
@ -280,7 +276,7 @@ class UrlTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
function testWithoutCall()
|
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"));
|
$url2 = $url->getUrlWithout(array("param"));
|
||||||
$this->assertNotEquals(
|
$this->assertNotEquals(
|
||||||
$url,
|
$url,
|
||||||
@ -299,7 +295,7 @@ class UrlTest extends BaseTestCase
|
|||||||
|
|
||||||
function testAddParamAfterCreation()
|
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(
|
$url->addParams(array(
|
||||||
"param4" => "val4",
|
"param4" => "val4",
|
||||||
"param3" => "newval3"
|
"param3" => "newval3"
|
||||||
@ -321,7 +317,7 @@ class UrlTest extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
function testToString()
|
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(
|
$this->assertEquals(
|
||||||
$url->getAbsoluteUrl(),
|
$url->getAbsoluteUrl(),
|
||||||
(string) $url,
|
(string) $url,
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
namespace Tests\Icinga\Web\Widget;
|
namespace Tests\Icinga\Web\Widget;
|
||||||
|
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
use Tests\Icinga\Web\RequestMock;
|
|
||||||
use Tests\Icinga\Web\ViewMock;
|
use Tests\Icinga\Web\ViewMock;
|
||||||
use Icinga\Web\Widget\Tab;
|
use Icinga\Web\Widget\Tab;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
@ -64,7 +63,7 @@ class TabTest extends BaseTestCase
|
|||||||
array(
|
array(
|
||||||
"name" => "tab",
|
"name" => "tab",
|
||||||
"title" => "Title text",
|
"title" => "Title text",
|
||||||
"url" => Url::fromPath("my/url", array(), new RequestMock())
|
"url" => Url::fromPath("my/url")
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$html = $tab->render(new ViewMock());
|
$html = $tab->render(new ViewMock());
|
||||||
@ -88,7 +87,7 @@ class TabTest extends BaseTestCase
|
|||||||
array(
|
array(
|
||||||
"name" => "tab",
|
"name" => "tab",
|
||||||
"title" => "Title text",
|
"title" => "Title text",
|
||||||
"icon" => Url::fromPath("my/url", array(), new RequestMock())
|
"icon" => Url::fromPath("my/url")
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$html = $tab->render(new ViewMock());
|
$html = $tab->render(new ViewMock());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user