Skip to content

Commit

Permalink
Update test for navbar.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikaël Capelle committed Feb 8, 2017
1 parent 9ec77ae commit d0abcb6
Showing 1 changed file with 82 additions and 1 deletion.
83 changes: 82 additions & 1 deletion tests/TestCase/View/Helper/BootstrapNavbarHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function testText() {

public function testMenu() {
// TODO: Add test for this...
$this->navbar->autoActiveLink = false;
$this->navbar->config('autoActiveLink', false);
// Basic test:
$this->navbar->create(null);
$result = $this->navbar->beginMenu(['class' => 'my-menu']);
Expand Down Expand Up @@ -304,4 +304,85 @@ public function testMenu() {
// TODO: Add more tests...
}

public function testAutoButtonLink() {
$this->navbar->create(null);

// Active and outside a menu:
$this->navbar->config('autoButtonLink', true);
$result = $this->navbar->link('Button', '/');
$expected = [
['a' => ['href' => '/', 'class' => 'navbar-btn btn btn-default']],
'Button', '/a'
];
$this->assertHtml($expected, $result);

// Inactive and outside a menu:
$this->navbar->config('autoButtonLink', false);
$result = $this->navbar->link('Link', '/');
$expected = [
['li' => ['class' => 'active']],
['a' => ['href' => '/']], 'Link', '/a',
'/li'
];
$this->assertHtml($expected, $result);

// Active and inside a menu:
$this->navbar->config('autoButtonLink', true);
$this->navbar->beginMenu('');
$result = $this->navbar->link('Link', '/');
$expected = [
['li' => ['class' => 'active']],
['a' => ['href' => '/']], 'Link', '/a',
'/li'
];
$this->assertHtml($expected, $result);

}

public function testAutoActiveLink() {
$this->navbar->create(null);
$this->navbar->beginMenu('');

// Active and correct link:
$this->navbar->config('autoActiveLink', true);
$result = $this->navbar->link('Link', '/');
$expected = [
['li' => ['class' => 'active']],
['a' => ['href' => '/']], 'Link', '/a',
'/li'
];
$this->assertHtml($expected, $result);

// Active and incorrect link but more complex:
$this->navbar->config('autoActiveLink', true);
$result = $this->navbar->link('Link', '/pages');
$expected = [
['li' => []],
['a' => ['href' => '/pages']], 'Link', '/a',
'/li'
];
$this->assertHtml($expected, $result);

// Unactive and correct link:
$this->navbar->config('autoActiveLink', false);
$result = $this->navbar->link('Link', '/');
$expected = [
['li' => []],
['a' => ['href' => '/']], 'Link', '/a',
'/li'
];
$this->assertHtml($expected, $result);

// Unactive and incorrect link:
$this->navbar->config('autoActiveLink', false);
$result = $this->navbar->link('Link', '/pages');
$expected = [
['li' => []],
['a' => ['href' => '/pages']], 'Link', '/a',
'/li'
];
$this->assertHtml($expected, $result);

}

};

0 comments on commit d0abcb6

Please sign in to comment.