diff --git a/composer.json b/composer.json index 69ec81d..0eade1c 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "require-dev": { "facade/ignition": "^2.5", "fakerphp/faker": "^1.9.1", + "laravel/dusk": "^6.15", "laravel/sail": "^1.0.1", "mockery/mockery": "^1.4.2", "nunomaduro/collision": "^5.0", diff --git a/composer.lock b/composer.lock index 80e2cc2..5834e25 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": "87007d07e57cf240dbd9fa0b8d5c422a", + "content-hash": "bedab5d5dfeb4c11aa53ce8b1e2f732b", "packages": [ { "name": "asm89/stack-cors", @@ -5817,6 +5817,79 @@ }, "time": "2020-07-09T08:09:16+00:00" }, + { + "name": "laravel/dusk", + "version": "v6.15.1", + "source": { + "type": "git", + "url": "https://github.com/laravel/dusk.git", + "reference": "6978f331f526e84f06b803ed4407d372a6db065f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/dusk/zipball/6978f331f526e84f06b803ed4407d372a6db065f", + "reference": "6978f331f526e84f06b803ed4407d372a6db065f", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-zip": "*", + "illuminate/console": "^6.0|^7.0|^8.0", + "illuminate/support": "^6.0|^7.0|^8.0", + "nesbot/carbon": "^2.0", + "php": "^7.2|^8.0", + "php-webdriver/webdriver": "^1.9.0", + "symfony/console": "^4.3|^5.0", + "symfony/finder": "^4.3|^5.0", + "symfony/process": "^4.3|^5.0", + "vlucas/phpdotenv": "^3.0|^4.0|^5.0" + }, + "require-dev": { + "mockery/mockery": "^1.0", + "orchestra/testbench": "^4.16|^5.17.1|^6.12.1", + "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" + ], + "support": { + "issues": "https://github.com/laravel/dusk/issues", + "source": "https://github.com/laravel/dusk/tree/v6.15.1" + }, + "time": "2021-07-06T16:42:00+00:00" + }, { "name": "laravel/sail", "version": "v1.8.3", @@ -6206,6 +6279,72 @@ }, "time": "2021-02-23T14:00:09+00:00" }, + { + "name": "php-webdriver/webdriver", + "version": "1.11.1", + "source": { + "type": "git", + "url": "https://github.com/php-webdriver/php-webdriver.git", + "reference": "da16e39968f8dd5cfb7d07eef91dc2b731c69880" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-webdriver/php-webdriver/zipball/da16e39968f8dd5cfb7d07eef91dc2b731c69880", + "reference": "da16e39968f8dd5cfb7d07eef91dc2b731c69880", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-zip": "*", + "php": "^5.6 || ~7.0 || ^8.0", + "symfony/polyfill-mbstring": "^1.12", + "symfony/process": "^2.8 || ^3.1 || ^4.0 || ^5.0" + }, + "replace": { + "facebook/webdriver": "*" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.0", + "ondram/ci-detector": "^2.1 || ^3.5 || ^4.0", + "php-coveralls/php-coveralls": "^2.4", + "php-mock/php-mock-phpunit": "^1.1 || ^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpunit/phpunit": "^5.7 || ^7 || ^8 || ^9", + "squizlabs/php_codesniffer": "^3.5", + "symfony/var-dumper": "^3.3 || ^4.0 || ^5.0" + }, + "suggest": { + "ext-SimpleXML": "For Firefox profile creation" + }, + "type": "library", + "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" + ], + "support": { + "issues": "https://github.com/php-webdriver/php-webdriver/issues", + "source": "https://github.com/php-webdriver/php-webdriver/tree/1.11.1" + }, + "time": "2021-05-21T15:12:49+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "2.2.0", diff --git a/database/factories/CompanyFactory.php b/database/factories/CompanyFactory.php new file mode 100644 index 0000000..d29fee9 --- /dev/null +++ b/database/factories/CompanyFactory.php @@ -0,0 +1,31 @@ + $this->faker->name(), + 'email' => $this->faker->unique()->safeEmail(), + 'logo' => $this->faker->image('/'), + 'website_link' => $this->faker->url(), + ]; + } +} diff --git a/phpunit.dusk.xml b/phpunit.dusk.xml new file mode 100644 index 0000000..07f70bd --- /dev/null +++ b/phpunit.dusk.xml @@ -0,0 +1,16 @@ + + + + + ./tests/Browser + + + diff --git a/resources/views/partials/sidebar.blade.php b/resources/views/partials/sidebar.blade.php index ede139e..d087186 100644 --- a/resources/views/partials/sidebar.blade.php +++ b/resources/views/partials/sidebar.blade.php @@ -64,9 +64,7 @@ class="nav-link {{ Request::routeIs('admin.home') ? 'active' : '' }}"> -

- {{ trans('simplecrm.sign_out') }} -

+

{{ trans('simplecrm.sign_out') }}

diff --git a/tests/Browser/Auth/LoginTest.php b/tests/Browser/Auth/LoginTest.php new file mode 100644 index 0000000..6b776b7 --- /dev/null +++ b/tests/Browser/Auth/LoginTest.php @@ -0,0 +1,32 @@ +browse(function (Browser $browser) { + // Create new user + $user = User::factory()->create([ + 'email' => 'admin@admin.com' + ]); + + // Begin test + $browser->visit('/login') + ->type('email', $user->email) + ->type('password', 'password') + ->press(trans('simplecrm.sign_in')) + ->click('a[href="' . route('logout') . '"]') + ->visit('/admin') + ->assertPathIs('/login'); + }); + } +} diff --git a/tests/Browser/CompanyTest.php b/tests/Browser/CompanyTest.php new file mode 100644 index 0000000..3bf7b1b --- /dev/null +++ b/tests/Browser/CompanyTest.php @@ -0,0 +1,26 @@ +create([ + 'email' => 'admin@admin.com' + ]); + + $this->browse(function (Browser $browser) use ($user) { + $browser->loginAs($user) + ->visit(route('admin.company.index')) + ->assertRouteIs('admin.company.index'); + }); + } +} diff --git a/tests/Browser/EmployeeTest.php b/tests/Browser/EmployeeTest.php new file mode 100644 index 0000000..5432b9c --- /dev/null +++ b/tests/Browser/EmployeeTest.php @@ -0,0 +1,26 @@ +create([ + 'email' => 'admin@admin.com' + ]); + + $this->browse(function (Browser $browser) use ($user) { + $browser->loginAs($user) + ->visit(route('admin.employee.index')) + ->assertRouteIs('admin.employee.index'); + }); + } +} 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/DuskTestCase.php b/tests/DuskTestCase.php new file mode 100644 index 0000000..808af69 --- /dev/null +++ b/tests/DuskTestCase.php @@ -0,0 +1,61 @@ +addArguments(collect([ + '--window-size=1920,1080', + ])->unless($this->hasHeadlessDisabled(), function ($items) { + return $items->merge([ + '--disable-gpu', + '--headless', + ]); + })->all()); + + return RemoteWebDriver::create( + $_ENV['DUSK_DRIVER_URL'] ?? 'http://localhost:9515', + DesiredCapabilities::chrome()->setCapability( + ChromeOptions::CAPABILITY, $options + ) + ); + } + + /** + * Determine whether the Dusk command has disabled headless mode. + * + * @return bool + */ + protected function hasHeadlessDisabled() + { + return isset($_SERVER['DUSK_HEADLESS_DISABLED']) || + isset($_ENV['DUSK_HEADLESS_DISABLED']); + } +} diff --git a/tests/Feature/Auth/RegisterTest.php b/tests/Feature/Auth/RegisterTest.php new file mode 100644 index 0000000..c9d8c13 --- /dev/null +++ b/tests/Feature/Auth/RegisterTest.php @@ -0,0 +1,17 @@ +get('/register'); + + $response->assertStatus(404); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 2932d4a..5a8da7e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,8 +3,16 @@ namespace Tests; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; +use App\Models\User; abstract class TestCase extends BaseTestCase { use CreatesApplication; + + protected function signIn($user = null) + { + $user = $user ?? User::factory()->create(); + $this->actingAs($user); + return $this; + } }