akaunting/tests/Feature/Common/ItemsTest.php
2019-11-18 10:54:26 +03:00

89 lines
2.2 KiB
PHP

<?php
namespace Tests\Feature\Common;
use App\Jobs\Common\CreateItem;
use Illuminate\Http\UploadedFile;
use Tests\Feature\FeatureTestCase;
class ItemsTest extends FeatureTestCase
{
public function testItShouldSeeItemListPage()
{
$this->loginAs()
->get(route('items.index'))
->assertStatus(200)
->assertSeeText(trans_choice('general.items', 2));
}
public function testItShouldSeeItemCreatePage()
{
$this->loginAs()
->get(route('items.create'))
->assertStatus(200)
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.items', 1)]));
}
public function testItShouldCreateItem()
{
$this->loginAs()
->post(route('items.store'), $this->getItemRequest())
->assertStatus(200);
$this->assertFlashLevel('success');
}
public function testItShouldSeeItemUpdatePage()
{
$item = $this->dispatch(new CreateItem($this->getItemRequest()));
$this->loginAs()
->get(route('items.edit', ['item' => $item->id]))
->assertStatus(200)
->assertSee($item->name);
}
public function testItShouldUpdateItem()
{
$request = $this->getItemRequest();
$item = $this->dispatch(new CreateItem($request));
$request['name'] = $this->faker->text(15);
$this->loginAs()
->patch(route('items.update', $item->id), $request)
->assertStatus(200);
$this->assertFlashLevel('success');
}
public function testItShouldDeleteItem()
{
$item = $this->dispatch(new CreateItem($this->getItemRequest()));
$this->loginAs()
->delete(route('items.destroy', ['item' => $item]))
->assertStatus(200);
$this->assertFlashLevel('success');
}
private function getItemRequest()
{
$picture = UploadedFile::fake()->create('image.jpg');
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'picture' => $picture,
'description' => $this->faker->text(100),
'purchase_price' => $this->faker->randomFloat(2, 10, 20),
'sale_price' => $this->faker->randomFloat(2, 10, 20),
'category_id' => $this->company->categories()->type('item')->pluck('id')->first(),
'tax_id' => '',
'enabled' => $this->faker->boolean ? 1 : 0
];
}
}