Skip to content

Commit

Permalink
Merge pull request #161 from kontenta/laravel7
Browse files Browse the repository at this point in the history
Update for use with Laravel 7
  • Loading branch information
erik-epineer authored Mar 20, 2020
2 parents 59ebf45 + 7479978 commit b3bdb12
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 38 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ matrix:
env: LARAVEL='6.*'
- php: 7.3
env: LARAVEL='6.*'
- php: 7.3
env: LARAVEL='7.*'
- php: 7.4
env: LARAVEL='7.*'
fast_finish: true

services:
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"description": "Admin area tool utilities for Laravel",
"license": "MIT",
"require": {
"laravel/framework": "5.8.* || ^6.0"
"laravel/framework": "5.8.* || ^6.0 || ^7.0",
"laravel/ui": "^1.0 || ^2.0"
},
"require-dev": {
"mockery/mockery": "^1.2",
"orchestra/testbench-dusk": "3.8.2 || ^4.0.1",
"orchestra/testbench-dusk": "3.8.2 || ^4.0.1 || ^5.0",
"squizlabs/php_codesniffer": "^3.3",
"timacdonald/log-fake": "^1.0"
},
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/AdminVisitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function setUp(): void
{
parent::setUp();
$this->prepareDatabase();
$this->user = factory(User::class)->create();
$this->user = factory(User::class)->create()->fresh();
}

public function test_can_be_serialized_and_deserialized()
Expand All @@ -30,6 +30,6 @@ public function test_can_be_serialized_and_deserialized()
$visit->__wakeup(); // Restore any serialized models on the original object
$unserializedVisit = unserialize($serializedVisit);

$this->assertEquals($visit, $unserializedVisit, "Unserialization did not produce the orginal object structure");
$this->assertEquals($visit, $unserializedVisit, "Unserialization did not produce the original object structure");
}
}
4 changes: 2 additions & 2 deletions tests/Feature/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public function test_admin_user_account_widget()
{
$routeManager = $this->app->make(\Kontenta\Kontour\Contracts\AdminRouteManager::class);
$response = $this->actingAs($this->user, 'admin')->get($routeManager->indexUrl());
$response->assertSee('<section data-kontour-widget="userAccount">');
$response->assertSee('<section data-kontour-widget="userAccount">', false);
$response->assertSee($this->user->getDisplayName());
$response->assertSee(">Logout</span>\n</button>");
$response->assertSee(">Logout</span>\n</button>", false);
}

public function test_logout()
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/AuthorizesWithAbilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function setUp(): void
{
parent::setUp();
$this->prepareDatabase();
$this->user = factory(User::class)->create();
$this->user = factory(User::class)->create()->fresh();

Gate::define('testGate', function ($user, $argument) {
return $user->id == $argument->id;
Expand Down Expand Up @@ -67,6 +67,6 @@ public function test_can_be_serialized_and_deserialized()
$unserializedLink = unserialize($serializedLink);

$this->assertTrue($unserializedLink->isAuthorized($this->user));
$this->assertEquals($link, $unserializedLink, "Unserialization did not produce the orginal object structure");
$this->assertEquals($link, $unserializedLink, "Unserialization did not produce the original object structure");
}
}
60 changes: 30 additions & 30 deletions tests/Feature/UserlandControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public function test_index_route()
$response = $this->actingAs($this->user, 'admin')->get(route('userland.index'));

$response->assertSuccessful();
$response->assertSee('<main');
$response->assertSee('<main', false);
$response->assertSee('UserlandAdminWidget');
$response->assertDontSee('UnauthorizedWidget');

Event::assertDispatched(AdminToolVisited::class, function ($e) {
$now = new \DateTimeImmutable();
return $e->visit->getLink()->getUrl() == route('userland.index') and
$this->user->is($e->visit->getUser()) and
$now->getTimestamp() - $e->visit->getDateTime()->getTimestamp() >= 0;
$this->user->is($e->visit->getUser()) and
$now->getTimestamp() - $e->visit->getDateTime()->getTimestamp() >= 0;
});
}

Expand All @@ -53,11 +53,11 @@ public function test_menu_widget()
$response = $this->actingAs($this->user, 'admin')->get(route('userland.index'));

$response->assertSuccessful();
$response->assertSee('<ul data-kontour-widget="menu">');
$response->assertSee('>main<');
$response->assertSee('<a href="' . route('userland.index') . '" aria-current="page">Userland Tool</a>');
$response->assertSee('>External<');
$response->assertSee('<a href="http://external.com">External Link</a>');
$response->assertSee('<ul data-kontour-widget="menu">', false);
$response->assertSee('>main<', false);
$response->assertSee('<a href="' . route('userland.index') . '" aria-current="page">Userland Tool</a>', false);
$response->assertSee('>External<', false);
$response->assertSee('<a href="http://external.com">External Link</a>', false);
}

public function test_recent_visits_widgets()
Expand All @@ -80,8 +80,8 @@ public function test_recent_visits_widgets()
$response->assertSuccessful();

