mockApplication();
}
public function testEncodeLabel()
{
$output = Menu::widget([
'route' => 'test/test',
'params' => [],
'encodeLabels' => true,
'items' => [
[
'encode' => false,
'label' => ' Users',
'url' => '#',
],
[
'encode' => true,
'label' => 'Authors & Publications',
'url' => '#',
],
]
]);
$expected = <<
Users
Authors & Publications
HTML;
$this->assertEqualsWithoutLE($expected, $output);
$output = Menu::widget([
'route' => 'test/test',
'params' => [],
'encodeLabels' => false,
'items' => [
[
'encode' => false,
'label' => ' Users',
'url' => '#',
],
[
'encode' => true,
'label' => 'Authors & Publications',
'url' => '#',
],
]
]);
$expected = << Users
Authors & Publications
HTML;
$this->assertEqualsWithoutLE($expected, $output);
}
/**
* @see https://github.com/yiisoft/yii2/issues/8064
*/
public function testTagOption()
{
$output = Menu::widget([
'route' => 'test/test',
'params' => [],
'encodeLabels' => true,
'options' => [
'tag' => false,
],
'items' => [
[
'label' => 'item1',
'url' => '#',
'options' => ['tag' => 'div'],
],
[
'label' => 'item2',
'url' => '#',
'options' => ['tag' => false],
],
]
]);
$expected = <<item1
item2
HTML;
$this->assertEqualsWithoutLE($expected, $output);
$output = Menu::widget([
'route' => 'test/test',
'params' => [],
'encodeLabels' => true,
'options' => [
'tag' => false,
],
'items' => [
[
'label' => 'item1',
'url' => '#',
],
[
'label' => 'item2',
'url' => '#',
],
],
'itemOptions' => ['tag' => false]
]);
$expected = <<item1
item2
HTML;
$this->assertEqualsWithoutLE($expected, $output);
}
public function testItemTemplate()
{
$output = Menu::widget([
'route' => 'test/test',
'params' => [],
'linkTemplate' => '',
'labelTemplate' => '',
'items' => [
[
'label' => 'item1',
'url' => '#',
'template' => 'label: {label}; url: {url}'
],
[
'label' => 'item2',
'template' => 'label: {label}'
],
[
'label' => 'item3 (no template)',
],
]
]);
$expected = <<label: item1; url: #
label: item2
HTML;
$this->assertEqualsWithoutLE($expected, $output);
}
}