Merge branch 'feature/integrate-ipl-html'

resolves #130
This commit is contained in:
Johannes Meyer 2019-01-17 14:15:27 +01:00
commit 788f690154
45 changed files with 470 additions and 2001 deletions

View file

@ -21,6 +21,7 @@ cache:
env:
- ICINGAWEB_VERSION=2.5.1
- IPL_VERSION=0.1.1
before_script:
- ./test/setup_vendor.sh

View file

@ -53,7 +53,7 @@ class NodeController extends Controller
)->setPath($path);
$bc = Breadcrumb::create($renderer);
$bc->attributes()->set('data-base-target', '_next');
$bc->getAttributes()->set('data-base-target', '_next');
$content->add($bc);
}
}

View file

@ -5,11 +5,6 @@ namespace Icinga\Module\Businessprocess\Controllers;
use Icinga\Date\DateFormatter;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\BpNode;
use Icinga\Module\Businessprocess\Html\Element;
use Icinga\Module\Businessprocess\Html\HtmlString;
use Icinga\Module\Businessprocess\Html\HtmlTag;
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Node;
use Icinga\Module\Businessprocess\Renderer\Breadcrumb;
use Icinga\Module\Businessprocess\Renderer\Renderer;
@ -23,11 +18,13 @@ use Icinga\Module\Businessprocess\Web\Component\ActionBar;
use Icinga\Module\Businessprocess\Web\Component\RenderedProcessActionBar;
use Icinga\Module\Businessprocess\Web\Component\Tabs;
use Icinga\Module\Businessprocess\Web\Controller;
use Icinga\Module\Businessprocess\Web\Url;
use Icinga\Util\Json;
use Icinga\Web\Notification;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\OutputFormat;
use ipl\Html\Html;
use ipl\Html\HtmlString;
class ProcessController extends Controller
{
@ -45,7 +42,7 @@ class ProcessController extends Controller
$this->setTitle($title);
$this->controls()
->add($this->tabsForCreate()->activate('create'))
->add(HtmlTag::h1($title));
->add(Html::tag('h1', null, $title));
$this->content()->add(
$this->loadForm('bpConfig')
@ -66,7 +63,7 @@ class ProcessController extends Controller
$this->setTitle($title);
$this->controls()
->add($this->tabsForCreate()->activate('upload'))
->add(HtmlTag::h1($title));
->add(Html::tag('h1', null, $title));
$this->content()->add(
$this->loadForm('BpUpload')
@ -113,9 +110,9 @@ class ProcessController extends Controller
}
$bp->addError(sprintf('There are %d missing nodes: %s', $count, implode(', ', $missing)));
}
$this->content()->addContent($this->showHints($bp));
$this->content()->addContent($this->showWarnings($bp));
$this->content()->addContent($this->showErrors($bp));
$this->content()->add($this->showHints($bp));
$this->content()->add($this->showWarnings($bp));
$this->content()->add($this->showErrors($bp));
$this->content()->add($renderer);
$this->loadActionForm($bp, $node);
$this->setDynamicAutorefresh();
@ -126,27 +123,23 @@ class ProcessController extends Controller
$controls = $this->controls();
if ($this->showFullscreen) {
$controls->attributes()->add('class', 'want-fullscreen');
$controls->add(
Link::create(
Icon::create('resize-small'),
$this->url()->without('showFullscreen')->without('view'),
null,
array(
'style' => 'float: right',
'title' => $this->translate(
'Leave full screen and switch back to normal mode'
)
)
)
);
$controls->getAttributes()->add('class', 'want-fullscreen');
$controls->add(Html::tag(
'a',
[
'href' => $this->url()->without('showFullscreen')->without('view'),
'title' => $this->translate('Leave full screen and switch back to normal mode'),
'style' => 'float: right'
],
Html::tag('i', ['class' => 'icon icon-resize-small'])
));
}
if (! ($this->showFullscreen || $this->view->compact)) {
$controls->add($this->getProcessTabs($bp, $renderer));
}
if (! $this->view->compact) {
$controls->add(Element::create('h1')->setContent($this->view->title));
$controls->add(Html::tag('h1')->setContent($this->view->title));
}
$controls->add(Breadcrumb::create($renderer));
if (! $this->showFullscreen && ! $this->view->compact) {
@ -259,7 +252,7 @@ class ProcessController extends Controller
}
if ($form) {
$this->content()->prependContent(HtmlString::create((string) $form));
$this->content()->prepend(HtmlString::create((string) $form));
}
}
@ -283,9 +276,9 @@ class ProcessController extends Controller
protected function showWarnings(BpConfig $bp)
{
if ($bp->hasWarnings()) {
$ul = Element::create('ul', array('class' => 'warning'));
$ul = Html::tag('ul', array('class' => 'warning'));
foreach ($bp->getWarnings() as $warning) {
$ul->createElement('li')->addContent($warning);
$ul->add(Html::tag('li')->setContent($warning));
}
return $ul;
@ -297,9 +290,9 @@ class ProcessController extends Controller
protected function showErrors(BpConfig $bp)
{
if ($bp->hasWarnings()) {
$ul = Element::create('ul', array('class' => 'error'));
$ul = Html::tag('ul', array('class' => 'error'));
foreach ($bp->getErrors() as $msg) {
$ul->createElement('li')->addContent($msg);
$ul->add(Html::tag('li')->setContent($msg));
}
return $ul;
@ -310,40 +303,41 @@ class ProcessController extends Controller
protected function showHints(BpConfig $bp)
{
$ul = Element::create('ul', array('class' => 'error'));
$ul = Html::tag('ul', ['class' => 'error']);
foreach ($bp->getErrors() as $error) {
$ul->createElement('li')->addContent($error);
$ul->add(Html::tag('li')->setContent($error));
}
if ($bp->hasChanges()) {
$ul->createElement('li')->setSeparator(' ')->addContent(sprintf(
$li = Html::tag('li')->setSeparator(' ');
$li->add(sprintf(
$this->translate('This process has %d pending change(s).'),
$bp->countChanges()
))->addContent(
Link::create(
$this->translate('Store'),
'businessprocess/process/config',
array('config' => $bp->getName())
)
)->addContent(
Link::create(
$this->translate('Dismiss'),
$this->url()->with('dismissChanges', true),
null
)
);
))->add(Html::tag(
'a',
['href' => Url::fromPath('businessprocess/process/config', ['config' => $bp->getName()])],
$this->translate('Store')
))->add(Html::tag(
'a',
['href' => $this->url()->with('dismissChanges', true)],
$this->translate('Dismiss')
));
$ul->add($li);
}
if ($bp->hasSimulations()) {
$ul->createElement('li')->setSeparator(' ')->addContent(sprintf(
$li = Html::tag('li')->setSeparator(' ');
$li->add(sprintf(
$this->translate('This process shows %d simulated state(s).'),
$bp->countSimulations()
))->addContent(Link::create(
$this->translate('Dismiss'),
$this->url()->with('dismissSimulations', true)
))->add(Html::tag(
'a',
['href' => $this->url()->with('dismissSimulations', true)],
$this->translate('Dismiss')
));
$ul->add($li);
}
if ($ul->hasContent()) {
if (! $ul->isEmpty()) {
return $ul;
} else {
return null;
@ -380,7 +374,7 @@ class ProcessController extends Controller
$this->setTitle($title);
$this->controls()
->add($this->tabsForConfig($bp)->activate('source'))
->add(HtmlTag::h1($title))
->add(Html::tag('h1', null, $title))
->add($this->createConfigActionBar($bp, $showDiff));
$this->setViewScript('process/source');
@ -424,7 +418,7 @@ class ProcessController extends Controller
$this->setTitle($title);
$this->controls()
->add($this->tabsForConfig($bp)->activate('config'))
->add(HtmlTag::h1($title))
->add(Html::tag('h1', null, $title))
->add($this->createConfigActionBar($bp));
$url = Url::fromPath(
@ -446,48 +440,42 @@ class ProcessController extends Controller
if ($showDiff) {
$params = array('config' => $config->getName());
$actionBar->add(
Link::create(
$this->translate('Source'),
'businessprocess/process/source',
$params,
array(
'class' => 'icon-doc-text',
'title' => $this->translate('Show source code'),
)
)
);
$actionBar->add(Html::tag(
'a',
[
'href' => Url::fromPath('businessprocess/process/source', $params),
'class' => 'icon-doc-text',
'title' => $this->translate('Show source code')
],
$this->translate('Source')
));
} else {
$params = array(
'config' => $config->getName(),
'showDiff' => true
);
$actionBar->add(
Link::create(
$this->translate('Diff'),
'businessprocess/process/source',
$params,
array(
'class' => 'icon-flapping',
'title' => $this->translate('Highlight changes'),
)
)
);
$actionBar->add(Html::tag(
'a',
[
'href' => Url::fromPath('businessprocess/process/source', $params),
'class' => 'icon-flapping',
'title' => $this->translate('Highlight changes')
],
$this->translate('Diff')
));
}
$actionBar->add(
Link::create(
$this->translate('Download'),
'businessprocess/process/download',
array('config' => $config->getName()),
array(
'target' => '_blank',
'class' => 'icon-download',
'title' => $this->translate('Download process configuration')
)
)
);
$actionBar->add(Html::tag(
'a',
[
'href' => Url::fromPath('businessprocess/process/download', ['config' => $config->getName()]),
'class' => 'icon-download',
'target' => '_blank',
'title' => $this->translate('Download process configuration')
],
$this->translate('Download')
));
return $actionBar;
}

View file

@ -2,8 +2,8 @@
namespace Icinga\Module\Businessprocess;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Web\Url;
use ipl\Html\Html;
class HostNode extends MonitoredNode
{
@ -69,6 +69,6 @@ class HostNode extends MonitoredNode
public function getLink()
{
return Link::create($this->hostname, $this->getUrl());
return Html::tag('a', ['href' => $this->getUrl()], $this->hostname);
}
}

View file

@ -1,130 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
class Attribute
{
/** @var string */
protected $name;
/** @var string|array */
protected $value;
/**
* Attribute constructor.
*
* @param $name
* @param $value
*/
public function __construct($name, $value)
{
$this->name = $name;
$this->value = $value;
}
/**
* @param $name
* @param $value
* @return static
*/
public static function create($name, $value)
{
return new static($name, $value);
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* @param string|array $value
* @return $this
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* @param string $value
* @return $this
*/
public function addValue($value)
{
if (! is_array($this->value)) {
$this->value = array($this->value);
}
if (is_array($value)) {
$this->value = array_merge($this->value, $value);
} else {
$this->value[] = $value;
}
return $this;
}
/**
* @return string
*/
public function render()
{
return sprintf(
'%s="%s"',
$this->renderName(),
$this->renderValue()
);
}
/**
* @return string
*/
public function renderName()
{
return static::escapeName($this->name);
}
/**
* @return string
*/
public function renderValue()
{
return static::escapeValue($this->value);
}
/**
* @param $name
* @return string
*/
public static function escapeName($name)
{
// TODO: escape
return (string) $name;
}
/**
* @param $value
* @return string
*/
public static function escapeValue($value)
{
// TODO: escape differently
if (is_array($value)) {
return Util::escapeForHtml(implode(' ', $value));
} else {
return Util::escapeForHtml((string) $value);
}
}
}

View file

@ -1,194 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
use Icinga\Exception\IcingaException;
use Icinga\Exception\ProgrammingError;
class Attributes
{
/** @var Attribute[] */
protected $attributes = array();
/** @var callable */
protected $callbacks = array();
/**
* Attributes constructor.
* @param Attribute[] $attributes
*/
public function __construct(array $attributes = null)
{
if (empty($attributes)) {
return;
}
foreach ($attributes as $key => $value) {
if ($value instanceof Attribute) {
$this->addAttribute($value);
} elseif (is_string($key)) {
$this->add($key, $value);
} elseif (is_array($value) && count($value) === 2) {
$this->add(array_shift($value), array_shift($value));
}
}
}
/**
* @param Attribute[] $attributes
* @return static
*/
public static function create(array $attributes = null)
{
return new static($attributes);
}
/**
* @param Attributes|array|null $attributes
* @return Attributes
* @throws IcingaException
*/
public static function wantAttributes($attributes)
{
if ($attributes instanceof Attributes) {
return $attributes;
} else {
$self = new static();
if (is_array($attributes)) {
foreach ($attributes as $k => $v) {
$self->add($k, $v);
}
return $self;
} elseif ($attributes !== null) {
throw new IcingaException(
'Attributes, Array or Null expected, got %s',
Util::getPhpTypeName($attributes)
);
}
return $self;
}
}
/**
* @return Attribute[]
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* @param Attribute|string $attribute
* @param string|array $value
* @return $this
*/
public function add($attribute, $value = null)
{
if ($attribute instanceof static) {
foreach ($attribute->getAttributes() as $a) {
$this->add($a);
}
} elseif ($attribute instanceof Attribute) {
$this->addAttribute($attribute);
} elseif (is_array($attribute)) {
foreach ($attribute as $name => $value) {
$this->add($name, $value);
}
} else {
$this->addAttribute(Attribute::create($attribute, $value));
}
return $this;
}
/**
* @param Attribute|string $attribute
* @param string|array $value
* @return $this
*/
public function set($attribute, $value = null)
{
if ($attribute instanceof static) {
foreach ($attribute as $a) {
$this->setAttribute($a);
}
return $this;
} elseif ($attribute instanceof Attribute) {
return $this->setAttribute($attribute);
} else {
return $this->setAttribute(new Attribute($attribute, $value));
}
}
/**
* @param Attribute $attribute
* @return $this
*/
public function addAttribute(Attribute $attribute)
{
$name = $attribute->getName();
if (array_key_exists($name, $this->attributes)) {
$this->attributes[$name]->addValue($attribute->getValue());
} else {
$this->attributes[$name] = $attribute;
}
return $this;
}
/**
* @param Attribute $attribute
* @return $this
*/
public function setAttribute(Attribute $attribute)
{
$name = $attribute->getName();
$this->attributes[$name] = $attribute;
return $this;
}
/**
* Callback must return an instance of Attribute
*
* @param string $name
* @param callable $callback
* @return $this
*/
public function registerCallbackFor($name, $callback)
{
if (! is_callable($callback)) {
throw new ProgrammingError('registerCallBack expects a callable callback');
}
$this->callbacks[$name] = $callback;
return $this;
}
/**
* @inheritdoc
*/
public function render()
{
if (empty($this->attributes) && empty($this->callbacks)) {
return '';
}
$parts = array();
foreach ($this->callbacks as $callback) {
$attribute = call_user_func($callback);
if (! $attribute instanceof Attribute) {
throw new ProgrammingError(
'A registered attribute callback must return an Attribute'
);
}
$parts[] = $attribute->render();
}
foreach ($this->attributes as $attribute) {
$parts[] = $attribute->render();
}
return ' ' . implode(' ', $parts);
}
}

View file

@ -1,117 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
use Exception;
abstract class BaseElement extends Html
{
/** @var array You may want to set default attributes when extending this class */
protected $defaultAttributes;
/** @var Attributes */
protected $attributes;
/** @var string */
protected $tag;
/**
* @return Attributes
*/
public function attributes()
{
if ($this->attributes === null) {
$default = $this->getDefaultAttributes();
if (empty($default)) {
$this->attributes = new Attributes();
} else {
$this->attributes = Attributes::wantAttributes($default);
}
}
return $this->attributes;
}
/**
* @param Attributes|array|null $attributes
* @return $this
*/
public function setAttributes($attributes)
{
$this->attributes = Attributes::wantAttributes($attributes);
return $this;
}
/**
* @param Attributes|array|null $attributes
* @return $this
*/
public function addAttributes($attributes)
{
$this->attributes()->add($attributes);
return $this;
}
public function getDefaultAttributes()
{
return $this->defaultAttributes;
}
public function setTag($tag)
{
$this->tag = $tag;
return $this;
}
public function getTag()
{
return $this->tag;
}
/**
* Container constructor.
*
* @param string $tag
* @param Attributes|array $attributes
*
* @return Element
*/
public function createElement($tag, $attributes = null)
{
$element = Element::create($tag, $attributes);
$this->add($element);
return $element;
}
public function renderContent()
{
return parent::render();
}
/**
* @return string
*/
public function render()
{
$tag = $this->getTag();
return sprintf(
'<%s%s>%s</%s>',
$tag,
$this->attributes()->render(),
$this->renderContent(),
$tag
);
}
/**
* Whether the given something can be rendered
*
* @param mixed $any
* @return bool
*/
protected function canBeRendered($any)
{
return is_string($any) || is_int($any) || is_null($any);
}
}

View file

@ -1,40 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
class Container extends BaseElement
{
/** @var string */
protected $contentSeparator = "\n";
/** @var string */
protected $tag = 'div';
protected function __construct()
{
}
/**
* @param Renderable|array|string $content
* @param Attributes|array $attributes
* @param string $tag
*
* @return static
*/
public static function create($attributes = null, $content = null, $tag = null)
{
$container = new static();
if ($content !== null) {
$container->setContent($content);
}
if ($attributes !== null) {
$container->setAttributes($attributes);
}
if ($tag !== null) {
$container->setTag($tag);
}
return $container;
}
}

View file

@ -1,34 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
class Element extends BaseElement
{
/**
* Container constructor.
*
* @param string $tag
* @param Attributes|array $attributes
*/
public function __construct($tag, $attributes = null)
{
$this->tag = $tag;
if ($attributes !== null) {
$this->attributes = $this->attributes()->add($attributes);
}
}
/**
* Container constructor.
*
* @param string $tag
* @param Attributes|array $attributes
*
* @return static
*/
public static function create($tag, $attributes = null)
{
return new static($tag, $attributes);
}
}

View file

@ -1,174 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
use Icinga\Exception\ProgrammingError;
use Exception;
class Html implements Renderable
{
protected $contentSeparator = '';
/**
* @var Renderable[]
*/
private $content = array();
public static function escape($any)
{
return Util::wantHtml($any);
}
/**
* @param Renderable $element
* @return $this
*/
public function add(Renderable $element)
{
$this->content[] = $element;
return $this;
}
/**
* @param Renderable $element
* @return $this
*/
public function prepend(Renderable $element)
{
array_unshift($this->content, $element);
return $this;
}
/**
* @param Renderable|array|string $content
* @return $this
*/
public function setContent($content)
{
$this->content = array();
static::addContent($content);
return $this;
}
/**
* @param Renderable|array|string $content
* @return $this
*/
public function addContent($content)
{
if (is_array($content)) {
foreach ($content as $c) {
static::addContent($c);
}
} else {
$this->content[] = static::escape($content);
}
return $this;
}
/**
* @param Renderable|array|string $content
* @return $this
*/
public function prependContent($content)
{
array_unshift($this->content, static::escape($content));
return $this;
}
/**
* return Html
*/
public function getContent()
{
if ($this->content === null) {
$this->content = array(new Html());
}
return $this->content;
}
public function hasContent()
{
if ($this->content === null) {
return false;
}
// TODO: unfinished
// return $this->content->isEmpty();
return true;
}
/**
* @param $separator
* @return $this
*/
public function setSeparator($separator)
{
$this->contentSeparator = $separator;
return $this;
}
/**
* @inheritdoc
*/
public function render()
{
$html = array();
foreach ($this->content as $element) {
if (is_string($element)) {
var_dump($this->content);
}
$html[] = $element->render();
}
return implode($this->contentSeparator, $html);
}
protected function translate($msg)
{
// TODO: Not so nice
return mt('businessprocess', $msg);
}
public static function element($name, $attributes = null)
{
// TODO: This might be anything here, add a better check
if (! ctype_alnum($name)) {
throw new ProgrammingError('Invalid element requested');
}
$class = __NAMESPACE__ . '\\' . $name;
/** @var Element $element */
$element = new $class();
if ($attributes !== null) {
$element->setAttributes($attributes);
}
return $element;
}
/**
* @param Exception|string $error
* @return string
*/
protected function renderError($error)
{
return Util::renderError($error);
}
/**
* @return string
*/
public function __toString()
{
try {
return $this->render();
} catch (Exception $e) {
return $this->renderError($e);
}
}
}

View file

@ -1,8 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
class HtmlString extends Text
{
protected $escaped = true;
}

View file

@ -1,28 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
abstract class HtmlTag
{
/**
* @param $content
* @param Attributes|array $attributes
*
* @return Element
*/
public static function h1($content, $attributes = null)
{
return Element::create('h1', $attributes)->setContent($content);
}
/**
* @param $content
* @param Attributes|array $attributes
*
* @return Element
*/
public static function p($content, $attributes = null)
{
return Element::create('p', $attributes)->setContent($content);
}
}

View file

@ -1,26 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
class Icon extends BaseElement
{
protected $tag = 'i';
protected function __construct()
{
}
/**
* @param string $name
* @param array $attributes
*
* @return static
*/
public static function create($name, array $attributes = null)
{
$icon = new static();
$icon->setAttributes($attributes);
$icon->attributes()->add('class', array('icon', 'icon-' . $name));
return $icon;
}
}

View file

@ -1,72 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Web\Url;
use Icinga\Web\Url as WebUrl;
class Img extends BaseElement
{
protected $tag = 'img';
/** @var Url */
protected $url;
protected $defaultAttributes = array('alt' => '');
protected function __construct()
{
}
/**
* @param Url|string $url
* @param array $urlParams
* @param array $attributes
*
* @return static
*/
public static function create($url, $urlParams = null, array $attributes = null)
{
$img = new static();
$img->setAttributes($attributes);
$img->attributes()->registerCallbackFor('src', array($img, 'getSrcAttribute'));
$img->setUrl($url, $urlParams);
return $img;
}
public function setUrl($url, $urlParams)
{
if ($url instanceof WebUrl) { // Hint: Url is also a WebUrl
if ($urlParams !== null) {
$url->addParams($urlParams);
}
$this->url = $url;
} else {
if ($urlParams === null) {
$this->url = Url::fromPath($url);
} else {
$this->url = Url::fromPath($url, $urlParams);
}
}
$this->url->getParams();
}
/**
* @return Attribute
*/
public function getSrcAttribute()
{
return new Attribute('src', $this->getUrl()->getAbsoluteUrl('&'));
}
/**
* @return Url
*/
public function getUrl()
{
// TODO: What if null? #?
return $this->url;
}
}

View file

@ -1,72 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Web\Url;
use Icinga\Web\Url as WebUrl;
class Link extends BaseElement
{
protected $tag = 'a';
/** @var Url */
protected $url;
protected function __construct()
{
}
/**
* @param Renderable|array|string $content
* @param Url|string $url
* @param array $urlParams
* @param array $attributes
*
* @return static
*/
public static function create($content, $url, $urlParams = null, array $attributes = null)
{
$link = new static();
$link->setContent($content);
$link->setAttributes($attributes);
$link->attributes()->registerCallbackFor('href', array($link, 'getHrefAttribute'));
$link->setUrl($url, $urlParams);
return $link;
}
public function setUrl($url, $urlParams)
{
if ($url instanceof WebUrl) { // Hint: Url is also a WebUrl
if ($urlParams !== null) {
$url->addParams($urlParams);
}
$this->url = $url;
} else {
if ($urlParams === null) {
$this->url = Url::fromPath($url);
} else {
$this->url = Url::fromPath($url, $urlParams);
}
}
$this->url->getParams();
}
/**
* @return Attribute
*/
public function getHrefAttribute()
{
return new Attribute('href', $this->getUrl()->getAbsoluteUrl('&'));
}
/**
* @return Url
*/
public function getUrl()
{
// TODO: What if null? #?
return $this->url;
}
}

View file

@ -1,8 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
interface Renderable
{
public function render();
}

View file

@ -1,82 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
class Text implements Renderable
{
/** @var string */
protected $string;
protected $escaped = false;
/**
* Text constructor.
*
* @param $text
*/
public function __construct($string)
{
$this->string = (string) $string;
}
/**
* @return string
*/
public function getText()
{
return $this->string;
}
/**
* @param bool $escaped
* @return $this
*/
public function setEscaped($escaped = true)
{
$this->escaped = $escaped;
return $this;
}
/**
* @param $text
*
* @return static
*/
public static function create($text)
{
return new static($text);
}
/**
* @return string
*/
public function render()
{
if ($this->escaped) {
return $this->string;
} else {
return Util::escapeForHtml($this->string);
}
}
/**
* @param Exception|string $error
* @return string
*/
protected function renderError($error)
{
return Util::renderError($error);
}
/**
* @return string
*/
public function __toString()
{
try {
return $this->render();
} catch (Exception $e) {
return $this->renderError($e);
}
}
}

View file

@ -1,130 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
use Exception;
use Icinga\Exception\IcingaException;
class Util
{
/**
* Charset to be used - we only support UTF-8
*/
const CHARSET = 'UTF-8';
/**
* The flags we use for htmlspecialchars depend on our PHP version
*/
protected static $htmlEscapeFlags;
/**
* Escape the given value top be safely used in view scripts
*
* @param string $value The output to be escaped
* @return string
*/
public static function escapeForHtml($value)
{
return htmlspecialchars(
$value,
static::htmlEscapeFlags(),
self::CHARSET,
true
);
}
/**
* @param Exception|string $error
* @return string
*/
public static function renderError($error)
{
if ($error instanceof Exception) {
$file = preg_split('/[\/\\\]/', $error->getFile(), -1, PREG_SPLIT_NO_EMPTY);
$file = array_pop($file);
$msg = sprintf(
'%s (%s:%d)',
$error->getMessage(),
$file,
$error->getLine()
);
} elseif (is_string($error)) {
$msg = $error;
} else {
$msg = 'Got an invalid error'; // TODO: translate?
}
return sprintf(
'ERROR: %s', // TODO: translate?
static::escapeForHtml($msg)
);
}
/**
* @param $any
* @return Renderable
* @throws IcingaException
*/
public static function wantHtml($any)
{
if ($any instanceof Renderable) {
return $any;
} elseif (static::canBeRenderedAsString($any)) {
return new Text($any);
} elseif (is_array($any)) {
$html = new Html();
foreach ($any as $el) {
$html->add(static::wantHtml($el));
}
return $html;
} else {
// TODO: Should we add a dedicated Exception class?
throw new IcingaException(
'String, Html Element or Array of such expected, got "%s"',
Util::getPhpTypeName($any)
);
}
}
public static function canBeRenderedAsString($any)
{
return is_string($any) || is_int($any) || is_null($any);
}
/**
* @param $any
* @return string
*/
public static function getPhpTypeName($any)
{
if (is_object($any)) {
return get_class($any);
} else {
return gettype($any);
}
}
/**
* This defines the flags used when escaping for HTML
*
* - Single quotes are not escaped (ENT_COMPAT)
* - With PHP >= 5.4, invalid characters are replaced with <EFBFBD> (ENT_SUBSTITUTE)
* - With PHP 5.3 they are ignored (ENT_IGNORE, less secure)
* - Uses HTML5 entities for PHP >= 5.4, disallowing &#013;
*
* @return int
*/
protected static function htmlEscapeFlags()
{
if (self::$htmlEscapeFlags === null) {
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
self::$htmlEscapeFlags = ENT_COMPAT | ENT_SUBSTITUTE | ENT_HTML5;
} else {
self::$htmlEscapeFlags = ENT_COMPAT | ENT_IGNORE;
}
}
return self::$htmlEscapeFlags;
}
}

View file

@ -3,11 +3,11 @@
namespace Icinga\Module\Businessprocess;
use Icinga\Application\Config;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\State\MonitoringState;
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
use Icinga\Module\Businessprocess\Web\Url;
use Exception;
use Icinga\Web\Url;
use ipl\Html\Html;
class ImportedNode extends Node
{
@ -226,13 +226,15 @@ class ImportedNode extends Node
*/
public function getLink()
{
return Link::create(
$this->getAlias(),
'businessprocess/process/show',
array(
'config' => $this->configName,
'node' => $this->nodeName
)
return Html::tag(
'a',
[
'href' => Url::fromPath('businessprocess/process/show', [
'config' => $this->configName,
'node' => $this->nodeName
])
],
$this->getAlias()
);
}
}

View file

@ -2,7 +2,7 @@
namespace Icinga\Module\Businessprocess;
use Icinga\Module\Businessprocess\Html\Link;
use ipl\Html\Html;
abstract class MonitoredNode extends Node
{
@ -11,9 +11,9 @@ abstract class MonitoredNode extends Node
public function getLink()
{
if ($this->isMissing()) {
return Link::create($this->getAlias(), '#');
return Html::tag('a', ['href' => '#'], $this->getAlias());
} else {
return Link::create($this->getAlias(), $this->getUrl());
return Html::tag('a', ['href' => $this->getUrl()], $this->getAlias());
}
}
}

View file

@ -3,7 +3,7 @@
namespace Icinga\Module\Businessprocess;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Businessprocess\Html\Link;
use ipl\Html\Html;
abstract class Node
{
@ -368,12 +368,9 @@ abstract class Node
return $this->className;
}
/**
* @return Link
*/
public function getLink()
{
return Link::create($this->getAlias(), '#');
return Html::tag('a', ['href' => '#'], $this->getAlias());
}
public function operatorHtml()

View file

@ -3,14 +3,12 @@
namespace Icinga\Module\Businessprocess\Renderer;
use Icinga\Module\Businessprocess\BpNode;
use Icinga\Module\Businessprocess\Html\BaseElement;
use Icinga\Module\Businessprocess\Html\Element;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Renderer\TileRenderer\NodeTile;
use Icinga\Module\Businessprocess\Web\Url;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
class Breadcrumb extends BaseElement
class Breadcrumb extends BaseHtmlElement
{
protected $tag = 'ul';
@ -32,16 +30,18 @@ class Breadcrumb extends BaseElement
$bpUrl->remove('action');
}
$breadcrumb->add(Element::create('li')->add(
Link::create(
Icon::create('dashboard'),
Url::fromPath('businessprocess'),
null,
['title' => mt('businessprocess', 'Show Overview')]
$breadcrumb->add(Html::tag('li')->add(
Html::tag(
'a',
[
'href' => Url::fromPath('businessprocess'),
'title' => mt('businessprocess', 'Show Overview')
],
Html::tag('i', ['class' => 'icon icon-dashboard'])
)
));
$breadcrumb->add(Element::create('li')->add(
Link::create($bp->getTitle(), $bpUrl)
$breadcrumb->add(Html::tag('li')->add(
Html::tag('a', ['href' => $bpUrl], $bp->getTitle())
));
$path = $renderer->getCurrentPath();
@ -52,7 +52,7 @@ class Breadcrumb extends BaseElement
static::renderNode($bp->getNode($node), $path, $renderer)
);
}
$breadcrumb->addContent($parts);
$breadcrumb->add($parts);
return $breadcrumb;
}
@ -70,7 +70,7 @@ class Breadcrumb extends BaseElement
$renderer = clone($renderer);
$renderer->lock()->setIsBreadcrumb();
$p = new NodeTile($renderer, (string) $node, $node, $path);
$p->attributes()->add('class', $renderer->getNodeClasses($node));
$p->getAttributes()->add('class', $renderer->getNodeClasses($node));
$p->setTag('li');
return $p;
}

View file

@ -6,14 +6,14 @@ use Icinga\Date\DateFormatter;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Businessprocess\BpNode;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Html\Container;
use Icinga\Module\Businessprocess\Html\Element;
use Icinga\Module\Businessprocess\Html\Html;
use Icinga\Module\Businessprocess\Html\HtmlString;
use Icinga\Module\Businessprocess\Node;
use Icinga\Module\Businessprocess\Web\Url;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlString;
abstract class Renderer extends Html
abstract class Renderer extends HtmlDocument
{
/** @var BpConfig */
protected $config;
@ -122,7 +122,7 @@ abstract class Renderer extends Html
/**
* @param $summary
* @return Container
* @return BaseHtmlElement
*/
public function renderStateBadges($summary)
{
@ -136,26 +136,24 @@ abstract class Renderer extends Html
continue;
}
$elements[] = Element::create(
$elements[] = Html::tag(
'span',
array(
'class' => array(
[
'class' => [
'badge',
'badge-' . strtolower($state)
),
],
// TODO: We should translate this in this module
'title' => mt('monitoring', $state)
)
)->setContent($cnt);
],
$cnt
);
}
if (!empty($elements)) {
$container = Container::create(
array('class' => 'badges')
)/* ->renderIfEmpty(false) */;
$container = Html::tag('div', ['class' => 'badges']);
foreach ($elements as $element) {
$container->addContent($element);
$container->add($element);
}
return $container;
@ -306,13 +304,14 @@ abstract class Renderer extends Html
return HtmlString::create('');
}
return Element::create(
return Html::tag(
'span',
array(
'class' => array('relative-time', 'time-since'),
'title' => DateFormatter::formatDateTime($time),
)
)->setContent(DateFormatter::timeSince($time, $timeOnly));
[
'class' => ['relative-time', 'time-since'],
'title' => DateFormatter::formatDateTime($time)
],
DateFormatter::timeSince($time, $timeOnly)
);
}
protected function createUnboundParent(BpConfig $bp)

View file

@ -2,10 +2,8 @@
namespace Icinga\Module\Businessprocess\Renderer;
use Icinga\Module\Businessprocess\Html\Container;
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Renderer\TileRenderer\NodeTile;
use ipl\Html\Html;
class TileRenderer extends Renderer
{
@ -15,14 +13,12 @@ class TileRenderer extends Renderer
public function render()
{
$bp = $this->config;
$nodesDiv = Container::create(
array(
'class' => array(
'tiles',
$this->howMany()
),
'data-base-target' => '_next',
)
$nodesDiv = Html::tag(
'div',
[
'class' => ['tiles', $this->howMany()],
'data-base-target' => '_next'
]
);
$nodes = $this->getChildNodes();
@ -50,7 +46,7 @@ class TileRenderer extends Renderer
$this->add($this->addNewNode());
}
$nodesDiv->addContent($this->getContent());
$nodesDiv->add($this->getContent());
$this->setContent($nodesDiv);
return parent::render();
@ -80,30 +76,26 @@ class TileRenderer extends Renderer
protected function addNewNode()
{
$div = Container::create(
array('class' => 'addnew', 'data-base-target' => '_self')
);
$div = Html::tag('div', ['class' => 'addnew', 'data-base-target' => '_self']);
$actions = Container::create(
array('class'=> 'actions')
);
$actions = Html::tag('div', ['class'=> 'actions']);
$link = Link::create(
$this->translate('Add'),
$this->getUrl()->with('action', 'add'),
null,
array(
'title' => $this->translate('Add a new business process node')
)
$link = Html::tag(
'a',
[
'href' => $this->getUrl()->with('action', 'add'),
'title' => mt('businessprocess', 'Add a new business process node')
],
mt('businessprocess', 'Add')
);
$actions->add(
Link::create(
Icon::create('plus'),
$this->getUrl()->with('action', 'add'),
null,
array(
'title' => $this->translate('Add a new business process node')
)
Html::tag(
'a',
[
'href' => $this->getUrl()->with('action', 'add'),
'title' => mt('businessprocess', 'Add a new business process node')
],
Html::tag('i', ['class' => 'icon icon-plus'])
)
);

View file

@ -4,18 +4,15 @@ namespace Icinga\Module\Businessprocess\Renderer\TileRenderer;
use Icinga\Module\Businessprocess\BpNode;
use Icinga\Module\Businessprocess\HostNode;
use Icinga\Module\Businessprocess\Html\BaseElement;
use Icinga\Module\Businessprocess\Html\Container;
use Icinga\Module\Businessprocess\Html\HtmlString;
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\ImportedNode;
use Icinga\Module\Businessprocess\MonitoredNode;
use Icinga\Module\Businessprocess\Node;
use Icinga\Module\Businessprocess\Renderer\Renderer;
use Icinga\Module\Businessprocess\ServiceNode;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
class NodeTile extends BaseElement
class NodeTile extends BaseHtmlElement
{
protected $tag = 'div';
@ -28,7 +25,7 @@ class NodeTile extends BaseElement
protected $path;
/**
* @var Container
* @var BaseHtmlElement
*/
private $actions;
@ -57,11 +54,12 @@ class NodeTile extends BaseElement
protected function addActions()
{
$this->actions = Container::create(
array(
$this->actions = Html::tag(
'div',
[
'class' => 'actions',
'data-base-target' => '_self'
)
]
);
return $this->add($this->actions);
@ -72,7 +70,7 @@ class NodeTile extends BaseElement
$renderer = $this->renderer;
$node = $this->node;
$attributes = $this->attributes();
$attributes = $this->getAttributes();
$attributes->add('class', $renderer->getNodeClasses($node));
$attributes->add('id', 'bp-' . (string) $node);
@ -83,9 +81,9 @@ class NodeTile extends BaseElement
if ($node instanceof BpNode) {
if ($renderer->isBreadcrumb()) {
$link->addContent($renderer->renderStateBadges($node->getStateSummary()));
$link->add($renderer->renderStateBadges($node->getStateSummary()));
} else {
$this->addContent($renderer->renderStateBadges($node->getStateSummary()));
$this->add($renderer->renderStateBadges($node->getStateSummary()));
}
}
@ -168,32 +166,22 @@ class NodeTile extends BaseElement
}
/**
* @return Link
* @return BaseHtmlElement
*/
protected function getMainNodeLink()
{
$node = $this->node;
$url = $this->getMainNodeUrl($node);
if ($node instanceof ServiceNode) {
$link = Link::create(
$node->getAlias(),
$url,
null,
array('data-base-target' => '_next')
);
$link = Html::tag('a', ['href' => $url, 'data-base-target' => '_next'], $node->getAlias());
} elseif ($node instanceof HostNode) {
$link = Link::create(
$node->getHostname(),
$url,
null,
array('data-base-target' => '_next')
);
$link = Html::tag('a', ['href' => $url, 'data-base-target' => '_next'], $node->getHostname());
} else {
$link = Link::create($node->getAlias(), $url);
$link = Html::tag('a', ['href' => $url], $node->getAlias());
if ($node instanceof ImportedNode) {
$link->attributes()->add('data-base-target', '_next');
$link->getAttributes()->add('data-base-target', '_next');
} else {
$link->attributes()->add('data-base-target', '_self');
$link->getAttributes()->add('data-base-target', '_self');
}
}
@ -206,56 +194,54 @@ class NodeTile extends BaseElement
$url = $this->getMainNodeUrl($node);
if ($node instanceof BpNode) {
$this->actions()->add(Link::create(
Icon::create('dashboard'),
$url->with('mode', 'tile'),
null,
array(
'title' => $this->translate('Show tiles for this subtree'),
'data-base-target' => '_self'
)
))->add(Link::create(
Icon::create('sitemap'),
$url->with('mode', 'tree'),
null,
array(
'title' => $this->translate('Show this subtree as a tree'),
'data-base-target' => '_next'
)
$this->actions()->add(Html::tag(
'a',
[
'data-base-target' => '_self',
'href' => $url->with('mode', 'tile'),
'title' => mt('businessprocess', 'Show tiles for this subtree')
],
Html::tag('i', ['class' => 'icon icon-dashboard'])
))->add(Html::tag(
'a',
[
'data-base-target' => '_next',
'href' => $url->with('mode', 'tree'),
'title' => mt('businessprocess', 'Show this subtree as a tree')
],
Html::tag('i', ['class' => 'icon icon-sitemap'])
));
$url = $node->getInfoUrl();
if ($url !== null) {
$link = Link::create(
Icon::create('info-circled'),
$url,
null,
array(
'title' => sprintf('%s: %s', $this->translate('More information'), $url),
'class' => 'node-info'
)
$link = Html::tag(
'a',
[
'href' => $url,
'class' => 'node-info',
'title' => sprintf('%s: %s', mt('businessprocess', 'More information'), $url)
],
Html::tag('i', ['class' => 'icon icon-circled'])
);
if (preg_match('#^http(?:s)?://#', $url)) {
$link->addAttributes(array('target' => '_blank'));
$link->addAttributes(['target' => '_blank']);
}
$this->actions()->add($link);
}
} else {
// $url = $this->makeMonitoredNodeUrl($node);
if ($node instanceof ServiceNode) {
$this->actions()->add(Link::create(
Icon::create('service'),
$node->getUrl(),
null,
array('data-base-target' => '_next')
$this->actions()->add(Html::tag(
'a',
['href' => $node->getUrl(), 'data-base-target' => '_next'],
Html::tag('i', ['class' => 'icon icon-service'])
));
} elseif ($node instanceof HostNode) {
$this->actions()->add(Link::create(
Icon::create('host'),
$node->getUrl(),
null,
array('data-base-target' => '_next')
$this->actions()->add(Html::tag(
'a',
['href' => $node->getUrl(), 'data-base-target' => '_next'],
Html::tag('i', ['class' => 'icon icon-host'])
));
}
}
@ -266,21 +252,29 @@ class NodeTile extends BaseElement
$node = $this->node;
$renderer = $this->renderer;
if ($node instanceof MonitoredNode) {
$this->actions()->add(Link::create(
Icon::create('magic'),
$renderer->getUrl()->with('action', 'simulation')
->with('simulationnode', $this->name),
null,
array('title' => $this->translate(
'Show the business impact of this node by simulating a specific state'
))
$this->actions()->add(Html::tag(
'a',
[
'href' => $renderer->getUrl()
->with('action', 'simulation')
->with('simulationnode', $this->name),
'title' => mt(
'businessprocess',
'Show the business impact of this node by simulating a specific state'
)
],
Html::tag('i', ['class' => 'icon icon-magic'])
));
$this->actions()->add(Link::create(
Icon::create('edit'),
$renderer->getUrl()->with('action', 'editmonitored')->with('editmonitorednode', $node->getName()),
null,
array('title' => $this->translate('Modify this monitored node'))
$this->actions()->add(Html::tag(
'a',
[
'href' => $renderer->getUrl()
->with('action', 'editmonitored')
->with('editmonitorednode', $node->getName()),
'title' => mt('businessprocess', 'Modify this monitored node')
],
Html::tag('i', ['class' => 'icon icon-edit'])
));
}
@ -291,11 +285,15 @@ class NodeTile extends BaseElement
}
if ($node instanceof BpNode) {
$this->actions()->add(Link::create(
Icon::create('edit'),
$renderer->getUrl()->with('action', 'edit')->with('editnode', $node->getName()),
null,
array('title' => $this->translate('Modify this business process node'))
$this->actions()->add(Html::tag(
'a',
[
'href' => $renderer->getUrl()
->with('action', 'edit')
->with('editnode', $node->getName()),
'title' => mt('businessprocess', 'Modify this business process node')
],
Html::tag('i', ['class' => 'icon icon-edit'])
));
}
@ -304,11 +302,13 @@ class NodeTile extends BaseElement
'deletenode' => $node->getName(),
);
$this->actions()->add(Link::create(
Icon::create('cancel'),
$renderer->getUrl()->with($params),
null,
array('title' => $this->translate('Delete this node'))
$this->actions()->add(Html::tag(
'a',
[
'href' => $renderer->getUrl()->with($params),
'title' => mt('businessprocess', 'Delete this node')
],
Html::tag('i', ['class' => 'icon icon-cancle'])
));
}
}

View file

@ -4,12 +4,9 @@ namespace Icinga\Module\Businessprocess\Renderer;
use Icinga\Module\Businessprocess\BpNode;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Html\Container;
use Icinga\Module\Businessprocess\Html\Element;
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Node;
use Icinga\Module\Businessprocess\Web\Url;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
class TreeRenderer extends Renderer
{
@ -19,11 +16,12 @@ class TreeRenderer extends Renderer
public function render()
{
$bp = $this->config;
$this->add(Container::create(
array(
$this->add(Html::tag(
'div',
[
'id' => $bp->getHtmlId(),
'class' => 'bp'
),
],
$this->renderBp($bp)
));
@ -79,16 +77,16 @@ class TreeRenderer extends Renderer
/**
* @param Node $node
* @return Icon[]
* @return BaseHtmlElement[]
*/
public function getNodeIcons(Node $node)
{
$icons = array();
if ($node->isInDowntime()) {
$icons[] = Icon::create('moon');
$icons[] = Html::tag('i', ['class' => 'icon icon-moon']);
}
if ($node->isAcknowledged()) {
$icons[] = Icon::create('ok');
$icons[] = Html::tag('i', ['class' => 'icon icon-ok']);
}
return $icons;
}
@ -102,17 +100,17 @@ class TreeRenderer extends Renderer
*/
public function renderNode(BpConfig $bp, Node $node, $path = array())
{
$table = Element::create(
$table = Html::tag(
'table',
array(
[
'id' => $this->getId($node, $path),
'class' => array(
'bp',
$node->getObjectClassName()
)
)
]
);
$attributes = $table->attributes();
$attributes = $table->getAttributes();
$attributes->add('class', $this->getStateClassNames($node));
if ($node->isHandled()) {
$attributes->add('class', 'handled');
@ -123,57 +121,68 @@ class TreeRenderer extends Renderer
$attributes->add('class', 'node');
}
$tbody = $table->createElement('tbody');
$tr = $tbody->createElement('tr');
$tbody = Html::tag('tbody');
$table->add($tbody);
$tr = Html::tag('tr');
$tbody->add($tr);
if ($node instanceof BpNode) {
$tr->createElement(
$tr->add(Html::tag(
'th',
array(
'rowspan' => $node->countChildren() + 1 + ($this->isLocked() ? 0 : 1)
)
)->createElement(
'span',
array('class' => 'op')
)->setContent($node->operatorHtml());
['rowspan' => $node->countChildren() + 1 + ($this->isLocked() ? 0 : 1)],
Html::tag('span', ['class' => 'op'], $node->operatorHtml())
));
}
$td = $tr->createElement('td');
$td = Html::tag('td');
$tr->add($td);
if ($node instanceof BpNode && $node->hasInfoUrl()) {
$td->add($this->createInfoAction($node));
}
if (! $this->isLocked()) {
$td->addContent($this->getActionIcons($bp, $node));
$td->add($this->getActionIcons($bp, $node));
}
$link = $node->getLink();
$link->attributes()->set('data-base-target', '_next');
$link->addContent($this->getNodeIcons($node));
$link->getAttributes()->set('data-base-target', '_next');
$link->add($this->getNodeIcons($node));
if ($node->hasChildren()) {
$link->addContent($this->renderStateBadges($node->getStateSummary()));
$link->add($this->renderStateBadges($node->getStateSummary()));
}
if ($time = $node->getLastStateChange()) {
$since = $this->timeSince($time)->prependContent(
$since = $this->timeSince($time)->prepend(
sprintf(' (%s ', $node->getStateName())
)->addContent(')');
$link->addContent($since);
)->add(')');
$link->add($since);
}
$td->addContent($link);
$td->add($link);
foreach ($node->getChildren() as $name => $child) {
$tbody->createElement('tr')->createElement('td')->setContent(
$this->renderNode($bp, $child, $this->getCurrentPath())
);
$tbody->add(Html::tag(
'tr',
null,
Html::tag(
'td',
null,
$this->renderNode($bp, $child, $this->getCurrentPath())
)
));
}
if (! $this->isLocked() && $node instanceof BpNode && $bp->getMetadata()->canModify()) {
$tbody->createElement('tr')->createElement('td')->setContent(
$this->renderAddNewNode($node)
);
$tbody->add(Html::tag(
'tr',
null,
Html::tag(
'td',
null,
$this->renderAddNewNode($node)
)
));
}
return $table;
@ -200,7 +209,7 @@ class TreeRenderer extends Renderer
'action' => 'edit',
'editnode' => $node->getName()
)),
$this->translate('Modify this node')
mt('businessprocess', 'Modify this node')
);
}
@ -213,7 +222,7 @@ class TreeRenderer extends Renderer
'action' => 'simulation',
'simulationnode' => $node->getName()
)),
$this->translate('Simulate a specific state')
mt('businessprocess', 'Simulate a specific state')
);
}
@ -223,33 +232,35 @@ class TreeRenderer extends Renderer
return $this->actionIcon(
'help',
$url,
sprintf('%s: %s', $this->translate('More information'), $url)
sprintf('%s: %s', mt('businessprocess', 'More information'), $url)
);
}
protected function actionIcon($icon, $url, $title)
{
return Link::create(
Icon::create($icon),
$url,
null,
array(
return Html::tag(
'a',
[
'href' => $url,
'title' => $title,
'style' => 'float: right',
)
'style' => 'float: right'
],
Html::tag('i', ['class' => 'icon icon-' . $icon])
);
}
protected function renderAddNewNode($parent)
{
return Link::create(
$this->translate('Add'),
$this->getUrl()->with('action', 'add')->with('node', $parent->getName()),
null,
array(
'class' => 'addnew icon-plus',
'title' => $this->translate('Add a new business process node')
)
return Html::tag(
'a',
[
'href' => $this->getUrl()
->with('action', 'add')
->with('node', $parent->getName()),
'title' => mt('businessprocess', 'Add a new business process node'),
'class' => 'addnew icon-plus'
],
mt('businessprocess', 'Add')
);
}
}

View file

@ -7,9 +7,9 @@ use Diff_Renderer_Html_Inline;
use Diff_Renderer_Html_SideBySide;
use Diff_Renderer_Text_Context;
use Diff_Renderer_Text_Unified;
use Icinga\Module\Businessprocess\Html\Renderable;
use ipl\Html\ValidHtml;
class ConfigDiff implements Renderable
class ConfigDiff implements ValidHtml
{
protected $a;

View file

@ -23,6 +23,7 @@ class Bootstrap
Cli::start($testsDir, $configDir)
->getModuleManager()
->loadModule('ipl', $basedir . '/vendor/ipl')
->loadModule('businessprocess', $basedir);
}
}

View file

@ -2,9 +2,9 @@
namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Module\Businessprocess\Html\BaseElement;
use ipl\Html\BaseHtmlElement;
class ActionBar extends BaseElement
class ActionBar extends BaseHtmlElement
{
protected $contentSeparator = ' ';

View file

@ -3,15 +3,12 @@
namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Html\BaseElement;
use Icinga\Module\Businessprocess\Html\Container;
use Icinga\Module\Businessprocess\Html\Element;
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Html\Text;
use Icinga\Module\Businessprocess\Web\Url;
use Icinga\Web\Url;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Html\Text;
class BpDashboardTile extends BaseElement
class BpDashboardTile extends BaseHtmlElement
{
protected $tag = 'div';
@ -19,33 +16,32 @@ class BpDashboardTile extends BaseElement
public function __construct(BpConfig $bp, $title, $description, $icon, $url, $urlParams = null, $attributes = null)
{
$this->add(
Container::create(
['class' => 'bp-link', 'data-base-target' => '_main'],
Link::create(
Icon::create($icon),
$url,
$urlParams,
$attributes
)->add(
Element::create('span', array('class' => 'header'))->addContent($title)
)->addContent($description)
)
);
if (! isset($attributes['href'])) {
$attributes['href'] = Url::fromPath($url, $urlParams ?: []);
}
$tiles = Container::create(['class' => 'bp-root-tiles']);
$this->add(Html::tag(
'div',
['class' => 'bp-link', 'data-base-target' => '_main'],
Html::tag('a', $attributes, Html::tag('i', ['class' => 'icon icon-' . $icon]))
->add(Html::tag('span', ['class' => 'header'], $title))
->add($description)
));
$tiles = Html::tag('div', ['class' => 'bp-root-tiles']);
foreach ($bp->getChildren() as $node) {
$state = strtolower($node->getStateName());
$tiles->add(
Link::create(
Text::create('&nbsp;')->setEscaped(),
$url,
$urlParams + ['node' => $node->getName()],
['class' => "badge state-{$state}", 'title' => $node->getAlias()]
)
);
$tiles->add(Html::tag(
'a',
[
'href' => Url::fromPath($url, $urlParams ?: [])->with(['node' => $node->getName()]),
'class' => "badge state-{$state}",
'title' => $node->getAlias()
],
Text::create('&nbsp;')->setEscaped()
));
}
$this->add($tiles);

View file

@ -2,10 +2,12 @@
namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Module\Businessprocess\Html\Container;
use ipl\Html\BaseHtmlElement;
class Content extends Container
class Content extends BaseHtmlElement
{
protected $tag = 'div';
protected $contentSeparator = "\n";
protected $defaultAttributes = array('class' => 'content');

View file

@ -2,10 +2,12 @@
namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Module\Businessprocess\Html\Container;
use ipl\Html\BaseHtmlElement;
class Controls extends Container
class Controls extends BaseHtmlElement
{
protected $tag = 'div';
protected $contentSeparator = "\n";
protected $defaultAttributes = array('class' => 'controls');

View file

@ -3,13 +3,12 @@
namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Authentication\Auth;
use Icinga\Module\Businessprocess\Html\BaseElement;
use Icinga\Module\Businessprocess\Html\Container;
use Icinga\Module\Businessprocess\Html\HtmlTag;
use Icinga\Module\Businessprocess\State\MonitoringState;
use Icinga\Module\Businessprocess\Storage\Storage;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
class Dashboard extends BaseElement
class Dashboard extends BaseHtmlElement
{
/** @var string */
protected $contentSeparator = "\n";
@ -40,21 +39,22 @@ class Dashboard extends BaseElement
// TODO: Auth?
$processes = $storage->listProcessNames();
$this->add(
HtmlTag::h1($this->translate('Welcome to your Business Process Overview'))
Html::tag('h1', null, mt('businessprocess', 'Welcome to your Business Process Overview'))
);
$this->add(
HtmlTag::p(
$this->translate(
'From here you can reach all your defined Business Process'
. ' configurations, create new or modify existing ones'
)
$this->add(Html::tag(
'p',
null,
mt(
'businessprocess',
'From here you can reach all your defined Business Process'
. ' configurations, create new or modify existing ones'
)
);
));
if ($auth->hasPermission('businessprocess/create')) {
$this->add(
new DashboardAction(
$this->translate('Create'),
$this->translate('Create a new Business Process configuration'),
mt('businessprocess', 'Create'),
mt('businessprocess', 'Create a new Business Process configuration'),
'plus',
'businessprocess/process/create',
null,
@ -62,8 +62,8 @@ class Dashboard extends BaseElement
)
)->add(
new DashboardAction(
$this->translate('Upload'),
$this->translate('Upload an existing Business Process configuration'),
mt('businessprocess', 'Upload'),
mt('businessprocess', 'Upload an existing Business Process configuration'),
'upload',
'businessprocess/process/upload',
null,
@ -71,10 +71,13 @@ class Dashboard extends BaseElement
)
);
} elseif (empty($processes)) {
$this->addContent(
Container::create()
->add(HtmlTag::h1($this->translate('Not available')))
->add(HtmlTag::p($this->translate('No Business Process has been defined for you')))
$this->add(
Html::tag('div')
->add(Html::tag('h1', null, mt('businessprocess', 'Not available')))
->add(Html::tag('p', null, mt(
'businessprocess',
'No Business Process has been defined for you'
)))
);
}

View file

@ -2,12 +2,11 @@
namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Module\Businessprocess\Html\BaseElement;
use Icinga\Module\Businessprocess\Html\Element;
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Web\Url;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
class DashboardAction extends BaseElement
class DashboardAction extends BaseHtmlElement
{
protected $tag = 'div';
@ -15,15 +14,13 @@ class DashboardAction extends BaseElement
public function __construct($title, $description, $icon, $url, $urlParams = null, $attributes = null)
{
$this->add(
Link::create(
Icon::create($icon),
$url,
$urlParams,
$attributes
)->add(
Element::create('span', array('class' => 'header'))->addContent($title)
)->addContent($description)
);
if (! isset($attributes['href'])) {
$attributes['href'] = Url::fromPath($url, $urlParams ?: []);
}
$this->add(Html::tag('a', $attributes)
->add(Html::tag('i', ['class' => 'icon icon-' . $icon]))
->add(Html::tag('span', ['class' => 'header'], $title))
->add($description));
}
}

View file

@ -4,10 +4,10 @@ namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Authentication\Auth;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Renderer\Renderer;
use Icinga\Module\Businessprocess\Renderer\TreeRenderer;
use Icinga\Module\Businessprocess\Web\Url;
use Icinga\Web\Url;
use ipl\Html\Html;
class RenderedProcessActionBar extends ActionBar
{
@ -16,87 +16,73 @@ class RenderedProcessActionBar extends ActionBar
$meta = $config->getMetadata();
if ($renderer instanceof TreeRenderer) {
$this->add(
Link::create(
$this->translate('Tiles'),
$url->with('mode', 'tile'),
null,
array(
'class' => 'icon-dashboard',
'title' => $this->translate('Switch to Tile view'),
)
)
);
$this->add(Html::tag(
'a',
[
'href' => $url->with('mode', 'tile'),
'title' => mt('businessprocess', 'Switch to Tile view'),
'class' => 'icon-dashboard'
],
mt('businessprocess', 'Tiles')
));
} else {
$this->add(
Link::create(
$this->translate('Tree'),
$url->with('mode', 'tree'),
null,
array(
'class' => 'icon-sitemap',
'title' => $this->translate('Switch to Tree view'),
)
)
);
$this->add(Html::tag(
'a',
[
'href' => $url->with('mode', 'tree'),
'title' => mt('businessprocess', 'Switch to Tree view'),
'class' => 'icon-sitemap'
],
mt('businessprocess', 'Tree')
));
}
$this->add(
Link::create(
$this->translate('Fullscreen'),
$url->with('showFullscreen', true),
null,
array(
'class' => 'icon-resize-full-alt',
'title' => $this->translate('Switch to fullscreen mode'),
'data-base-target' => '_main',
)
)
);
$this->add(Html::tag(
'a',
[
'data-base-target' => '_main',
'href' => $url->with('showFullscreen', true),
'title' => mt('businessprocess', 'Switch to fullscreen mode'),
'class' => 'icon-resize-full-alt'
],
mt('businessprocess', 'Fullscreen')
));
$hasChanges = $config->hasSimulations() || $config->hasBeenChanged();
if ($renderer->isLocked()) {
$this->add(
Link::create(
$this->translate('Editing locked'),
$url->with('unlocked', true),
null,
array(
'class' => 'icon-lock',
'title' => $this->translate('Click to unlock editing for this process'),
)
)
);
$this->add(Html::tag(
'a',
[
'href' => $url->with('unlocked', true),
'title' => mt('businessprocess', 'Click to unlock editing for this process'),
'class' => 'icon-lock'
],
mt('businessprocess', 'Editing locked')
));
} elseif (! $hasChanges) {
$this->add(
Link::create(
$this->translate('Editing unlocked'),
$url->without('unlocked')->without('action'),
null,
array(
'class' => 'icon-lock-open',
'title' => $this->translate('Click to lock editing for this process'),
)
)
);
$this->add(Html::tag(
'a',
[
'href' => $url->without('unlocked')->without('action'),
'title' => mt('businessprocess', 'Click to lock editing for this process'),
'class' => 'icon-lock-open'
],
mt('businessprocess', 'Editing unlocked')
));
}
if ($renderer->wantsRootNodes() && (
($hasChanges || (! $renderer->isLocked())) && $meta->canModify()
)) {
$this->add(
Link::create(
$this->translate('Config'),
'businessprocess/process/config',
$this->currentProcessParams($url),
array(
'class' => 'icon-wrench',
'title' => $this->translate('Modify this process'),
'data-base-target' => '_next',
)
)
);
if ($renderer->wantsRootNodes() && (($hasChanges || (! $renderer->isLocked())) && $meta->canModify())) {
$this->add(Html::tag(
'a',
[
'data-base-target' => '_next',
'href' => Url::fromPath('businessprocess/process/config', $this->currentProcessParams($url)),
'title' => mt('businessprocess', 'Modify this process'),
'class' => 'icon-wrench'
],
mt('businessprocess', 'Config')
));
}
}

View file

@ -2,8 +2,8 @@
namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Module\Businessprocess\Html\Renderable;
use ipl\Html\ValidHtml;
class Tabs extends WtfTabs implements Renderable
class Tabs extends WtfTabs implements ValidHtml
{
}

View file

@ -4,7 +4,6 @@ namespace Icinga\Module\Businessprocess\Web;
use Icinga\Application\Icinga;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Html\HtmlTag;
use Icinga\Module\Businessprocess\Modification\ProcessChanges;
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
use Icinga\Module\Businessprocess\Storage\Storage;
@ -16,6 +15,7 @@ use Icinga\Module\Businessprocess\Web\Form\FormLoader;
use Icinga\Web\Controller as ModuleController;
use Icinga\Web\Notification;
use Icinga\Web\View;
use ipl\Html\Html;
class Controller extends ModuleController
{
@ -86,9 +86,9 @@ class Controller extends ModuleController
protected function controls()
{
if ($this->view->controls === null) {
$controls = $this->view->controls = Controls::create();
$controls = $this->view->controls = new Controls();
if ($this->view->compact) {
$controls->attributes()->add('class', 'compact');
$controls->getAttributes()->add('class', 'compact');
}
}
@ -101,9 +101,9 @@ class Controller extends ModuleController
protected function content()
{
if ($this->view->content === null) {
$content = $this->view->content = Content::create();
$content = $this->view->content = new Content();
if ($this->view->compact) {
$content->attributes()->add('class', 'compact');
$content->getAttributes()->add('class', 'compact');
}
}
@ -187,7 +187,7 @@ class Controller extends ModuleController
$args = func_get_args();
array_shift($args);
$this->view->title = vsprintf($title, $args);
$this->controls()->add(HtmlTag::h1($this->view->title));
$this->controls()->add(Html::tag('h1', null, $this->view->title));
return $this;
}

View file

@ -4,10 +4,10 @@ namespace Icinga\Module\Businessprocess\Web\Form;
use Icinga\Application\Icinga;
use Icinga\Application\Modules\Module;
use Icinga\Module\Businessprocess\Html\Renderable;
use ipl\Html\ValidHtml;
use Zend_Form;
abstract class QuickBaseForm extends Zend_Form implements Renderable
abstract class QuickBaseForm extends Zend_Form implements ValidHtml
{
/**
* The Icinga module this form belongs to. Usually only set if the

View file

@ -1,150 +0,0 @@
<?php
namespace Tests\Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Html\Attribute;
use Icinga\Module\Businessprocess\Test\BaseTestCase;
class AttributeTest extends BaseTestCase
{
public function testCreatesFactoryCreatesAttribute()
{
$this->assertInstanceOf(
get_class(new Attribute('a', 'b')),
Attribute::create('a', 'b')
);
}
public function testKnowsItsName()
{
$a = new Attribute('target', '_blank');
$this->assertEquals(
'target',
$a->getName()
);
}
public function testKnowsItsValue()
{
$a = new Attribute('target', '_blank');
$this->assertEquals(
'_blank',
$a->getValue()
);
}
public function testItsValueCanBeModified()
{
$a = new Attribute('target', '_blank');
$a->setValue('_self');
$this->assertEquals(
'_self',
$a->getValue()
);
}
public function testPreservesComplexValues()
{
$a = new Attribute('special', 'süß "\'&');
$this->assertEquals(
'süß "\'&',
$a->getValue()
);
}
public function testAllowsToExtendItsValue()
{
$a = new Attribute('class', 'first');
$a->addValue('second');
$this->assertEquals(
array('first', 'second'),
$a->getValue()
);
$a->addValue('third');
$this->assertEquals(
array('first', 'second', 'third'),
$a->getValue()
);
$a->addValue(array('some', 'more'));
$this->assertEquals(
array('first', 'second', 'third', 'some', 'more'),
$a->getValue()
);
}
public function testAcceptsAndReturnsArrayValues()
{
$value = array('first', 'second', 'third');
$a = new Attribute('class', $value);
$this->assertEquals(
$value,
$a->getValue()
);
$value[] = 'forth';
$a->setValue($value);
$this->assertEquals(
$value,
$a->getValue()
);
}
public function testCorrectlyRendersItsName()
{
$a = new Attribute('class', 'test');
$this->assertEquals(
'class',
$a->renderName()
);
}
public function testCorrectlyRendersItsValue()
{
$a = new Attribute('href', '/some/url?a=b&c=d');
$this->assertEquals(
'/some/url?a=b&amp;c=d',
$a->renderValue()
);
}
public function testCorrectlyRendersArrayValues()
{
$a = new Attribute('weird', array('"sü?ß', '/some/url?a=b&c=d'));
$this->assertEquals(
'&quot;sü?ß /some/url?a=b&amp;c=d',
$a->renderValue()
);
}
public function testCorrectlyEscapesAName()
{
$this->assertEquals(
'class',
Attribute::escapeName('class')
);
}
public function testCorrectlyEscapesAValue()
{
$this->assertEquals(
"&quot;sü?ß' /some/url?a=b&amp;c=d",
Attribute::escapeValue('"sü?ß\' /some/url?a=b&c=d')
);
}
public function testRendersCorrectly()
{
$a = new Attribute('weird', array('"sü?ß', '/some/url?a=b&c=d'));
$this->assertEquals(
'weird="&quot;sü?ß /some/url?a=b&amp;c=d"',
$a->render()
);
}
}

View file

@ -1,111 +0,0 @@
<?php
namespace Tests\Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Html\Attribute;
use Icinga\Module\Businessprocess\Html\Attributes;
use Icinga\Module\Businessprocess\Test\BaseTestCase;
class AttributesTest extends BaseTestCase
{
public function testCanBeConstructedFromANormalArray()
{
$a = new Attributes(
array(
'class' => array('small', 'nice'),
'target' => '_blank'
)
);
$this->assertEquals(
' class="small nice" target="_blank"',
$a->render()
);
}
public function testCanBeInstantiatedThroughCreate()
{
$class = get_class(new Attributes());
$this->assertInstanceOf(
$class,
Attributes::create()
);
$this->assertInstanceOf(
$class,
Attributes::create(array('some' => 'attr'))
);
}
public function testCanBeCreatedForArrayOrNullOrAttributes()
{
$empty = Attributes::wantAttributes(null);
$this->assertEquals('', $empty->render());
$array = Attributes::wantAttributes(array('a' => 'b'));
$this->assertEquals(' a="b"', $array->render());
$attributes = Attributes::wantAttributes(
Attributes::create(array('a' => 'b'))
);
$this->assertEquals(' a="b"', $attributes->render());
}
public function testCanBeExtendedWithAnAttribute()
{
$a = Attributes::create();
$a->add(Attribute::create('a', 'b'));
$this->assertEquals(' a="b"', $a->render());
$a->add(Attribute::create('c', 'd'));
$this->assertEquals(' a="b" c="d"', $a->render());
$a->add(Attribute::create('a', 'c'));
$this->assertEquals(' a="b c" c="d"', $a->render());
}
public function testCanBeExtendedWithAttributes()
{
$a = Attributes::create();
$a->add(Attributes::create(array('a' => 'b')));
$this->assertEquals(' a="b"', $a->render());
$a->add(Attributes::create(
array(
'a' => 'c',
'c' => 'd'
)
));
$this->assertEquals(' a="b c" c="d"', $a->render());
}
public function testCanBeExtendedWithANameValuePair()
{
$a = Attributes::create();
$a->add('a', 'b');
$this->assertEquals(' a="b"', $a->render());
}
public function testAttributesCanBeReplacedWithAnAttribute()
{
$a = Attributes::create();
$a->add(Attribute::create('a', 'b'));
$a->set(Attribute::create('a', 'c'));
$this->assertEquals(' a="c"', $a->render());
}
public function testAttributesCanBeReplacedWithANameValuePair()
{
$a = Attributes::create();
$a->add(Attribute::create('a', 'b'));
$a->set('a', 'c');
$this->assertEquals(' a="c"', $a->render());
}
public function testCanBeConstructedAndRenderedEmpty()
{
$a = new Attributes();
$this->assertEquals('', $a->render());
}
}

View file

@ -1,18 +0,0 @@
<?php
namespace Tests\Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Html\HtmlTag;
use Icinga\Module\Businessprocess\Test\BaseTestCase;
class HtmlTagTest extends BaseTestCase
{
public function testHeaderIsRendered()
{
$h1 = HtmlTag::h1('Hea & der');
$this->assertEquals(
$h1->render(),
'<h1>Hea &amp; der</h1>'
);
}
}

View file

@ -1,42 +0,0 @@
<?php
namespace Tests\Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Html\Html;
use Icinga\Module\Businessprocess\Test\BaseTestCase;
class HtmlTest extends BaseTestCase
{
public function testContentIsRendered()
{
$h = new Html();
$h->setContent('Some content');
$this->assertEquals(
'Some content',
$h->render()
);
}
public function testContentCanBeExtended()
{
$h = new Html();
$h->setContent('Some content');
$h->addContent('More content');
$this->assertEquals(
'Some contentMore content',
$h->render()
);
}
public function testSeparatorsAreRespected()
{
$h = new Html();
$h->setContent('Some content');
$h->setSeparator(', and ');
$h->addContent('More content');
$this->assertEquals(
'Some content, and More content',
$h->render()
);
}
}

View file

@ -1,43 +0,0 @@
<?php
namespace Tests\Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Test\BaseTestCase;
class LinkTest extends BaseTestCase
{
public function testContentFromFactoryIsRendered()
{
$l = Link::create('Click here', 'go/some/where');
$this->assertEquals(
'Click here',
$l->renderContent()
);
}
public function testSimpleLinkRendersCorrectly()
{
$l = Link::create('Click here', 'go/some/where');
$this->assertEquals(
'<a href="/icingaweb2/go/some/where">Click here</a>',
$l->render()
);
}
public function testLinkWithParamsRendersCorrectly()
{
$l = Link::create(
'Click here',
'go/some/where',
array(
'with' => 'me',
'and' => 'aDog'
)
);
$this->assertEquals(
'<a href="/icingaweb2/go/some/where?with=me&amp;and=aDog">Click here</a>',
$l->render()
);
}
}

View file

@ -1,43 +0,0 @@
<?php
namespace Tests\Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Html\Text;
use Icinga\Module\Businessprocess\Test\BaseTestCase;
class TextTest extends BaseTestCase
{
public function testTextIsReturnedAsGiven()
{
$this->assertEquals(
'A & O',
Text::create('A & O')->getText()
);
}
public function testTextIsRenderedAsGivenWhenDeclaredBeingEscaped()
{
$this->assertEquals(
'A & O',
Text::create('A & O')->setEscaped()->render()
);
$this->assertEquals(
'A & O',
Text::create('A & O')->setEscaped(true)->render()
);
$this->assertEquals(
'A &amp; O',
Text::create('A & O')->setEscaped(false)->render()
);
}
public function testTextIsEscapedWhenRendered()
{
$this->assertEquals(
'A &amp; O',
Text::create('A & O')->render()
);
}
}

View file

@ -9,6 +9,8 @@ PHP_VERSION="$(php -r 'echo phpversion();')"
ICINGAWEB_VERSION=${ICINGAWEB_VERSION:=2.5.1}
ICINGAWEB_GITREF=${ICINGAWEB_GITREF:=}
IPL_VERSION=${IPL_VERSION:=0.1.1}
PHPCS_VERSION=${PHPCS_VERSION:=2.9.1}
if [ "$PHP_VERSION" '<' 5.6.0 ]; then
@ -52,6 +54,18 @@ fi
ln -svf "${icingaweb_path}"/library/Icinga
ln -svf "${icingaweb_path}"/library/vendor/Zend
# ipl
ipl_path="ipl"
if [ ! -d "$ipl_path" ]; then
git clone https://github.com/Icinga/icingaweb2-module-ipl.git "$ipl_path"
fi
(
set -e
cd "$ipl_path"
git fetch -p
git checkout -f "stable/$IPL_VERSION"
)
# phpunit
phpunit_path="phpunit-${PHPUNIT_VERSION}"
if [ ! -e "${phpunit_path}".phar ]; then