CMSMenuItemTest.php
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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="<something>"',
			$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="<something>"',
			$menuItem->getAttributesHTML(),
			'Attributes appear correctly when using setAttributes()'
		);
		$this->assertEquals(
			'title="foo bar" disabled="disabled" data-foo="<something>"',
			$menuItem->getAttributesHTML('foo bar'),
			'getAttributesHTML() ignores a string argument and falls back to class property'
		);
	}
}