akaunting/tests/Feature/Settings/CategoriesTest.php

82 lines
2.2 KiB
PHP
Raw Normal View History

2018-10-04 16:53:16 +03:00
<?php
namespace Tests\Feature\Settings;
2019-11-17 15:06:00 +03:00
use App\Jobs\Setting\CreateCategory;
2018-10-04 16:53:16 +03:00
use Tests\Feature\FeatureTestCase;
class CategoriesTest extends FeatureTestCase
{
public function testItShouldSeeCategoryListPage()
{
$this->loginAs()
->get(route('categories.index'))
->assertStatus(200)
->assertSeeText(trans_choice('general.categories', 2));
}
public function testItShouldSeeCategoryCreatePage()
{
$this->loginAs()
->get(route('categories.create'))
->assertStatus(200)
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.categories', 1)]));
}
public function testItShouldCreateCategory()
{
$this->loginAs()
->post(route('categories.store'), $this->getCategoryRequest())
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-04 16:53:16 +03:00
$this->assertFlashLevel('success');
}
public function testItShouldSeeCategoryUpdatePage()
{
2019-11-17 15:06:00 +03:00
$category = $this->dispatch(new CreateCategory($this->getCategoryRequest()));
2018-10-04 16:53:16 +03:00
$this->loginAs()
->get(route('categories.edit', ['category' => $category->id]))
->assertStatus(200)
->assertSee($category->name);
}
public function testItShouldUpdateCategory()
{
$request = $this->getCategoryRequest();
2019-11-17 15:06:00 +03:00
$category = $this->dispatch(new CreateCategory($request));
2018-10-04 16:53:16 +03:00
$request['name'] = $this->faker->text(15);
$this->loginAs()
->patch(route('categories.update', $category->id), $request)
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-04 16:53:16 +03:00
$this->assertFlashLevel('success');
}
public function testItShouldDeleteCategory()
{
2019-11-17 15:06:00 +03:00
$category = $this->dispatch(new CreateCategory($this->getCategoryRequest()));
2018-10-04 16:53:16 +03:00
$this->loginAs()
->delete(route('categories.destroy', $category->id))
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-04 16:53:16 +03:00
$this->assertFlashLevel('success');
}
private function getCategoryRequest()
{
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
2019-11-17 15:06:00 +03:00
'type' => 'item',
2018-10-04 16:53:16 +03:00
'color' => $this->faker->text(15),
'enabled' => $this->faker->boolean ? 1 : 0
];
}
2019-04-02 18:51:06 +03:00
}