diff --git a/composer.json b/composer.json index 8d4979b..70ee27f 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "laravel/sail": "^1.0.1", "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^6.1", + "pestphp/pest-plugin-laravel": "^1.2", "phpunit/phpunit": "^9.5.10", "spatie/laravel-ignition": "^1.0" }, @@ -57,7 +58,10 @@ "config": { "optimize-autoloader": true, "preferred-install": "dist", - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true + } }, "minimum-stability": "dev", "prefer-stable": true diff --git a/composer.lock b/composer.lock index 516f773..3a670e3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "12524947d8c752f84bc21aaaede06bfa", + "content-hash": "cb04fd9a53709c6f2ef827bfaf387e82", "packages": [ { "name": "brick/math", @@ -5672,6 +5672,261 @@ ], "time": "2022-04-05T15:31:38+00:00" }, + { + "name": "pestphp/pest", + "version": "v1.21.2", + "source": { + "type": "git", + "url": "https://github.com/pestphp/pest.git", + "reference": "63f009fadf9b37f611fda43928d03336475d5d9f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pestphp/pest/zipball/63f009fadf9b37f611fda43928d03336475d5d9f", + "reference": "63f009fadf9b37f611fda43928d03336475d5d9f", + "shasum": "" + }, + "require": { + "nunomaduro/collision": "^5.10.0|^6.0", + "pestphp/pest-plugin": "^1.0.0", + "php": "^7.3 || ^8.0", + "phpunit/phpunit": "^9.5.5" + }, + "require-dev": { + "illuminate/console": "^8.47.0", + "illuminate/support": "^8.47.0", + "laravel/dusk": "^6.15.0", + "pestphp/pest-dev-tools": "dev-master", + "pestphp/pest-plugin-parallel": "^1.0" + }, + "bin": [ + "bin/pest" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "pest": { + "plugins": [ + "Pest\\Plugins\\Coverage", + "Pest\\Plugins\\Init", + "Pest\\Plugins\\Version", + "Pest\\Plugins\\Environment" + ] + }, + "laravel": { + "providers": [ + "Pest\\Laravel\\PestServiceProvider" + ] + } + }, + "autoload": { + "files": [ + "src/Functions.php", + "src/Pest.php" + ], + "psr-4": { + "Pest\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "An elegant PHP Testing Framework.", + "keywords": [ + "framework", + "pest", + "php", + "test", + "testing", + "unit" + ], + "support": { + "issues": "https://github.com/pestphp/pest/issues", + "source": "https://github.com/pestphp/pest/tree/v1.21.2" + }, + "funding": [ + { + "url": "https://www.paypal.com/paypalme/enunomaduro", + "type": "custom" + }, + { + "url": "https://github.com/lukeraymonddowning", + "type": "github" + }, + { + "url": "https://github.com/nunomaduro", + "type": "github" + }, + { + "url": "https://github.com/octoper", + "type": "github" + }, + { + "url": "https://github.com/olivernybroe", + "type": "github" + }, + { + "url": "https://github.com/owenvoke", + "type": "github" + }, + { + "url": "https://www.patreon.com/nunomaduro", + "type": "patreon" + } + ], + "time": "2022-03-05T19:34:40+00:00" + }, + { + "name": "pestphp/pest-plugin", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/pestphp/pest-plugin.git", + "reference": "fc8519de148699fe612d9c669be60554cd2db4fa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pestphp/pest-plugin/zipball/fc8519de148699fe612d9c669be60554cd2db4fa", + "reference": "fc8519de148699fe612d9c669be60554cd2db4fa", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.1 || ^2.0", + "php": "^7.3 || ^8.0" + }, + "conflict": { + "pestphp/pest": "<1.0" + }, + "require-dev": { + "composer/composer": "^1.10.19", + "pestphp/pest": "^1.0", + "pestphp/pest-dev-tools": "dev-master" + }, + "type": "composer-plugin", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "class": "Pest\\Plugin\\Manager" + }, + "autoload": { + "psr-4": { + "Pest\\Plugin\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "The Pest plugin manager", + "keywords": [ + "framework", + "manager", + "pest", + "php", + "plugin", + "test", + "testing", + "unit" + ], + "support": { + "source": "https://github.com/pestphp/pest-plugin/tree/v1.0.0" + }, + "funding": [ + { + "url": "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L", + "type": "custom" + }, + { + "url": "https://github.com/nunomaduro", + "type": "github" + }, + { + "url": "https://www.patreon.com/nunomaduro", + "type": "patreon" + } + ], + "time": "2021-01-03T15:53:42+00:00" + }, + { + "name": "pestphp/pest-plugin-laravel", + "version": "v1.2.0", + "source": { + "type": "git", + "url": "https://github.com/pestphp/pest-plugin-laravel.git", + "reference": "64996218006570f6f58f3c7ebb6f0c7bfb3c60b9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pestphp/pest-plugin-laravel/zipball/64996218006570f6f58f3c7ebb6f0c7bfb3c60b9", + "reference": "64996218006570f6f58f3c7ebb6f0c7bfb3c60b9", + "shasum": "" + }, + "require": { + "laravel/framework": "^7.0 || ^8.0 || ^9.0", + "pestphp/pest": "^1.7", + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "orchestra/testbench": "^5.12.1 || ^6.7.2", + "pestphp/pest-dev-tools": "dev-master" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "files": [ + "src/Autoload.php" + ], + "psr-4": { + "Pest\\Laravel\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "The Pest Laravel Plugin", + "keywords": [ + "framework", + "laravel", + "pest", + "php", + "test", + "testing", + "unit" + ], + "support": { + "source": "https://github.com/pestphp/pest-plugin-laravel/tree/v1.2.0" + }, + "funding": [ + { + "url": "https://www.paypal.com/paypalme/enunomaduro", + "type": "custom" + }, + { + "url": "https://github.com/nunomaduro", + "type": "github" + }, + { + "url": "https://www.patreon.com/nunomaduro", + "type": "patreon" + } + ], + "time": "2022-01-13T17:09:04+00:00" + }, { "name": "phar-io/manifest", "version": "2.0.3", diff --git a/resources/views/admin/joined/create.blade.php b/resources/views/admin/joined/create.blade.php index 6816c40..f7409fa 100644 --- a/resources/views/admin/joined/create.blade.php +++ b/resources/views/admin/joined/create.blade.php @@ -8,7 +8,7 @@ @section('content') -
@csrf diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index 78ccc21..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,21 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } -} diff --git a/tests/Feature/Http/Controllers/SessionsControllerTest.php b/tests/Feature/Http/Controllers/SessionsControllerTest.php deleted file mode 100644 index 245c64e..0000000 --- a/tests/Feature/Http/Controllers/SessionsControllerTest.php +++ /dev/null @@ -1,22 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } -} diff --git a/tests/Feature/JoinedTest.php b/tests/Feature/JoinedTest.php new file mode 100644 index 0000000..a30c6f4 --- /dev/null +++ b/tests/Feature/JoinedTest.php @@ -0,0 +1,90 @@ +user = Collective::first(); +}); + +test('get joined index', function () { + $response = $this->actingAs($this->user)->get('fanatic/joined'); + $response->assertViewIs('admin.joined.index'); +}); + +test('get joined create', function () { + $response = $this->actingAs($this->user)->get('fanatic/joined/create'); + $response->assertViewIs('admin.joined.create'); +}); + +test('valid joined form passes create validation', function () { + $response = $this->actingAs($this->user)->post('/fanatic/joined', [ + 'categories' => [3, 10], + 'url' => 'http://punkfairie.net', + 'subject' => 'Test', + ]); + + $response->assertValid(); +}); + +test('invalid category response does not pass create validation', function () { + $response = $this->actingAs($this->user)->post('/fanatic/joined', [ + 'categories' => 4, + 'url' => 'http://punkfairie.net', + 'subject' => 'Test', + ]); + + $response->assertInvalid(); +}); + +test('invalid url does not pass create validation', function () { + $response = $this->actingAs($this->user)->post('/fanatic/joined', [ + 'categories' => [4], + 'url' => 'hello', + 'subject' => 'Test', + ]); + + $response->assertInvalid(); +}); + +test('missing category does not pass create validation', function () { + $response = $this->actingAs($this->user)->post('/fanatic/joined', [ + 'url' => 'https://punkfairie.net', + 'subject' => 'Test', + ]); + + $response->assertInvalid(); +}); + +test('missing subject does not pass create validation', function () { + $response = $this->actingAs($this->user)->post('/fanatic/joined', [ + 'categories' => [1,5], + 'url' => 'https://punkfairie.net', + ]); + + $response->assertInvalid(); +}); + +test('missing url does not pass create validation', function () { + $response = $this->actingAs($this->user)->post('/fanatic/joined', [ + 'categories' => [2], + 'subject' => 'Test', + ]); + + $response->assertInvalid(); +}); + +// test('can upload joined button on create', function () { +// Storage::fake('local'); +// $file = UploadedFile::fake()->image('code.png'); + +// $response = $this->actingAs($this->user)->post('/fanatic/joined', [ +// 'categories' => [3, 10], +// 'url' => 'http://punkfairie.net', +// 'subject' => 'Test', +// 'image' => $file, +// ]); + +// Storage::disk('local')->assertExists($file->hashName()); +// }); \ No newline at end of file diff --git a/tests/Feature/SessionsTest.php b/tests/Feature/SessionsTest.php new file mode 100644 index 0000000..88a410e --- /dev/null +++ b/tests/Feature/SessionsTest.php @@ -0,0 +1,14 @@ +get('/fanatic'); + $response->assertRedirect('/fanatic/login'); +}); + +test('logs in', function () { + $user = Collective::first(); + $response = $this->actingAs($user)->get('/fanatic'); + $response->assertViewIs('admin.dashboard'); +}); diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..5d3a73b --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,45 @@ +in('Feature'); + +/* +|-------------------------------------------------------------------------- +| Expectations +|-------------------------------------------------------------------------- +| +| When you're writing tests, you often need to check that values meet certain conditions. The +| "expect()" function gives you access to a set of "expectations" methods that you can use +| to assert different things. Of course, you may extend the Expectation API at any time. +| +*/ + +expect()->extend('toBeOne', function () { + return $this->toBe(1); +}); + +/* +|-------------------------------------------------------------------------- +| Functions +|-------------------------------------------------------------------------- +| +| While Pest is very powerful out-of-the-box, you may have some testing code specific to your +| project that you don't want to repeat in every file. Here you can also expose helpers as +| global functions to help you to reduce the number of lines of code in your test files. +| +*/ + +function something() +{ + // .. +} diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index e5c5fef..0000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,18 +0,0 @@ -assertTrue(true); - } -}