Blame view

tests/Feature/Common/ItemsTest.php 1.71 KB
b7c7a5f6   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  <?php
  
  namespace Tests\Feature\Common;
  
  use App\Models\Common\Item;
  use Illuminate\Http\UploadedFile;
  use Tests\Feature\FeatureTestCase;
  
  class ItemsTest extends FeatureTestCase
  {
  	public function testItShouldBeShowTheItemsPage()
  	{
  		$this
  			->loginAs()
  			->get(route('items.index'))
  			->assertStatus(200)
  			->assertSee('Items');
  	}
  
  	public function testItShouldBeShowCreateItemPage()
  	{
  		$this
  			->loginAs()
  			->get(route('items.create'))
  			->assertStatus(200)
  			->assertSee('New Item');
  	}
  
  	public function testItShouldStoreAnItem()
  	{
  		$picture = UploadedFile::fake()->create('image.jpg');
  
  		$item = [
  			'name' => $this->faker->title,
  			'sku' => $this->faker->languageCode,
  			'picture' => $picture,
  			'description' => $this->faker->text(100),
  			'purchase_price' => $this->faker->randomFloat(2,10,20),
  			'sale_price' => $this->faker->randomFloat(2,10,20),
  			'quantity' => $this->faker->randomNumber(2),
  			'category_id' => $this->company->categories()->first()->id,
  			'tax_id' => $this->company->taxes()->first()->id,
  			'enabled' => $this->faker->boolean ? 1 : 0
  		];
  
  		$this
  			->loginAs()
  			->post(route('items.store'), $item)
  			->assertStatus(302)
  			->assertRedirect(route('items.index'));
  		$this->assertFlashLevel('success');
  	}
  
  	public function testItShouldEditItem()
  	{
  		$item = factory(Item::class)->create();
  
  		$this
  			->loginAs()
  			->get(route('items.edit', ['item' => $item]))
  			->assertStatus(200)
  			->assertSee($item->name);
  	}
  
  	public function testItShouldDeleteItem()
  	{
  		$item = factory(Item::class)->create();
  
  		$this
  			->loginAs()
  			->delete(route('items.destroy', ['item' => $item]))
  			->assertStatus(302)
  			->assertRedirect(route('items.index'));
  
  		$this->assertFlashLevel('success');
  	}
  }