2013-10-09 11:43:53 +02:00
|
|
|
<?php
|
2016-08-11 01:14:02 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Admin\Tests;
|
|
|
|
|
2016-08-11 01:14:02 +02:00
|
|
|
use SilverStripe\Admin\CMSMenuItem;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
2013-10-09 11:43:53 +02:00
|
|
|
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="<something>"',
|
2016-08-11 01:40:23 +02:00
|
|
|
(string)$menuItem->getAttributesHTML($exampleAttributes),
|
2013-10-09 11:43:53 +02:00
|
|
|
'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(
|
|
|
|
'',
|
2016-08-11 01:40:23 +02:00
|
|
|
(string)$menuItem->getAttributesHTML('some string'),
|
2013-10-09 11:43:53 +02:00
|
|
|
'getAttributesHTML() ignores a string argument'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Set attributes as class property
|
|
|
|
$menuItem->setAttributes($exampleAttributes);
|
|
|
|
$this->assertEquals(
|
|
|
|
'title="foo bar" disabled="disabled" data-foo="<something>"',
|
2016-08-11 01:40:23 +02:00
|
|
|
(string)$menuItem->getAttributesHTML(),
|
2013-10-09 11:43:53 +02:00
|
|
|
'Attributes appear correctly when using setAttributes()'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
2016-08-11 01:40:23 +02:00
|
|
|
'title="foo bar" disabled="disabled"',
|
|
|
|
(string)$menuItem->getAttributesHTML('data-foo'),
|
2013-10-09 11:43:53 +02:00
|
|
|
'getAttributesHTML() ignores a string argument and falls back to class property'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|