Move to data providers
This commit is contained in:
parent
3db124e709
commit
7df636515f
1 changed files with 51 additions and 64 deletions
|
@ -6,83 +6,70 @@ use App\Mail\CheckoutAssetMail;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\CheckoutAcceptance;
|
use App\Models\CheckoutAcceptance;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class CheckoutAssetMailTest extends TestCase
|
class CheckoutAssetMailTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testSubjectLine()
|
public static function data()
|
||||||
{
|
{
|
||||||
$user = User::factory()->create();
|
yield 'Asset requiring acceptance' => [
|
||||||
$actor = User::factory()->create();
|
function () {
|
||||||
|
$asset = Asset::factory()->requiresAcceptance()->create();
|
||||||
|
return [
|
||||||
|
'asset' => $asset,
|
||||||
|
'acceptance' => CheckoutAcceptance::factory()->for($asset, 'checkoutable')->create(),
|
||||||
|
'first_time_sending' => true,
|
||||||
|
'expected_subject' => 'Asset checked out',
|
||||||
|
'expected_opening' => 'A new item has been checked out under your name that requires acceptance, details are below.'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
$assetRequiringAcceptance = Asset::factory()->requiresAcceptance()->create();
|
yield 'Asset not requiring acceptance' => [
|
||||||
$assetNotRequiringAcceptance = Asset::factory()->doesNotRequireAcceptance()->create();
|
function () {
|
||||||
|
return [
|
||||||
|
'asset' => Asset::factory()->doesNotRequireAcceptance()->create(),
|
||||||
|
'acceptance' => null,
|
||||||
|
'first_time_sending' => true,
|
||||||
|
'expected_subject' => 'Asset checked out',
|
||||||
|
'expected_opening' => 'A new item has been checked out under your name, details are below.'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
$acceptance = CheckoutAcceptance::factory()->for($assetRequiringAcceptance, 'checkoutable')->create();
|
yield 'Reminder' => [
|
||||||
|
function () {
|
||||||
(new CheckoutAssetMail(
|
return [
|
||||||
$assetRequiringAcceptance,
|
'asset' => Asset::factory()->requiresAcceptance()->create(),
|
||||||
$user,
|
'acceptance' => CheckoutAcceptance::factory()->create(),
|
||||||
$actor,
|
'first_time_sending' => false,
|
||||||
$acceptance,
|
'expected_subject' => 'Reminder: You have Unaccepted Assets.',
|
||||||
'A note goes here',
|
'expected_opening' => 'An item was recently checked out under your name that requires acceptance, details are below.'
|
||||||
true,
|
];
|
||||||
))->assertHasSubject('Asset checked out');
|
}
|
||||||
|
];
|
||||||
(new CheckoutAssetMail(
|
|
||||||
$assetNotRequiringAcceptance,
|
|
||||||
$user,
|
|
||||||
$actor,
|
|
||||||
null,
|
|
||||||
'A note goes here',
|
|
||||||
true,
|
|
||||||
))->assertHasSubject('Asset checked out');
|
|
||||||
|
|
||||||
(new CheckoutAssetMail(
|
|
||||||
$assetRequiringAcceptance,
|
|
||||||
$user,
|
|
||||||
$actor,
|
|
||||||
$acceptance,
|
|
||||||
'A note goes here',
|
|
||||||
false,
|
|
||||||
))->assertHasSubject('Reminder: You have Unaccepted Assets.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testContent()
|
#[DataProvider('data')]
|
||||||
|
public function testSubjectLineAndOpening($data)
|
||||||
{
|
{
|
||||||
$user = User::factory()->create();
|
[
|
||||||
$actor = User::factory()->create();
|
'asset' => $asset,
|
||||||
|
'acceptance' => $acceptance,
|
||||||
$assetRequiringAcceptance = Asset::factory()->requiresAcceptance()->create();
|
'first_time_sending' => $firstTimeSending,
|
||||||
$assetNotRequiringAcceptance = Asset::factory()->doesNotRequireAcceptance()->create();
|
'expected_subject' => $expectedSubject,
|
||||||
|
'expected_opening' => $expectedOpening,
|
||||||
$acceptance = CheckoutAcceptance::factory()->for($assetRequiringAcceptance, 'checkoutable')->create();
|
] = $data();
|
||||||
|
|
||||||
(new CheckoutAssetMail(
|
(new CheckoutAssetMail(
|
||||||
$assetRequiringAcceptance,
|
$asset,
|
||||||
$user,
|
User::factory()->create(),
|
||||||
$actor,
|
User::factory()->create(),
|
||||||
$acceptance,
|
$acceptance,
|
||||||
'A note goes here',
|
'A note goes here',
|
||||||
true,
|
$firstTimeSending,
|
||||||
))->assertSeeInText('A new item has been checked out under your name that requires acceptance, details are below.');
|
))->assertHasSubject($expectedSubject)
|
||||||
|
->assertSeeInText($expectedOpening);
|
||||||
(new CheckoutAssetMail(
|
|
||||||
$assetNotRequiringAcceptance,
|
|
||||||
$user,
|
|
||||||
$actor,
|
|
||||||
null,
|
|
||||||
'A note goes here',
|
|
||||||
true,
|
|
||||||
))->assertSeeInText('A new item has been checked out under your name, details are below.');
|
|
||||||
|
|
||||||
(new CheckoutAssetMail(
|
|
||||||
$assetRequiringAcceptance,
|
|
||||||
$user,
|
|
||||||
$actor,
|
|
||||||
$acceptance,
|
|
||||||
'A note goes here',
|
|
||||||
false,
|
|
||||||
))->assertSeeInText('An item was recently checked out under your name that requires acceptance, details are below.');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue