mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-01-21 11:42:53 -05:00
tests: first tests for our HTML classes
This commit is contained in:
parent
ea7e79248c
commit
1f43d2c71c
4 changed files with 346 additions and 0 deletions
150
test/php/library/Businessprocess/Html/AttributeTest.php
Normal file
150
test/php/library/Businessprocess/Html/AttributeTest.php
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
<?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&c=d',
|
||||
$a->renderValue()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCorrectlyRendersArrayValues()
|
||||
{
|
||||
$a = new Attribute('weird', array('"sü?ß', '/some/url?a=b&c=d'));
|
||||
$this->assertEquals(
|
||||
'"sü?ß /some/url?a=b&c=d',
|
||||
$a->renderValue()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCorrectlyEscapesAName()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'class',
|
||||
Attribute::escapeName('class')
|
||||
);
|
||||
}
|
||||
|
||||
public function testCorrectlyEscapesAValue()
|
||||
{
|
||||
$this->assertEquals(
|
||||
""sü?ß' /some/url?a=b&c=d",
|
||||
Attribute::escapeValue('"sü?ß\' /some/url?a=b&c=d')
|
||||
);
|
||||
}
|
||||
|
||||
public function testRendersCorrectls()
|
||||
{
|
||||
$a = new Attribute('weird', array('"sü?ß', '/some/url?a=b&c=d'));
|
||||
$this->assertEquals(
|
||||
'weird=""sü?ß /some/url?a=b&c=d"',
|
||||
$a->render()
|
||||
);
|
||||
}
|
||||
}
|
||||
111
test/php/library/Businessprocess/Html/AttributesTest.php
Normal file
111
test/php/library/Businessprocess/Html/AttributesTest.php
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<?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());
|
||||
}
|
||||
}
|
||||
42
test/php/library/Businessprocess/Html/HtmlTest.php
Normal file
42
test/php/library/Businessprocess/Html/HtmlTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?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()
|
||||
);
|
||||
}
|
||||
}
|
||||
43
test/php/library/Businessprocess/Html/LinkTest.php
Normal file
43
test/php/library/Businessprocess/Html/LinkTest.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?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&and=aDog">Click here</a>',
|
||||
$l->render()
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue