-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStoreItemTest.php
More file actions
139 lines (106 loc) · 3.8 KB
/
StoreItemTest.php
File metadata and controls
139 lines (106 loc) · 3.8 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
use App\User;
use App\Models\StoreItem;
use App\Models\StoreCategory;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class StoreItemTest extends TestCase
{
//use DatabaseMigrations;
/** @test */
public function check_if_overview_can_be_accessed()
{
//Login with the admin user
$this->login_with_admin_user();
//Check if overview can be accessed
$this->visit('/webpanel/store/items')->see('All Items');
}
/** @test */
public function create_item_and_check_if_exists()
{
//Delete category if already exists
$this->delete_item_if_exists();
//Create a test Category
$this->create_category();
//Login with the admin user
$this->login_with_admin_user();
//Go to the create page and verify it
$this->visit('/webpanel/store/items/create')->see('Create a new Item');
//Fill out the form
$this->type('test-itm', 'name');
$this->type('Test Itm', 'display_name');
$this->type('Integration Test Item', 'description');
$this->type('integration_test', 'type');
$this->type('integration_slot', 'loadout_slot');
$this->type('7669035', 'price');
$this->type($this->get_category_id(), 'category_id');
$this->press('Create Item');
//Get the ID of the Item
$item_id = $this->get_item_id();
$this->assertNotNull($item_id); //Check that the item exists
//TODO: Verify that the item is shown at the gui
//Visit the Edit page
$this->visit('/webpanel/store/items/'.$item_id.'/edit')->see('Edit Item test-itm');
$this->see("test-itm"); //Check for the name
$this->see("integration_slot"); //Check for the loadout slot
//Make a Edit and Save
$this->type('integration_test_2', 'type'); //Change the type
$this->press('Edit Item');
$this->visit('/webpanel/store/items/'.$item_id.'/edit')->see('Edit Item test-itm');
//Confirm the edit
$this->see('integration_test_2'); //Verify the changed type
//TODO: Add a remove and a remove+refund button so the item can be deleted from the edit menu
//Delete the category
//$this->press('Remove ' . $item_id);
//Confirm that its deleted
//$this->assertNull(StoreItem::where('name', 'test-itm')->first());
}
private function get_item_id()
{
$item = StoreItem::where('name', 'test-itm')->first();
if ($item != NULL)
{
return $item->id;
}
else
{
return NULL;
}
}
private function delete_item_if_exists()
{
$item = StoreItem::where('name', 'test-itm');
if ($item != null)
{
$item->delete();
}
}
private function create_category()
{
$category = StoreCategory::where('display_name', 'test-cat')->first();
if($category != null)
{
$category->delete();
}
$category = new StoreCategory();
$category->priority = 5;
$category->display_name = "test-cat";
$category->description = "Cat for Itm Test";
$category->require_plugin = "integration_test";
$category->web_description = "Test Category for Item Test";
$category->web_color = "#000000";
$category->enable_server_restriction = 0;
$category->save();
}
private function get_category_id()
{
$category = StoreCategory::where('display_name','test-cat')->first();
return $category->id;
}
private function login_with_admin_user()
{
$admin = User::where('name', 'admin')->first();
$this->actingAs($admin);
}
}