// Check personal links
$response->assertSee('<aside data-kontour-widget="personalRecentVisits">');
$response->assertSee('<header>Recent</header>');
$response->assertSee('<aside data-kontour-widget="personalRecentVisits">', false);
$response->assertSee('<header>Recent</header>', false);

$numberOfMatches = substr_count($response->content(), '<li data-kontour-visit-type="show" title="Recent Userland Tool"><a href="' . route('userland.index') . '" aria-current="page">Recent Userland Tool</a>');
$this->assertEquals(0, $numberOfMatches);
Expand All @@ -90,57 +90,57 @@ public function test_recent_visits_widgets()
$this->assertEquals(1, $numberOfMatches);

// Check team links
$response->assertSee('<aside data-kontour-widget="teamRecentVisits">');
$response->assertSee('<header>Team Recent</header>');
$response->assertSee('<aside data-kontour-widget="teamRecentVisits">', false);
$response->assertSee('<header>Team Recent</header>', false);

$numberOfMatches = substr_count($response->content(), '<li data-kontour-visit-type="edit" data-kontour-username="' . $otherUser->getDisplayName() . '" title="Other Recent Userland Tool"><a href="' . route('userland.edit', 1) . '">Other Recent Userland Tool</a>');
$this->assertEquals(1, $numberOfMatches);

$response->assertDontSee('<a href="' . route('userland.index') . '">Other Recent Userland Tool</a>');
$response->assertDontSee('<a href="' . route('userland.index') . '">Other Recent Userland Tool</a>', false);
}

public function test_item_history_widget()
{
$response = $this->actingAs($this->user, 'admin')->get(route('userland.edit', 1));

$response->assertSuccessful();
$response->assertSee('<section data-kontour-widget="itemHistory">');
$response->assertSee('<header>Item History</header>');
$response->assertSee('<li lang="en" data-kontour-entry-action="created" data-kontour-username="' . $this->user->getDisplayName() . '">');
$response->assertSee('<li lang="en" data-kontour-entry-action="updated" data-kontour-username="' . $this->user->getDisplayName() . '">');
$response->assertSee('<section data-kontour-widget="itemHistory">', false);
$response->assertSee('<header>Item History</header>', false);
$response->assertSee('<li lang="en" data-kontour-entry-action="created" data-kontour-username="' . $this->user->getDisplayName() . '">', false);
$response->assertSee('<li lang="en" data-kontour-entry-action="updated" data-kontour-username="' . $this->user->getDisplayName() . '">', false);
}

public function test_crumbtrail_widget()
{
$response = $this->actingAs($this->user, 'admin')->get(route('userland.edit', 1));

$response->assertSuccessful();
$response->assertSee('<nav aria-label="Crumb trail" data-kontour-widget="crumbtrail">');
$response->assertSee('<a href="' . route('userland.index') . '">1</a>');
$response->assertSee('<li aria-current="true"><a href="' . route('userland.edit', 1) . '" aria-current="page">2</a>');
$response->assertSee('<nav aria-label="Crumb trail" data-kontour-widget="crumbtrail">', false);
$response->assertSee('<a href="' . route('userland.index') . '">1</a>', false);
$response->assertSee('<li aria-current="true"><a href="' . route('userland.edit', 1) . '" aria-current="page">2</a>', false);
}

public function test_message_widget()
{
$response = $this->actingAs($this->user, 'admin')->get(route('userland.edit', 1));

$response->assertSuccessful();
$response->assertSee('<section data-kontour-widget="message">');
$response->assertSeeInOrder(['<li', 'data-kontour-message-level="info"', 'role="status"', '>Hello World!</li>']);
$response->assertSee('<section data-kontour-widget="message">', false);
$response->assertSeeInOrder(['<li', 'data-kontour-message-level="info"', 'role="status"', '>Hello World!</li>'], false);
}

public function test_css_and_js_additions()
{
$response = $this->actingAs($this->user, 'admin')->get(route('userland.index'));

$response->assertSuccessful();
$response->assertSee('<link href="' . url('admin.css') . '" rel="stylesheet">');
$response->assertSee('<link href="' . url('userland.css') . '" rel="stylesheet">');
$response->assertSee('<link href="' . url('userland-index.css') . '" rel="stylesheet">');

$response->assertSee('<script src="https://cdn.example.com/framework.js"></script>');
$response->assertSee('<script src="' . url('admin.js') . '"></script>');
$response->assertSee('<script src="' . url('userland.js') . '"></script>');
$response->assertSee('<script src="' . url('userland-index.js') . '"></script>');
$response->assertSee('<link href="' . url('admin.css') . '" rel="stylesheet">', false);
$response->assertSee('<link href="' . url('userland.css') . '" rel="stylesheet">', false);
$response->assertSee('<link href="' . url('userland-index.css') . '" rel="stylesheet">', false);

$response->assertSee('<script src="https://cdn.example.com/framework.js"></script>', false);
$response->assertSee('<script src="' . url('admin.js') . '"></script>', false);
$response->assertSee('<script src="' . url('userland.js') . '"></script>', false);
$response->assertSee('<script src="' . url('userland-index.js') . '"></script>', false);
}
}

0 comments on commit b3bdb12

Please sign in to comment.