diff --git a/library/Businessprocess/Test/BaseTestCase.php b/library/Businessprocess/Test/BaseTestCase.php index 0a74885..8673cda 100644 --- a/library/Businessprocess/Test/BaseTestCase.php +++ b/library/Businessprocess/Test/BaseTestCase.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Businessprocess\Test; use Icinga\Application\Config; use Icinga\Application\ApplicationBootstrap; use Icinga\Application\Icinga; +use Icinga\Module\Businessprocess\Web\FakeRequest; use PHPUnit_Framework_TestCase; abstract class BaseTestCase extends PHPUnit_Framework_TestCase @@ -18,6 +19,7 @@ abstract class BaseTestCase extends PHPUnit_Framework_TestCase public function setUp() { $this->app(); + FakeRequest::setConfiguredBaseUrl('/icingaweb2/'); } protected function emptyConfigSection() diff --git a/library/Businessprocess/Web/Component/Component.php b/library/Businessprocess/Web/Component/Component.php index 3830e06..eaec881 100644 --- a/library/Businessprocess/Web/Component/Component.php +++ b/library/Businessprocess/Web/Component/Component.php @@ -42,12 +42,17 @@ abstract class Component protected function discoveredView() { if (self::$discoveredView === null) { - $viewRenderer = Icinga::app()->getViewRenderer(); - if ($viewRenderer->view === null) { - $viewRenderer->initView(); - } + $icinga = Icinga::app(); + if ($icinga->isCli()) { + self::$discoveredView = new View(); + } else { + $viewRenderer = $icinga->getViewRenderer(); + if ($viewRenderer->view === null) { + $viewRenderer->initView(); + } - self::$discoveredView = $viewRenderer->view; + self::$discoveredView = $viewRenderer->view; + } } return self::$discoveredView; diff --git a/library/Businessprocess/Web/Component/Link.php b/library/Businessprocess/Web/Component/Link.php index 525694c..5f82b59 100644 --- a/library/Businessprocess/Web/Component/Link.php +++ b/library/Businessprocess/Web/Component/Link.php @@ -2,7 +2,7 @@ namespace Icinga\Module\Businessprocess\Web\Component; -use Icinga\Web\Url; +use Icinga\Module\Businessprocess\Web\Url; class Link extends Component { diff --git a/library/Businessprocess/Web/FakeRequest.php b/library/Businessprocess/Web/FakeRequest.php new file mode 100644 index 0000000..6735e81 --- /dev/null +++ b/library/Businessprocess/Web/FakeRequest.php @@ -0,0 +1,26 @@ +setPath($url); + } + + $parts = parse_url($url); + + $self->setBasePath($request->getBaseUrl()); + if (isset($parts['path'])) { + $self->setPath($parts['path']); + } + + if (isset($parts['fragment'])) { + $self->setAnchor($parts['fragment']); + } + + $self->setParams($params); + return $self; + } + + protected static function getRequest() + { + $app = Icinga::app(); + if ($app->isCli()) { + return new FakeRequest(); + } else { + return $app->getRequest(); + } + } + +} \ No newline at end of file