2017-02-15 13:08:17 -05:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
2017-02-15 16:13:32 -05:00
|
|
|
* Hummingbird Anime List Client
|
2017-02-15 13:08:17 -05:00
|
|
|
*
|
2018-08-22 13:48:27 -04:00
|
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
2017-02-15 13:08:17 -05:00
|
|
|
*
|
2019-12-03 15:17:25 -05:00
|
|
|
* PHP version 7.2
|
2017-02-15 13:08:17 -05:00
|
|
|
*
|
2017-02-15 16:13:32 -05:00
|
|
|
* @package HummingbirdAnimeClient
|
2017-02-15 13:08:17 -05:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2018-01-15 14:43:15 -05:00
|
|
|
* @copyright 2015 - 2018 Timothy J. Warren
|
2017-02-15 13:08:17 -05:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2018-10-01 11:35:51 -04:00
|
|
|
* @version 4.1
|
2017-03-07 20:53:58 -05:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
2017-02-15 13:08:17 -05:00
|
|
|
*/
|
2015-10-21 11:57:58 -04:00
|
|
|
|
2017-02-22 15:08:29 -05:00
|
|
|
namespace Aviat\AnimeClient\Tests\Helper;
|
2017-02-15 11:49:38 -05:00
|
|
|
|
2015-10-21 11:57:58 -04:00
|
|
|
use Aviat\AnimeClient\Helper\Menu as MenuHelper;
|
2017-02-22 15:08:29 -05:00
|
|
|
use Aviat\AnimeClient\Tests\AnimeClientTestCase;
|
2015-10-21 11:57:58 -04:00
|
|
|
|
2017-02-15 16:40:18 -05:00
|
|
|
class MenuHelperTest extends AnimeClientTestCase {
|
2017-02-22 15:08:29 -05:00
|
|
|
|
|
|
|
protected $helper;
|
|
|
|
protected $urlGenerator;
|
2015-10-21 11:57:58 -04:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->helper = $this->container->get('html-helper');
|
|
|
|
$this->urlGenerator = $this->container->get('url-generator');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoke()
|
|
|
|
{
|
|
|
|
$menus = [
|
|
|
|
'no selection' => [
|
|
|
|
'route_prefix' => '/foo',
|
|
|
|
'items' => [
|
|
|
|
'bar' => '/bar'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'selected' => [
|
|
|
|
'route_prefix' => '',
|
|
|
|
'items' => [
|
|
|
|
'index' => '/foobar'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$expected = [];
|
|
|
|
|
|
|
|
// No selection
|
|
|
|
$link = $this->helper->a($this->urlGenerator->url('/foo/bar'), 'Bar');
|
|
|
|
$this->helper->ul()->rawItem($link);
|
|
|
|
$expected['no selection'] = $this->helper->ul()->__toString();
|
|
|
|
|
|
|
|
// selected
|
|
|
|
$link = $this->helper->a($this->urlGenerator->url('/foobar'), 'Index');
|
|
|
|
$this->helper->ul()->rawItem($link, ['class' => 'selected']);
|
|
|
|
$expected['selected'] = $this->helper->ul()->__toString();
|
|
|
|
|
|
|
|
// Set config for tests
|
|
|
|
$config = $this->container->get('config');
|
|
|
|
$config->set('menus', $menus);
|
2016-08-29 15:36:36 -04:00
|
|
|
$this->container->setInstance('config', $config);
|
2015-10-21 11:57:58 -04:00
|
|
|
|
|
|
|
foreach($menus as $case => $config)
|
|
|
|
{
|
|
|
|
if ($case === 'selected')
|
|
|
|
{
|
|
|
|
$this->setSuperGlobals([
|
|
|
|
'_SERVER' => [
|
|
|
|
'HTTP_HOST' => 'localhost',
|
|
|
|
'REQUEST_URI' => '/foobar'
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->setSuperGlobals([
|
|
|
|
'_SERVER' => [
|
|
|
|
'HTTP_HOST' => 'localhost',
|
|
|
|
'REQUEST_URI' => '/applesauceisgreat'
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$helper = new MenuHelper();
|
|
|
|
$helper->setContainer($this->container);
|
|
|
|
$this->assertEquals($expected[$case], (string)$helper($case));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|