Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/WalletsTest.php
Show All 25 Lines | class WalletsTest extends TestCase | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('wallets-controller@kolabnow.com'); | $this->deleteTestUser('wallets-controller@kolabnow.com'); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test for getWalletNotice() method | * Test for getWalletNotice() method | ||||
*/ | */ | ||||
public function testGetWalletNotice(): void | public function testGetWalletNotice(): void | ||||
{ | { | ||||
$user = $this->getTestUser('wallets-controller@kolabnow.com'); | $user = $this->getTestUser('wallets-controller@kolabnow.com'); | ||||
$package = \App\Package::where('title', 'kolab')->first(); | $package = \App\Package::where('title', 'kolab')->first(); | ||||
$user->assignPackage($package); | $user->assignPackage($package); | ||||
Show All 21 Lines | public function testGetWalletNotice(): void | ||||
$this->assertSame('You are out of credit, top up your balance now.', $notice); | $this->assertSame('You are out of credit, top up your balance now.', $notice); | ||||
// User/entitlements created slightly more than a month ago, balance=9,99 CHF (monthly) | // User/entitlements created slightly more than a month ago, balance=9,99 CHF (monthly) | ||||
$wallet->owner->created_at = Carbon::now()->subMonthsWithoutOverflow(1)->subDays(1); | $wallet->owner->created_at = Carbon::now()->subMonthsWithoutOverflow(1)->subDays(1); | ||||
$wallet->owner->save(); | $wallet->owner->save(); | ||||
// test "1 month" | // test "1 month" | ||||
$wallet->balance = 999; | $wallet->balance = 990; | ||||
$notice = $method->invoke($controller, $wallet); | $notice = $method->invoke($controller, $wallet); | ||||
$this->assertRegExp('/\((1 month|4 weeks)\)/', $notice); | $this->assertRegExp('/\((1 month|4 weeks)\)/', $notice); | ||||
// test "2 months" | // test "2 months" | ||||
$wallet->balance = 999 * 2.6; | $wallet->balance = 990 * 2.6; | ||||
$notice = $method->invoke($controller, $wallet); | $notice = $method->invoke($controller, $wallet); | ||||
$this->assertRegExp('/\(2 months 2 weeks\)/', $notice); | $this->assertRegExp('/\(2 months 2 weeks\)/', $notice); | ||||
// Change locale to make sure the text is localized by Carbon | // Change locale to make sure the text is localized by Carbon | ||||
\app()->setLocale('de'); | \app()->setLocale('de'); | ||||
// test "almost 2 years" | // test "almost 2 years" | ||||
$wallet->balance = 999 * 23.5; | $wallet->balance = 990 * 23.5; | ||||
$notice = $method->invoke($controller, $wallet); | $notice = $method->invoke($controller, $wallet); | ||||
$this->assertRegExp('/\(1 Jahr 11 Monate\)/', $notice); | $this->assertRegExp('/\(1 Jahr 11 Monate\)/', $notice); | ||||
// Old entitlements, 100% discount | // Old entitlements, 100% discount | ||||
$this->backdateEntitlements($wallet->entitlements, Carbon::now()->subDays(40)); | $this->backdateEntitlements($wallet->entitlements, Carbon::now()->subDays(40)); | ||||
$discount = \App\Discount::where('discount', 100)->first(); | $discount = \App\Discount::where('discount', 100)->first(); | ||||
$wallet->discount()->associate($discount); | $wallet->discount()->associate($discount); | ||||
▲ Show 20 Lines • Show All 261 Lines • Show Last 20 Lines |