first commit

This commit is contained in:
benjibennn
2023-12-22 12:35:55 +08:00
commit 9f89a732d6
872 changed files with 156291 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
<?php
namespace Tests\Browser;
use App\Models\User;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
class AuthTest extends DuskTestCase
{
//use DatabaseMigrations;
public function setUp(): void
{
parent::setUp();
// $this->artisan('db:seed');
}
/**
* A Dusk test example.
*
* @return void
*/
public function testSignup()
{
$this->browse(function (Browser $browser) {
User::where('email', '=', 'scoobydoo@gmail.com')->first()->delete();
$browser->visit('/')
->clickLink('Sign Up')
->assertPathIs('/register')
->type('name', 'Scooby Doo')
->type('username', 'scoobydoo')
->type('email', 'scoobydoo@gmail.com')
->type('password', 'password123')
->type('password_confirmation', 'password123')
->click('button[type="submit"]')
->waitForText('Thanks for signing up!')
->assertSee('Thanks for signing up!');
});
}
public function testLogout()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(User::where('email', '=', 'scoobydoo@gmail.com')->first())
->visit('/dashboard')
->mouseover('.user-icon')
->waitForText('Logout')
->clickLink('Logout')
->assertPathIs('/');
});
}
public function testLogin()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->clickLink('Login')
->assertPathIs('/login')
->type('email', 'scoobydoo@gmail.com')
->type('password', 'password123')
->click('button[type="submit"]')
->waitForText('Successfully logged in.')
->assertSee('Successfully logged in.');
});
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Tests\Browser;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class HomePageTest extends DuskTestCase
{
//use DatabaseMigrations;
public function setUp(): void
{
parent::setUp();
//$this->artisan('db:seed');
}
/**
* A Dusk test example.
*
* @return void
*/
public function testText()
{
$this->browse(function (Browser $browser) {
$browser->visit('/') //->dump()
->waitForText('Wave is the perfect starter kit')
->assertSeeIn('h2', 'Wave is the perfect starter kit');
});
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Tests\Browser\Pages;
use Laravel\Dusk\Browser;
class HomePage extends Page
{
/**
* Get the URL for the page.
*
* @return string
*/
public function url()
{
return '/';
}
/**
* Assert that the browser is on the page.
*
* @param \Laravel\Dusk\Browser $browser
* @return void
*/
public function assert(Browser $browser)
{
//
}
/**
* Get the element shortcuts for the page.
*
* @return array
*/
public function elements()
{
return [
'@element' => '#selector',
];
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Tests\Browser\Pages;
use Laravel\Dusk\Page as BasePage;
abstract class Page extends BasePage
{
/**
* Get the global element shortcuts for the site.
*
* @return array
*/
public static function siteElements()
{
return [
'@element' => '#selector',
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Tests\Browser;
use App\Models\User;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class UserProfileTest extends DuskTestCase
{
/**
* A Dusk test example.
*
* @return void
*/
public function testProfilePage()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(User::where('email', '=', 'scoobydoo@gmail.com')->first())
->visit('/@scoobydoo')
->assertSee('Scooby Doo');
});
}
}

File diff suppressed because one or more lines are too long

2
tests/Browser/console/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore

2
tests/Browser/screenshots/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore

View File

@@ -0,0 +1,22 @@
<?php
namespace Tests;
use Illuminate\Contracts\Console\Kernel;
trait CreatesApplication
{
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
return $app;
}
}

View File

@@ -0,0 +1,63 @@
<?php
dataset('authroutes', function () {
return [
'/',
'/admin',
'/@admin',
'/blog',
'/blog/category-1',
'/blog/category-1/best-ways-to-market-your-application',
'/docs/welcome',
'/admin/announcements',
'/admin/announcements/create',
'/admin/announcements/1',
'/admin/announcements/1/edit',
'/admin/bread',
'/admin/bread/users/create',
'/admin/bread/users/edit',
'/admin/categories',
'/admin/categories/create',
'/admin/categories/1',
'/admin/categories/1/edit',
'/admin/database',
// '/admin/hooks', Hooks: Removed in Voyager 1.5+
'/admin/media',
'/admin/menus',
'/admin/menus/create',
'/admin/menus/1',
'/admin/menus/1/edit',
'/admin/pages',
'/admin/pages/create',
'/admin/pages/1',
'/admin/pages/1/edit',
'/admin/plans',
'/admin/plans/create',
'/admin/plans/1',
'/admin/plans/1/edit',
'/admin/posts',
'/admin/posts/create',
'/admin/posts/5',
'/admin/posts/5/edit',
'/admin/profile',
'/admin/roles',
'/admin/roles/create',
'/admin/roles/1',
'/admin/roles/1/edit',
'/admin/settings',
'/admin/users',
'/admin/users/create',
'/admin/users/1',
'/admin/users/1/edit',
'/announcement/1',
'/announcements',
'/dashboard',
'/notifications',
'/settings/profile',
'/settings/security',
'/settings/api',
'/settings/plans',
'/settings/subscription',
'/settings/invoices'
];
});

16
tests/Datasets/Routes.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
dataset('routes', function () {
return [
'/admin/login',
'/@admin',
'/blog',
'/blog/category-1',
'/blog/category-1/best-ways-to-market-your-application',
'/docs/welcome',
'/login',
'/password/reset',
'/pricing',
'/p/about',
];
});

44
tests/DuskTestCase.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
namespace Tests;
use Laravel\Dusk\TestCase as BaseTestCase;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
/**
* Prepare for Dusk test execution.
*
* @beforeClass
* @return void
*/
public static function prepare()
{
static::startChromeDriver();
}
/**
* Create the RemoteWebDriver instance.
*
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
'--window-size=1920,1080',
]);
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}
}

View File

@@ -0,0 +1,17 @@
<?php
test('available routes', function ($url) {
$response = $this->get($url);
$response->assertStatus(200);
})->with('routes');
test('available auth routes', function ($url) {
$user = \App\Models\User::find(1);
$this->actingAs($user);
$response = $this->get($url);
$response->assertStatus(200);
})->with('authroutes');

47
tests/Pest.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
use Tests\Traits\RecursiveRefreshDatabase as RefreshDatabase;
/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "uses()" function to bind a different classes or traits.
|
*/
uses(Tests\TestCase::class, RefreshDatabase::class)->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()
{
// ..
}

10
tests/TestCase.php Normal file
View File

@@ -0,0 +1,10 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Tests\Traits;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\RefreshDatabaseState;
trait RecursiveRefreshDatabase {
use RefreshDatabase;
/**
* Refresh the in-memory database.
*
* @return void
*/
protected function refreshInMemoryDatabase()
{
$this->artisan('migrate', ['--path' => 'database/migrations/']);
$this->artisan('db:seed');
$this->app[Kernel::class]->setArtisan(null);
}
/**
* Refresh a conventional test database.
*
* @return void
*/
protected function refreshTestDatabase()
{
if (! RefreshDatabaseState::$migrated) {
$this->artisan('migrate:fresh', $this->migrateFreshUsing());
$this->app[Kernel::class]->setArtisan(null);
$this->artisan('db:seed');
RefreshDatabaseState::$migrated = true;
}
$this->beginDatabaseTransaction();
}
/**
* The parameters that should be used when running "migrate:fresh".
*
* @return array
*/
protected function migrateFreshUsing()
{
return array_merge(
[
'--drop-views' => $this->shouldDropViews(),
'--drop-types' => $this->shouldDropTypes(),
],
);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$this->assertTrue(true);
}
}