Skip to content
This repository was archived by the owner on Feb 9, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions app/Modules/Navigation/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use App\Model\Menu;
use Illuminate\Http\Request;
use App\Modules\ModuleEngine;
use Illuminate\Validation\Rule;
use Illuminate\Http\RedirectResponse;
use App\Classes\Repositories\LinkRepository;
use App\Classes\Repositories\MenuRepository;
use App\Classes\Repositories\PageRepository;
Expand Down Expand Up @@ -80,13 +80,11 @@ public function create()
* External or Internal Hyperlinks and connections.
*
* @param Menu $menu
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
* @param Request $request
* @return RedirectResponse
*/
public function store(Request $request, Menu $menu)
{
$request->validate(['title' => 'min:3|max:255|unique:menus,title,NULL,id,deleted_at,NULL|required']);

$this->save($request, $menu);

return redirect()->route('admin.navigation.index');
Expand Down Expand Up @@ -125,8 +123,6 @@ public function edit($id)
*/
public function update(Request $request, $id)
{
$request->validate(['title' => ['min:3|max:255|required', Rule::unique('menus')->ignore($id)]]);

$menu = $this->menus->whereID($id);

$this->save($request, $menu);
Expand Down Expand Up @@ -185,7 +181,9 @@ public function reorder(Request $request)
*/
private function save(Request $request, Menu $menu)
{
$this->validate($request, ['title => required|min:3|max:255']);
$this->validate($request, [
'title' => 'min:3|max:255|required|unique:menus,title,NULL,id,deleted_at,NULL',
]);

DB::transaction(function () use ($request, $menu) {
if ($request['linkable_object']) {
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.0"
"phpunit/phpunit": "^7.0",
"ext-json": "*"
},
"autoload": {
"files": [
Expand Down
67 changes: 67 additions & 0 deletions tests/Navigation/NavigationBackendTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Tests\Modules;

use Carbon\Carbon;
use App\Model\Menu;
use App\Model\Page;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

/**
* Class NavigationBackendTest.
*/
class NavigationBackendTest extends TestCase
{
use RefreshDatabase;

/**
* @test
*/
public function it_can_use_a_title_of_an_already_used_title_once_deleted(): void
{
$this->signIn();

// create a menu that has been deleted.
$menu = factory(Menu::class)->create(['title' => 'foo', 'deleted_at' => Carbon::now()->timestamp]);

// create a new page for the new menu
$new_page = factory(Page::class)->create();

// encode to json for creation of a new link model
$encoding = json_encode(['key' => $new_page->id, 'class' => $new_page->getMorphClass()]);

// generate teh new menu with the encoding
$new_menu = factory(Menu::class)->make(['title' => 'foo', 'linkable_object' => $encoding]);

// get a request from the dashboard once passing the model to the url.
$request = $this->post('/admin/navigation/', $new_menu->toArray());

// make sure the database has the new menu added.
$this->assertDatabaseHas('menus', ['title' => 'foo', 'page_id' => $new_menu->page->id]);
}

/**
* @test
*/
public function it_can_change_the_title_to_an_already_used_title_that_was_removed() : void
{
$this->signIn();

// A menu that has been deleted.
$menu = factory(Menu::class)->create(['title' => 'foo', 'deleted_at' => Carbon::now()->timestamp]);

// the current menu to be changed
/** @var Menu $current_menu */
$current_menu = factory(Menu::class)->create(['title' => 'bar']);

// set its title back to foo.
$current_menu->setAttribute('title', 'foo');

// send the new menu as a
$request = $this->patch("/admin/navigation/{$current_menu->id}", $current_menu->toArray());

// assert the database has the changed details.
$this->assertDatabaseHas('menus', ['title' => 'foo', 'id' => $current_menu->getKey()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Class NavigationTest.
*/
class NavigationTest extends TestCase
class NavigationModelTest extends TestCase
{
/**
* @test
Expand Down