Unit test coverage for CMSMenuItem

This commit is contained in:
Loz Calver 2013-10-09 10:43:53 +01:00
parent 55c6f35e15
commit c34167b0ec

View File

@ -0,0 +1,44 @@
<?php
/**
* @package framework
* @subpackage tests
*/
class CMSMenuItemTest extends SapphireTest {
public function testAttributes() {
$menuItem = new CMSMenuItem('Foo', 'foo');
$exampleAttributes = array('title' => 'foo bar', 'disabled' => true, 'data-foo' => '<something>');
$this->assertEquals(
'title="foo bar" disabled="disabled" data-foo="&lt;something&gt;"',
$menuItem->getAttributesHTML($exampleAttributes),
'Attributes appear correctly when passed as an argument'
);
$emptyAttributes = array('empty' => '');
$this->assertEquals(
'',
$menuItem->getAttributesHTML($emptyAttributes),
'No attributes are output when argument values are empty'
);
$this->assertEquals(
'',
$menuItem->getAttributesHTML('some string'),
'getAttributesHTML() ignores a string argument'
);
// Set attributes as class property
$menuItem->setAttributes($exampleAttributes);
$this->assertEquals(
'title="foo bar" disabled="disabled" data-foo="&lt;something&gt;"',
$menuItem->getAttributesHTML(),
'Attributes appear correctly when using setAttributes()'
);
$this->assertEquals(
'title="foo bar" disabled="disabled" data-foo="&lt;something&gt;"',
$menuItem->getAttributesHTML('foo bar'),
'getAttributesHTML() ignores a string argument and falls back to class property'
);
}
}