diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..f66de36 --- /dev/null +++ b/.env.test @@ -0,0 +1,42 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY= +APP_DEBUG=true +APP_URL=http://localhost + +LOG_CHANNEL=stack + +DB_CONNECTION=sqlite +DB_DATABASE=database/database.sqlite + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS=null +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER=mt1 + +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 63863eb..b6f4004 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -13,8 +13,9 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Copy .env - run: php -r "file_exists('.env') || copy('.env.example', '.env');" + run: php -r "file_exists('.env') || copy('.env.test', '.env');" - name: Install Dependencies run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - name: Generate key @@ -24,9 +25,10 @@ jobs: - name: Create Database run: | mkdir -p database - touch database/database.pgsql + touch database/database.sqlite + php artisan migrate - name: Execute tests (Unit and Feature tests) via PHPUnit env: - DB_CONNECTION: pgsql - DB_DATABASE: database/database.pgsql + DB_CONNECTION: sqlite + DB_DATABASE: database/database.sqlite run: vendor/bin/phpunit diff --git a/composer.json b/composer.json index d418fef..abac5ce 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "barryvdh/laravel-debugbar": "^3.3", "facade/ignition": "^2.0", "fzaninotto/faker": "^1.9.1", + "laravel/dusk": "^6.4", "mockery/mockery": "^1.3.1", "nunomaduro/collision": "^4.1", "phpunit/phpunit": "^8.5" diff --git a/composer.lock b/composer.lock index 4213af2..b9ec0b0 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": "73d802409456a1a52d8c3c867ff2626b", + "content-hash": "33bfd0057d61d787a9206b2111c17bbd", "packages": [ { "name": "asm89/stack-cors", @@ -2177,7 +2177,7 @@ "email": "fabien@symfony.com" }, { - "name": "Jean-Fran??ois Simon", + "name": "Jean-François Simon", "email": "jeanfrancois.simon@sensiolabs.com" }, { @@ -3867,6 +3867,57 @@ "homepage": "https://github.com/tijsverkoyen/CssToInlineStyles", "time": "2020-07-13T06:12:54+00:00" }, + { + "name": "twbs/bootstrap", + "version": "v4.5.2", + "source": { + "type": "git", + "url": "https://github.com/twbs/bootstrap.git", + "reference": "5f2480a90ab911babc53039835fe78c6fc12646d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twbs/bootstrap/zipball/5f2480a90ab911babc53039835fe78c6fc12646d", + "reference": "5f2480a90ab911babc53039835fe78c6fc12646d", + "shasum": "" + }, + "replace": { + "twitter/bootstrap": "self.version" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Otto", + "email": "markdotto@gmail.com" + }, + { + "name": "Jacob Thornton", + "email": "jacobthornton@gmail.com" + } + ], + "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.", + "homepage": "https://getbootstrap.com/", + "keywords": [ + "JS", + "css", + "framework", + "front-end", + "mobile-first", + "responsive", + "sass", + "web" + ], + "time": "2020-08-06T16:22:43+00:00" + }, { "name": "vlucas/phpdotenv", "version": "v4.1.8", @@ -4382,7 +4433,7 @@ ], "authors": [ { - "name": "Fran??ois Zaninotto" + "name": "François Zaninotto" } ], "description": "Faker is a PHP library that generates fake data for you.", @@ -4440,6 +4491,74 @@ ], "time": "2020-07-09T08:09:16+00:00" }, + { + "name": "laravel/dusk", + "version": "v6.4.1", + "source": { + "type": "git", + "url": "https://github.com/laravel/dusk.git", + "reference": "db10ac70d01f332614a54cd7f1fe4757066db7cc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/dusk/zipball/db10ac70d01f332614a54cd7f1fe4757066db7cc", + "reference": "db10ac70d01f332614a54cd7f1fe4757066db7cc", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-zip": "*", + "illuminate/console": "^6.0|^7.0", + "illuminate/support": "^6.0|^7.0", + "nesbot/carbon": "^2.0", + "php": "^7.2", + "php-webdriver/webdriver": "^1.8.1", + "symfony/console": "^4.3|^5.0", + "symfony/finder": "^4.3|^5.0", + "symfony/process": "^4.3|^5.0", + "vlucas/phpdotenv": "^3.0|^4.0" + }, + "require-dev": { + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^7.5.15|^8.4|^9.0" + }, + "suggest": { + "ext-pcntl": "Used to gracefully terminate Dusk when tests are running." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.x-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Dusk\\DuskServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Dusk\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel Dusk provides simple end-to-end testing and browser automation.", + "keywords": [ + "laravel", + "testing", + "webdriver" + ], + "time": "2020-07-14T18:02:46+00:00" + }, { "name": "maximebf/debugbar", "version": "v1.16.3", @@ -4543,7 +4662,7 @@ ], "authors": [ { - "name": "P??draic Brady", + "name": "Pádraic Brady", "email": "padraic.brady@gmail.com", "homepage": "http://blog.astrumfutura.com" }, @@ -4789,6 +4908,71 @@ "description": "Library for handling version information and constraints", "time": "2018-07-08T19:19:57+00:00" }, + { + "name": "php-webdriver/webdriver", + "version": "1.8.2", + "source": { + "type": "git", + "url": "https://github.com/php-webdriver/php-webdriver.git", + "reference": "3308a70be084d6d7fd1ee5787b4c2e6eb4b70aab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-webdriver/php-webdriver/zipball/3308a70be084d6d7fd1ee5787b4c2e6eb4b70aab", + "reference": "3308a70be084d6d7fd1ee5787b4c2e6eb4b70aab", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-zip": "*", + "php": "^5.6 || ~7.0", + "symfony/polyfill-mbstring": "^1.12", + "symfony/process": "^2.8 || ^3.1 || ^4.0 || ^5.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.0", + "jakub-onderka/php-parallel-lint": "^1.0", + "php-coveralls/php-coveralls": "^2.0", + "php-mock/php-mock-phpunit": "^1.1", + "phpunit/phpunit": "^5.7", + "sebastian/environment": "^1.3.4 || ^2.0 || ^3.0", + "sminnee/phpunit-mock-objects": "^3.4", + "squizlabs/php_codesniffer": "^3.5", + "symfony/var-dumper": "^3.3 || ^4.0 || ^5.0" + }, + "suggest": { + "ext-SimpleXML": "For Firefox profile creation" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Facebook\\WebDriver\\": "lib/" + }, + "files": [ + "lib/Exception/TimeoutException.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A PHP client for Selenium WebDriver. Previously facebook/webdriver.", + "homepage": "https://github.com/php-webdriver/php-webdriver", + "keywords": [ + "Chromedriver", + "geckodriver", + "php", + "selenium", + "webdriver" + ], + "time": "2020-03-04T14:40:12+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "2.2.0", diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index ff871dd..02ded29 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -30,5 +30,6 @@ 'email_verified_at' => now(), 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 'remember_token' => Str::random(10), + 'is_admin' => true, ]; }); diff --git a/tests/Browser/ExampleTest.php b/tests/Browser/ExampleTest.php new file mode 100644 index 0000000..9d8968b --- /dev/null +++ b/tests/Browser/ExampleTest.php @@ -0,0 +1,23 @@ +browse(function (Browser $browser) { + $browser->visit('/') + ->assertSee('Laravel'); + }); + } +} diff --git a/tests/Browser/Pages/HomePage.php b/tests/Browser/Pages/HomePage.php new file mode 100644 index 0000000..26bf174 --- /dev/null +++ b/tests/Browser/Pages/HomePage.php @@ -0,0 +1,41 @@ + '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/Page.php b/tests/Browser/Pages/Page.php new file mode 100644 index 0000000..f8d7622 --- /dev/null +++ b/tests/Browser/Pages/Page.php @@ -0,0 +1,20 @@ + '#selector', + ]; + } +} diff --git a/tests/Browser/console/.gitignore b/tests/Browser/console/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/tests/Browser/console/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/Browser/screenshots/.gitignore b/tests/Browser/screenshots/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/tests/Browser/screenshots/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php new file mode 100644 index 0000000..b1dd1bc --- /dev/null +++ b/tests/DuskTestCase.php @@ -0,0 +1,44 @@ +addArguments([ + '--disable-gpu', + '--headless', + '--window-size=1920,1080', + ]); + + return RemoteWebDriver::create( + 'http://localhost:9515', DesiredCapabilities::chrome()->setCapability( + ChromeOptions::CAPABILITY, $options + ) + ); + } +} diff --git a/tests/Unit/HTTPTest.php b/tests/Unit/HTTPTest.php new file mode 100644 index 0000000..1a0af81 --- /dev/null +++ b/tests/Unit/HTTPTest.php @@ -0,0 +1,82 @@ +get('/'); + $response->assertStatus(200); + } + + /** @test */ + public function getHomePageTest() + { + $response = $this->get('/home'); + $response->assertStatus(200); + } + + /** @test */ + public function getAboutPageTest() + { + $response = $this->get('/about'); + $response->assertStatus(200); + } + + + /** This test is used to verify a user a redirected to the login + * if they attempt to access the rent a locker page without + * being authenticated + */ + /** @test */ + public function getRentalPageWithoutLoginTest() + { + $response = $this->get('/rent'); + + $response->assertRedirect('/login'); + } + + /** This test is used to verify that the admin dashboard page + * does not work without authentication + */ + /** @test */ + public function adminPageWithoutAdminRightsTest() + { + $response = $this->get('/admin/dashboard'); + + $response->assertRedirect('/login'); + } + + /** This test is used to verify that accessing the rental page + * as a user works + */ + /** @test */ + public function rentalPageAsUserTest() + { + $user = factory(User::class)->create(); + + $response = $this->actingAs($user)->get('/rent'); + + $response->assertStatus(200); + } + + /** This test is used to verify that accessing the rental page + * as a user works + */ + /** @test */ + public function adminDashboardAsAdmin() + { + $user = factory(User::class)->create(); + + $response = $this->actingAs($user)->get('/admin/dashboard'); + + $response->assertStatus(200); + } +}