forked from artkonekt/menu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Menu has been renamed to Repository, tests have been added
- Loading branch information
1 parent
feb171d
commit 33cfe95
Showing
9 changed files
with
220 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
/** | ||
* Contains the MenuAlreadyExistsException class. | ||
* | ||
* @copyright Copyright (c) 2017 Attila Fulop | ||
* @author Attila Fulop | ||
* @license MIT | ||
* @since 2017-06-16 | ||
* | ||
*/ | ||
|
||
|
||
namespace Konekt\Menu\Exceptions; | ||
|
||
|
||
class MenuAlreadyExistsException extends \Exception | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* Contains the FacadeTest class. | ||
* | ||
* @copyright Copyright (c) 2017 Attila Fulop | ||
* @author Attila Fulop | ||
* @license MIT | ||
* @since 2017-06-16 | ||
* | ||
*/ | ||
|
||
|
||
namespace Konekt\Menu\Tests\Feature; | ||
|
||
|
||
use Konekt\Menu\Builder; | ||
use Konekt\Menu\Tests\TestCase; | ||
use Menu; | ||
|
||
class FacadeTest extends TestCase | ||
{ | ||
public function testMenuCanBeCreatedWithFacade() | ||
{ | ||
$navbar = Menu::create('navbar', function($menu) { | ||
$menu->add('Home'); | ||
}); | ||
|
||
$this->assertInstanceOf(Builder::class, $navbar); | ||
$this->assertCount(1, $navbar->items); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Contains the TestCase class. | ||
* | ||
* @copyright Copyright (c) 2017 Attila Fulop | ||
* @author Attila Fulop | ||
* @license MIT | ||
* @since 2017-06-16 | ||
* | ||
*/ | ||
|
||
|
||
namespace Konekt\Menu\Tests; | ||
|
||
|
||
use Konekt\Menu\Facades\Menu; | ||
use Konekt\Menu\MenuServiceProvider; | ||
use Orchestra\Testbench\TestCase as OrchestraTestCase; | ||
use Illuminate\Foundation\AliasLoader; | ||
|
||
abstract class TestCase extends OrchestraTestCase | ||
{ | ||
/** | ||
* @param \Illuminate\Foundation\Application $app | ||
* | ||
* @return array | ||
*/ | ||
protected function getPackageProviders($app) | ||
{ | ||
return [ | ||
MenuServiceProvider::class | ||
]; | ||
} | ||
|
||
/** | ||
* Set up the environment. | ||
* | ||
* @param \Illuminate\Foundation\Application $app | ||
*/ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
// Register the facade | ||
AliasLoader::getInstance()->alias('Menu', Menu::class); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* Contains the SmokeTest class. | ||
* | ||
* @copyright Copyright (c) 2017 Attila Fulop | ||
* @author Attila Fulop | ||
* @license MIT | ||
* @since 2017-06-16 | ||
* | ||
*/ | ||
|
||
|
||
namespace Konekt\Menu\Tests\Unit; | ||
|
||
|
||
use Konekt\Menu\Exceptions\MenuAlreadyExistsException; | ||
use Konekt\Menu\Repository; | ||
use Konekt\Menu\Tests\TestCase; | ||
|
||
class RepositoryTest extends TestCase | ||
{ | ||
/** @var Repository */ | ||
protected $repo; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->repo = new Repository(); | ||
} | ||
|
||
public function testEmptyMenuCanBeCreated() | ||
{ | ||
$sidebar = $this->repo->create('sidebar'); | ||
|
||
$this->assertNotNull($sidebar); | ||
$this->assertCount(0, $sidebar->items); | ||
} | ||
|
||
public function testMenuCanBeCreatedWithItemsInClosure() | ||
{ | ||
$sidebar = $this->repo->create('sidebar', function ($menu) { | ||
$menu->add('Home', 'home'); | ||
$menu->add('Somewhere else', 'somewhere-else'); | ||
}); | ||
|
||
$this->assertCount(2, $sidebar->items); | ||
} | ||
|
||
public function testMenuCanBeRetrievedByKey() | ||
{ | ||
$this->repo->create('sidebar', function ($menu) { | ||
$menu->add('Moscow', 'moscow'); | ||
$menu->add('Tallin', 'tallin'); | ||
$menu->add('Göteborg', 'goteborg'); | ||
}); | ||
|
||
$sidebar = $this->repo->get('sidebar'); | ||
$this->assertNotNull($sidebar); | ||
$this->assertCount(3, $sidebar->items); | ||
} | ||
|
||
public function testNonExistentEntryReturnsNull() | ||
{ | ||
$this->assertNull($this->repo->get('I do not exist')); | ||
} | ||
|
||
public function testMenusWithSameNameCantBeCreated() | ||
{ | ||
$this->repo->create('i_am_unique'); | ||
$this->expectException(MenuAlreadyExistsException::class); | ||
$this->repo->create('i_am_unique'); | ||
} | ||
|
||
public function testAllActuallyReturnsAll() | ||
{ | ||
$this->repo->create('splash'); | ||
$this->repo->create('bang'); | ||
$this->repo->create('pow'); | ||
$this->repo->create('phitang'); | ||
|
||
$this->assertCount(4, $this->repo->all()); | ||
|
||
$this->assertArrayHasKey('splash', $this->repo->all()->all()); | ||
$this->assertArrayHasKey('bang', $this->repo->all()->all()); | ||
$this->assertArrayHasKey('pow', $this->repo->all()->all()); | ||
$this->assertArrayHasKey('phitang', $this->repo->all()->all()); | ||
} | ||
|
||
} |
Oops, something went wrong.