/**
  * @param Navigation $navigation
  * @param Dispatcher $dispatcher
  * @return CommandResult
  */
 public function handle(Navigation $navigation, Dispatcher $dispatcher)
 {
     // check if user has permission
     if (!$this->disablePermissionChecking) {
         if (!$this->user->hasAnyPermission(['navigationBuilder.manage'])) {
             return new CommandResult(false, "Not enough permission.", null, 403);
         }
     }
     // fire before create event
     $dispatcher->fire('navigationBuilder.beforeQuery', array($this->args));
     if ($this->id && $this->id != '') {
         if (!($res = $navigation->with(array())->find($this->id))) {
             return new CommandResult(false, "Navigation does not exist.", null, 404);
         }
     } else {
         if ($this->paginated) {
             $res = $navigation->with(array())->paginate($this->perPage);
         } else {
             $res = $navigation->all();
         }
     }
     // fire after create
     $dispatcher->fire('navigationBuilder.afterQuery', array($this->args));
     // all good
     return new CommandResult(true, "List custom navigation command successful.", $res, 200);
 }
 public function testShouldUpdateNavigation()
 {
     $this->createUserAndLoggedIn(array('navigationBuilder.manage' => 1));
     $nav = $this->createDummyNavigation();
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\Navigation\\Commands\\UpdateNavigationCommand', array('id' => $nav->id, 'name' => 'main navigation updated', 'data' => array(array('title' => 'home', 'attr' => array('class' => 'some-class', 'id' => 'some-id'), 'url' => 'http://www.url.com', 'items' => []), array('title' => 'about', 'attr' => array('class' => 'some-class', 'id' => 'some-id'), 'url' => 'http://www.url.com/about', 'items' => []))));
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals('Navigation successfully updated.', $result->getMessage());
     // prove the data has been changed/updated
     $updatedNav = Navigation::all()->first();
     $this->assertEquals('main navigation updated', $updatedNav->name);
     $this->assertCount(2, $updatedNav->data);
 }
 public function testShouldNowCreateIfAllCheckPointPassed()
 {
     $user = $this->createUserAndLoggedIn(array('navigationBuilder.manage' => 1));
     $result = $this->commandDispatcher->dispatchFromArray('Darryldecode\\Backend\\Components\\Navigation\\Commands\\CreateNavigationCommand', array('name' => 'SomeNavigationName', 'data' => array('title' => 'home', 'class' => 'some-class', 'url' => 'www.url.com', 'items' => [])));
     $this->assertTrue($result->isSuccessful(), "Command should be a success.");
     $this->assertEquals(201, $result->getStatusCode(), "Status code should be created.");
     $this->assertEquals('Navigation successfully created.', $result->getMessage());
     // prove that nav exist
     $this->assertCount(1, Navigation::all()->toArray());
     $this->assertEquals('SomeNavigationName', Navigation::all()->first()->name);
     $this->assertInternalType('array', Navigation::all()->first()->data);
 }