generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
189 additions
and
191 deletions.
There are no files selected for viewing
54 changes: 27 additions & 27 deletions
54
src/Filament/Resources/EmailResource/Pages/ListEmails.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
<?php | ||
|
||
namespace RickDBCN\FilamentEmail\Filament\Resources\EmailResource\Pages; | ||
|
||
use Filament\Actions\Concerns\InteractsWithActions; | ||
use Filament\Resources\Pages\ListRecords; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use RickDBCN\FilamentEmail\Filament\Resources\EmailResource; | ||
|
||
class ListEmails extends ListRecords | ||
{ | ||
use InteractsWithActions; | ||
|
||
public static function getResource(): string | ||
{ | ||
return config('filament-email.resource.class', EmailResource::class); | ||
} | ||
|
||
protected function applySearchToTableQuery(Builder $query): Builder | ||
{ | ||
if (filled($searchQuery = $this->getTableSearch())) { | ||
return $query->filter(['search' => $searchQuery]); | ||
} | ||
|
||
return $query; | ||
} | ||
} | ||
<?php | ||
|
||
namespace RickDBCN\FilamentEmail\Filament\Resources\EmailResource\Pages; | ||
|
||
use Filament\Actions\Concerns\InteractsWithActions; | ||
use Filament\Resources\Pages\ListRecords; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use RickDBCN\FilamentEmail\Filament\Resources\EmailResource; | ||
|
||
class ListEmails extends ListRecords | ||
{ | ||
use InteractsWithActions; | ||
|
||
public static function getResource(): string | ||
{ | ||
return config('filament-email.resource.class', EmailResource::class); | ||
} | ||
|
||
protected function applySearchToTableQuery(Builder $query): Builder | ||
{ | ||
if (filled($searchQuery = $this->getTableSearch())) { | ||
return $query->filter(['search' => $searchQuery]); | ||
} | ||
|
||
return $query; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,61 @@ | ||
<?php | ||
|
||
use Faker\Factory; | ||
use Illuminate\Support\Facades\Mail; | ||
use RickDBCN\FilamentEmail\Filament\Resources\EmailResource\Pages\ListEmails; | ||
use RickDBCN\FilamentEmail\Models\Email; | ||
use RickDBCN\FilamentEmail\Tests\Models\User; | ||
|
||
use function Pest\Laravel\assertDatabaseCount; | ||
use function Pest\Laravel\assertModelExists; | ||
use function Pest\Livewire\livewire; | ||
use function PHPUnit\Framework\assertEquals; | ||
|
||
beforeEach(function () { | ||
$this->model = config('filament-email.resource.model') ?? Email::class; | ||
$this->actingAs(User::factory() | ||
->create()); | ||
}); | ||
|
||
it('can create an Email model', function () { | ||
$emailModel = Email::factory() | ||
->create(); | ||
assertModelExists($emailModel); | ||
}); | ||
|
||
it('can capture a sent email', function () { | ||
$faker = Factory::create(); | ||
$recipient = $faker->email(); | ||
|
||
Mail::raw('Test e-mail text', function ($message) use ($recipient) { | ||
$message->to($recipient) | ||
->subject('the email subject'); | ||
}); | ||
|
||
assertDatabaseCount('filament_email_log', 1); | ||
|
||
assertEquals($this->model::first()->to, $recipient); | ||
}); | ||
|
||
it('can render table page', function () { | ||
$this->model::factory() | ||
->create(); | ||
livewire(ListEmails::class) | ||
->assertSuccessful(); | ||
}); | ||
|
||
it('can render table records', function () { | ||
$records = $this->model::factory() | ||
->count(10) | ||
->create(); | ||
livewire(ListEmails::class) | ||
->assertCanSeeTableRecords($records); | ||
}); | ||
|
||
it('can resend email', function () { | ||
$email = $this->model::factory() | ||
->create(); | ||
livewire(ListEmails::class) | ||
->callTableAction('resend', $email); | ||
assertDatabaseCount((new $this->model)->getTable(), 2); | ||
}); | ||
<?php | ||
|
||
use Faker\Factory; | ||
use Illuminate\Support\Facades\Mail; | ||
use RickDBCN\FilamentEmail\Filament\Resources\EmailResource\Pages\ListEmails; | ||
use RickDBCN\FilamentEmail\Models\Email; | ||
use RickDBCN\FilamentEmail\Tests\Models\User; | ||
|
||
use function Pest\Laravel\assertDatabaseCount; | ||
use function Pest\Laravel\assertModelExists; | ||
use function Pest\Livewire\livewire; | ||
use function PHPUnit\Framework\assertEquals; | ||
|
||
beforeEach(function () { | ||
$this->model = config('filament-email.resource.model') ?? Email::class; | ||
$this->actingAs(User::factory() | ||
->create()); | ||
}); | ||
|
||
it('can create an Email model', function () { | ||
$emailModel = Email::factory() | ||
->create(); | ||
assertModelExists($emailModel); | ||
}); | ||
|
||
it('can capture a sent email', function () { | ||
$faker = Factory::create(); | ||
$recipient = $faker->email(); | ||
|
||
Mail::raw('Test e-mail text', function ($message) use ($recipient) { | ||
$message->to($recipient) | ||
->subject('the email subject'); | ||
}); | ||
|
||
assertDatabaseCount('filament_email_log', 1); | ||
|
||
assertEquals($this->model::first()->to, $recipient); | ||
}); | ||
|
||
it('can render table page', function () { | ||
$this->model::factory() | ||
->create(); | ||
livewire(ListEmails::class) | ||
->assertSuccessful(); | ||
}); | ||
|
||
it('can render table records', function () { | ||
$records = $this->model::factory() | ||
->count(10) | ||
->create(); | ||
livewire(ListEmails::class) | ||
->assertCanSeeTableRecords($records); | ||
}); | ||
|
||
it('can resend email', function () { | ||
$email = $this->model::factory() | ||
->create(); | ||
livewire(ListEmails::class) | ||
->callTableAction('resend', $email); | ||
assertDatabaseCount((new $this->model)->getTable(), 2); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
use RickDBCN\FilamentEmail\Tests\TestCase; | ||
|
||
uses(TestCase::class)->in(__DIR__); | ||
<?php | ||
|
||
use RickDBCN\FilamentEmail\Tests\TestCase; | ||
|
||
uses(TestCase::class)->in(__DIR__); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,96 @@ | ||
<?php | ||
|
||
namespace RickDBCN\FilamentEmail\Tests; | ||
|
||
use BladeUI\Heroicons\BladeHeroiconsServiceProvider; | ||
use BladeUI\Icons\BladeIconsServiceProvider; | ||
use Filament\Actions\ActionsServiceProvider; | ||
use Filament\FilamentServiceProvider; | ||
use Filament\Forms\FormsServiceProvider; | ||
use Filament\Notifications\NotificationsServiceProvider; | ||
use Filament\Support\SupportServiceProvider; | ||
use Filament\Tables\TablesServiceProvider; | ||
use Filament\Widgets\WidgetsServiceProvider; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Foundation\Application; | ||
use Livewire\LivewireServiceProvider; | ||
use Malzariey\FilamentDaterangepickerFilter\Fields\DateRangePicker; | ||
use Malzariey\FilamentDaterangepickerFilter\FilamentDaterangepickerFilterServiceProvider; | ||
use Malzariey\FilamentDaterangepickerFilter\Filters\DateRangeFilter; | ||
use Orchestra\Testbench\TestCase as Orchestra; | ||
use RickDBCN\FilamentEmail\FilamentEmailServiceProvider; | ||
use RickDBCN\FilamentEmail\Providers\EmailMessageServiceProvider; | ||
use RickDBCN\FilamentEmail\Tests\Models\User; | ||
use RickDBCN\FilamentEmail\Tests\Panels\TestPanelProvider; | ||
|
||
class TestCase extends Orchestra | ||
{ | ||
protected User $adminUser; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpDatabase($this->app); | ||
|
||
Factory::guessFactoryNamesUsing( | ||
fn (string $modelName) => 'RickDBCN\\FilamentEmail\\Database\\Factories\\'.class_basename($modelName).'Factory' | ||
); | ||
} | ||
|
||
protected function getPackageProviders($app) | ||
{ | ||
$packageProviders = [ | ||
BladeHeroiconsServiceProvider::class, | ||
BladeIconsServiceProvider::class, | ||
FilamentServiceProvider::class, | ||
FormsServiceProvider::class, | ||
LivewireServiceProvider::class, | ||
SupportServiceProvider::class, | ||
TablesServiceProvider::class, | ||
ActionsServiceProvider::class, | ||
WidgetsServiceProvider::class, | ||
EmailMessageServiceProvider::class, | ||
FilamentEmailServiceProvider::class, | ||
FilamentDaterangepickerFilterServiceProvider::class, | ||
TestPanelProvider::class, | ||
]; | ||
|
||
if (class_exists(NotificationsServiceProvider::class)) { | ||
$packageProviders[] = NotificationsServiceProvider::class; | ||
} | ||
|
||
return $packageProviders; | ||
} | ||
|
||
public function getEnvironmentSetUp($app) | ||
{ | ||
config()->set('database.default', 'testing'); | ||
|
||
$migration = include __DIR__.'/../database/migrations/create_filament_email_table.php.stub'; | ||
$migration->up(); | ||
|
||
$migration = include __DIR__.'/../database/migrations/add_attachments_field_to_filament_email_log_table.php.stub'; | ||
$migration->up(); | ||
|
||
$migration = include __DIR__.'/../database/migrations/add_team_id_field_to_filament_email_log_table.php.stub'; | ||
$migration->up(); | ||
} | ||
|
||
/** | ||
* Set up the database. | ||
* | ||
* @param Application $app | ||
*/ | ||
protected function setUpDatabase($app) | ||
{ | ||
$app['db']->connection()->getSchemaBuilder()->create('users', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('email'); | ||
$table->string('name'); | ||
}); | ||
|
||
$this->adminUser = User::create(['email' => '[email protected]', 'name' => 'Admin']); | ||
|
||
//self::$migration->up(); | ||
} | ||
} | ||
<?php | ||
|
||
namespace RickDBCN\FilamentEmail\Tests; | ||
|
||
use BladeUI\Heroicons\BladeHeroiconsServiceProvider; | ||
use BladeUI\Icons\BladeIconsServiceProvider; | ||
use Filament\Actions\ActionsServiceProvider; | ||
use Filament\FilamentServiceProvider; | ||
use Filament\Forms\FormsServiceProvider; | ||
use Filament\Notifications\NotificationsServiceProvider; | ||
use Filament\Support\SupportServiceProvider; | ||
use Filament\Tables\TablesServiceProvider; | ||
use Filament\Widgets\WidgetsServiceProvider; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Foundation\Application; | ||
use Livewire\LivewireServiceProvider; | ||
use Malzariey\FilamentDaterangepickerFilter\FilamentDaterangepickerFilterServiceProvider; | ||
use Orchestra\Testbench\TestCase as Orchestra; | ||
use RickDBCN\FilamentEmail\FilamentEmailServiceProvider; | ||
use RickDBCN\FilamentEmail\Providers\EmailMessageServiceProvider; | ||
use RickDBCN\FilamentEmail\Tests\Models\User; | ||
use RickDBCN\FilamentEmail\Tests\Panels\TestPanelProvider; | ||
|
||
class TestCase extends Orchestra | ||
{ | ||
protected User $adminUser; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpDatabase($this->app); | ||
|
||
Factory::guessFactoryNamesUsing( | ||
fn (string $modelName) => 'RickDBCN\\FilamentEmail\\Database\\Factories\\'.class_basename($modelName).'Factory' | ||
); | ||
} | ||
|
||
protected function getPackageProviders($app) | ||
{ | ||
$packageProviders = [ | ||
BladeHeroiconsServiceProvider::class, | ||
BladeIconsServiceProvider::class, | ||
FilamentServiceProvider::class, | ||
FormsServiceProvider::class, | ||
LivewireServiceProvider::class, | ||
SupportServiceProvider::class, | ||
TablesServiceProvider::class, | ||
ActionsServiceProvider::class, | ||
WidgetsServiceProvider::class, | ||
EmailMessageServiceProvider::class, | ||
FilamentEmailServiceProvider::class, | ||
FilamentDaterangepickerFilterServiceProvider::class, | ||
TestPanelProvider::class, | ||
]; | ||
|
||
if (class_exists(NotificationsServiceProvider::class)) { | ||
$packageProviders[] = NotificationsServiceProvider::class; | ||
} | ||
|
||
return $packageProviders; | ||
} | ||
|
||
public function getEnvironmentSetUp($app) | ||
{ | ||
config()->set('database.default', 'testing'); | ||
|
||
$migration = include __DIR__.'/../database/migrations/create_filament_email_table.php.stub'; | ||
$migration->up(); | ||
|
||
$migration = include __DIR__.'/../database/migrations/add_attachments_field_to_filament_email_log_table.php.stub'; | ||
$migration->up(); | ||
|
||
$migration = include __DIR__.'/../database/migrations/add_team_id_field_to_filament_email_log_table.php.stub'; | ||
$migration->up(); | ||
} | ||
|
||
/** | ||
* Set up the database. | ||
* | ||
* @param Application $app | ||
*/ | ||
protected function setUpDatabase($app) | ||
{ | ||
$app['db']->connection()->getSchemaBuilder()->create('users', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('email'); | ||
$table->string('name'); | ||
}); | ||
|
||
$this->adminUser = User::create(['email' => '[email protected]', 'name' => 'Admin']); | ||
|
||
//self::$migration->up(); | ||
} | ||
} |