akaunting/tests/Feature/Common/ItemsTest.php

78 lines
1.7 KiB
PHP
Raw Normal View History

2018-07-14 13:26:29 +03:00
<?php
namespace Tests\Feature\Common;
2019-11-17 15:06:00 +03:00
use App\Jobs\Common\CreateItem;
2019-11-22 17:35:46 +03:00
use App\Models\Common\Item;
2018-07-14 13:26:29 +03:00
use Tests\Feature\FeatureTestCase;
class ItemsTest extends FeatureTestCase
{
2018-09-29 22:41:17 +03:00
public function testItShouldSeeItemListPage()
2018-07-14 13:26:29 +03:00
{
2018-09-29 17:28:34 +03:00
$this->loginAs()
2018-07-14 13:26:29 +03:00
->get(route('items.index'))
->assertStatus(200)
2018-09-29 22:41:17 +03:00
->assertSeeText(trans_choice('general.items', 2));
2018-07-14 13:26:29 +03:00
}
2018-09-29 22:41:17 +03:00
public function testItShouldSeeItemCreatePage()
2018-07-14 13:26:29 +03:00
{
2018-09-29 17:28:34 +03:00
$this->loginAs()
2018-07-14 13:26:29 +03:00
->get(route('items.create'))
->assertStatus(200)
2018-09-29 22:41:17 +03:00
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.items', 1)]));
2018-07-14 13:26:29 +03:00
}
2018-09-29 22:41:17 +03:00
public function testItShouldCreateItem()
2018-07-14 13:26:29 +03:00
{
2018-09-29 17:28:34 +03:00
$this->loginAs()
2020-01-07 01:28:05 +03:00
->post(route('items.store'), $this->getRequest())
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-09-29 17:28:34 +03:00
2018-07-14 13:26:29 +03:00
$this->assertFlashLevel('success');
}
2018-09-29 22:41:17 +03:00
public function testItShouldSeeItemUpdatePage()
2018-07-14 13:26:29 +03:00
{
2020-01-07 01:28:05 +03:00
$item = $this->dispatch(new CreateItem($this->getRequest()));
2018-07-14 13:26:29 +03:00
2018-09-29 17:28:34 +03:00
$this->loginAs()
2020-01-13 10:55:19 +03:00
->get(route('items.edit', $item->id))
2018-07-14 13:26:29 +03:00
->assertStatus(200)
->assertSee($item->name);
}
2018-09-29 22:41:17 +03:00
public function testItShouldUpdateItem()
{
2020-01-07 01:28:05 +03:00
$request = $this->getRequest();
2018-09-29 22:41:17 +03:00
2019-11-17 15:06:00 +03:00
$item = $this->dispatch(new CreateItem($request));
2018-09-29 22:41:17 +03:00
2019-11-18 10:54:26 +03:00
$request['name'] = $this->faker->text(15);
2018-09-29 22:41:17 +03:00
$this->loginAs()
->patch(route('items.update', $item->id), $request)
2020-01-13 17:20:28 +03:00
->assertStatus(200)
->assertSee($request['name']);
2018-09-29 22:41:17 +03:00
$this->assertFlashLevel('success');
}
2018-07-14 13:26:29 +03:00
public function testItShouldDeleteItem()
{
2020-01-07 01:28:05 +03:00
$item = $this->dispatch(new CreateItem($this->getRequest()));
2018-07-14 13:26:29 +03:00
2018-09-29 17:28:34 +03:00
$this->loginAs()
2020-01-13 10:55:19 +03:00
->delete(route('items.destroy', $item->id))
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-07-14 13:26:29 +03:00
$this->assertFlashLevel('success');
}
2020-01-07 01:28:05 +03:00
public function getRequest()
{
return factory(Item::class)->states('enabled')->raw();
}
2019-04-02 18:51:06 +03:00
}