toby/tests/Feature/SelectYearPeriodTest.php
Krzysztof Rewak f6d59f8bfb
- directory refactor (#32)
* - directory refactor

* - readme.md update

* Update readme.md

Co-authored-by: Adrian Hopek <adrian.hopek@blumilk.pl>

* Update readme.md

Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>

* Update readme.md

Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>

* Update readme.md

Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>

* Update readme.md

Co-authored-by: Adrian Hopek <adrian.hopek@blumilk.pl>
Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
2022-01-26 12:31:26 +01:00

54 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Carbon;
use Tests\FeatureTestCase;
use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\User;
class SelectYearPeriodTest extends FeatureTestCase
{
use DatabaseMigrations;
protected YearPeriodRetriever $yearPeriodRetriever;
protected function setUp(): void
{
parent::setUp();
$this->yearPeriodRetriever = $this->app->make(YearPeriodRetriever::class);
}
public function testUserCanSelectNextYearPeriod(): void
{
$nextYearPeriod = $this->createYearPeriod(Carbon::now()->year + 1);
$user = User::factory()->create();
$this->actingAs($user)
->post("/year-periods/{$nextYearPeriod->id}/select")
->assertRedirect();
$this->assertSame($nextYearPeriod->id, $this->yearPeriodRetriever->selected()->id);
}
public function testUserCannotSelectNextYearPeriodIfDoesntExist(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->post("/year-periods/25/select")
->assertNotFound();
}
public function testIfUserDoesntSelectAnyYearPeriodCurrentActsAsSelected(): void
{
$currentYearPeriod = $this->yearPeriodRetriever->current();
$this->assertSame($currentYearPeriod->id, $this->yearPeriodRetriever->selected()->id);
}
}