1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Functional tests for the commerce product ui module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Test the product and product type CRUD.
|
10
|
*/
|
11
|
class CommerceProductUIAdminTest extends CommerceBaseTestCase {
|
12
|
|
13
|
|
14
|
/**
|
15
|
* Implementation of getInfo().
|
16
|
*/
|
17
|
public static function getInfo() {
|
18
|
return array(
|
19
|
'name' => 'Product administration',
|
20
|
'description' => 'Tests creating, deleting and editing products and product types.',
|
21
|
'group' => 'Drupal Commerce',
|
22
|
);
|
23
|
}
|
24
|
|
25
|
|
26
|
/**
|
27
|
* Implementation of setUp().
|
28
|
*/
|
29
|
function setUp() {
|
30
|
$modules = parent::setUpHelper('all');
|
31
|
parent::setUp($modules);
|
32
|
|
33
|
// Set a clean starting point. $_GET can be different between the UI test
|
34
|
// runner and the command line one. As a consequence, the 'active' classes
|
35
|
// on the links can end up being different.
|
36
|
$_GET['q'] = '';
|
37
|
|
38
|
// User creation for different operations.
|
39
|
$this->store_admin = $this->createStoreAdmin();
|
40
|
$this->store_customer = $this->createStoreCustomer();
|
41
|
|
42
|
// Get the product types, and if the default product type is not present,
|
43
|
// create it.
|
44
|
$product_types = commerce_product_types();
|
45
|
if (empty($product_types['product'])) {
|
46
|
$this->createDummyProductType('product');
|
47
|
commerce_product_types_reset();
|
48
|
}
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Test the permissions to access the product listing.
|
53
|
*/
|
54
|
public function testCommerceProductUIAccessProductList() {
|
55
|
// Login with normal user.
|
56
|
$this->drupalLogin($this->store_customer);
|
57
|
|
58
|
// Access to the admin product list.
|
59
|
$this->drupalGet('admin/commerce/products');
|
60
|
|
61
|
$this->assertResponse(403, t('Normal user is not able to access the product admin list page'));
|
62
|
|
63
|
// Login with store admin.
|
64
|
$this->drupalLogin($this->store_admin);
|
65
|
|
66
|
// Access to the admin product list.
|
67
|
$this->drupalGet('admin/commerce/products');
|
68
|
|
69
|
$this->assertResponse(200, t('Store admin user can access the product admin list page'));
|
70
|
|
71
|
// Ensure that the link for create products is in place.
|
72
|
$this->assertText(t('Add a product'), t('%addproduct link is present in the admin list page', array('%addproduct' => t('Add a product'))));
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* Test the add product process.
|
77
|
*/
|
78
|
public function testCommerceProductUIAddProduct() {
|
79
|
// Login with normal user.
|
80
|
$this->drupalLogin($this->store_customer);
|
81
|
|
82
|
// Access to the admin product creation page.
|
83
|
$this->drupalGet('admin/commerce/products/add/product');
|
84
|
|
85
|
$this->assertResponse(403, t('Normal user is not able to add a product using the admin interface'));
|
86
|
|
87
|
// Login with store admin.
|
88
|
$this->drupalLogin($this->store_admin);
|
89
|
|
90
|
// Access to the admin product creation page.
|
91
|
$this->drupalGet('admin/commerce/products/add/product');
|
92
|
|
93
|
$this->assertResponse(200, t('Store admin user is allowed to add a product using the admin interface'));
|
94
|
|
95
|
// Check the integrity of the add form.
|
96
|
$this->pass(t('Test the integrity of the product add form:'));
|
97
|
$this->assertFieldByName('sku', NULL, t('SKU field is present'));
|
98
|
$this->assertFieldByXPath('//input[@name="sku" and contains(@class, "required")]', NULL, t('SKU field is required'));
|
99
|
$this->assertFieldByName('title', NULL, t('Title field is present'));
|
100
|
$this->assertFieldByXPath('//input[@name="title" and contains(@class, "required")]', NULL, t('Title field is required'));
|
101
|
$this->assertFieldByName('commerce_price[und][0][amount]', NULL, t('Price field is present'));
|
102
|
$this->assertFieldByName('status', NULL, t('Status field is present'));
|
103
|
$status_required = $this->xpath('//div[contains(@class, "form-item-status")]/label/span[contains(@class, "form-required")]');
|
104
|
$this->assertFalse(empty($status_required), t('Status field is required'));
|
105
|
$this->assertFieldById('edit-submit', t('Save product'), t('Save product button is present'));
|
106
|
$this->assertFieldById('edit-save-continue', t('Save and add another'), t('Save an add another button is present'));
|
107
|
$this->assertRaw(l(t('Cancel'), 'admin/commerce/products'), t('Cancel link is present'));
|
108
|
|
109
|
// Try to save the product and check validation messages.
|
110
|
$this->drupalPost(NULL, array(), t('Save product'));
|
111
|
|
112
|
$this->assertText(t('Product SKU field is required'), t('Validation message for SKU is displayed when tryin to submit the form with the field empty.'));
|
113
|
$this->assertText(t('Title field is required'), t('Validation message for title is displayed when tryin to submit the form with the field empty.'));
|
114
|
|
115
|
// Create the product.
|
116
|
$price = rand(2,500);
|
117
|
$edit = array(
|
118
|
'sku' => 'PROD-01',
|
119
|
'title' => $this->randomName(10),
|
120
|
'commerce_price[und][0][amount]' => commerce_currency_amount_to_decimal($price, 'USD'),
|
121
|
'status' => 1,
|
122
|
);
|
123
|
$this->drupalPost(NULL, $edit, t('Save product'));
|
124
|
|
125
|
// Load the product and wrap it.
|
126
|
$product = commerce_product_load_by_sku($edit['sku']);
|
127
|
$product_wrapper = entity_metadata_wrapper('commerce_product', $product);
|
128
|
|
129
|
// Check the product in database
|
130
|
$this->pass(t('Test the product creation in database:'));
|
131
|
$this->assertTrue($product_wrapper->sku->value() == $edit['sku'], t('SKU stored in database correctly set'));
|
132
|
$this->assertTrue($product_wrapper->title->value() == $edit['title'], t('Title stored in database correctly set'));
|
133
|
|
134
|
$this->assertTrue($product_wrapper->commerce_price->amount->value() == $price, t('Amount stored in database correctly set'));
|
135
|
$this->assertTrue($product->status == $edit['status'], t('Status stored in database correctly set'));
|
136
|
|
137
|
// Check the product listing
|
138
|
$this->pass(t('Test the product listing after saving a product'));
|
139
|
$this->assertTrue($this->url == url('admin/commerce/products', array('absolute' => TRUE)), t('Landing page after save is the list of products'));
|
140
|
$this->assertText(t('Product saved.'), t('%message message is present', array('%message' => t('Product saved'))));
|
141
|
$this->assertText($edit['sku'], t('SKU of the product is present'));
|
142
|
$this->assertText($edit['title'], t('Title of the product is present'));
|
143
|
|
144
|
// Assert the product creation.
|
145
|
$this->assertProductCreated($product, $this->store_admin);
|
146
|
}
|
147
|
|
148
|
|
149
|
/**
|
150
|
* Test the save and add another product.
|
151
|
*/
|
152
|
public function testCommerceProductUISaveAndAddAnother() {
|
153
|
// Login with store admin.
|
154
|
$this->drupalLogin($this->store_admin);
|
155
|
|
156
|
// Access to the admin product creation page.
|
157
|
$this->drupalGet('admin/commerce/products/add/product');
|
158
|
|
159
|
// Create the product.
|
160
|
$price = rand(2, 500);
|
161
|
$edit = array(
|
162
|
'sku' => 'PROD-01',
|
163
|
'title' => $this->randomName(10),
|
164
|
'commerce_price[und][0][amount]' => commerce_currency_amount_to_decimal($price, 'USD'),
|
165
|
'status' => 1,
|
166
|
);
|
167
|
// Save and add another.
|
168
|
$this->drupalPost(NULL, $edit, t('Save and add another'));
|
169
|
|
170
|
// Check the product in database
|
171
|
$product = commerce_product_load_by_sku($edit['sku']);
|
172
|
$product_wrapper = entity_metadata_wrapper('commerce_product', $product);
|
173
|
$this->pass(t('Test the product creation in database:'));
|
174
|
$this->assertTrue($product_wrapper->sku->value() == $edit['sku'], t('SKU stored in database correctly set'));
|
175
|
$this->assertTrue($product_wrapper->title->value() == $edit['title'], t('Title stored in database correctly set'));
|
176
|
$this->assertTrue($product_wrapper->commerce_price->amount->value() == $price, t('Amount stored in database correctly set'));
|
177
|
$this->assertTrue($product->status == $edit['status'], t('Status stored in database correctly set'));
|
178
|
|
179
|
// Check if we are in the product creation page.
|
180
|
$this->assertTrue($this->url == url('admin/commerce/products/add/product', array('absolute' => TRUE)), t('Landing page after save and add another is the product creation page'));
|
181
|
}
|
182
|
|
183
|
/**
|
184
|
* Test the edit process for a product.
|
185
|
*/
|
186
|
public function testCommerceProductUIEditProduct() {
|
187
|
// Create dummy product.
|
188
|
$product = $this->createDummyProduct('PROD-01', 'Product One');
|
189
|
$product_wrapper = entity_metadata_wrapper('commerce_product', $product);
|
190
|
|
191
|
// Login with normal user.
|
192
|
$this->drupalLogin($this->store_customer);
|
193
|
|
194
|
// Access to the edit product page.
|
195
|
$this->drupalGet('admin/commerce/products/' . $product->product_id . '/edit');
|
196
|
|
197
|
$this->assertResponse(403, t('Normal user is not able to access the product edit page'));
|
198
|
|
199
|
// Login with store admin.
|
200
|
$this->drupalLogin($this->store_admin);
|
201
|
|
202
|
// Access to the edit product page.
|
203
|
$this->drupalGet('admin/commerce/products/' . $product->product_id . '/edit');
|
204
|
|
205
|
$this->assertResponse(200, t('Store admin user can access the product edit page'));
|
206
|
|
207
|
// Check the fields and buttons for the edit product form.
|
208
|
$this->pass(t('Test the integrity of the edit product form:'));
|
209
|
$this->assertFieldByName('sku', $product_wrapper->sku->value(), t('SKU field is present'));
|
210
|
$this->assertFieldByName('title', $product_wrapper->title->value(), t('Title field is present'));
|
211
|
$this->assertFieldByName('commerce_price[und][0][amount]', commerce_currency_amount_to_decimal($product_wrapper->commerce_price->amount->value(), $product_wrapper->commerce_price->currency_code->value()), t('Price field is present'));
|
212
|
$this->assertFieldByName('status', $product->status, t('Status field is present'));
|
213
|
$this->assertFieldById('edit-submit', t('Save product'), t('Save product button is present'));
|
214
|
$this->assertRaw(l(t('Cancel'), 'admin/commerce/products'), t('Cancel link is present'));
|
215
|
|
216
|
// Change the product values.
|
217
|
$price = rand(2, 500);
|
218
|
$edit = array(
|
219
|
'sku' => 'PROD-02',
|
220
|
'title' => $this->randomName(10),
|
221
|
'commerce_price[und][0][amount]' => commerce_currency_amount_to_decimal($price, 'USD'),
|
222
|
'status' => 0,
|
223
|
);
|
224
|
$this->drupalPost(NULL, $edit, t('Save product'));
|
225
|
|
226
|
// Check the product in database
|
227
|
$product = commerce_product_load_by_sku($edit['sku']);
|
228
|
$product_wrapper = entity_metadata_wrapper('commerce_product', $product);
|
229
|
$this->pass(t('Test the product edit in database:'));
|
230
|
$this->assertTrue($product_wrapper->sku->value() == $edit['sku'], t('SKU stored in database correctly set'));
|
231
|
$this->assertTrue($product_wrapper->title->value() == $edit['title'], t('Title stored in database correctly set'));
|
232
|
$this->assertTrue($product_wrapper->commerce_price->amount->value() == $price, t('Amount stored in database correctly set'));
|
233
|
$this->assertTrue($product->status == $edit['status'], t('Status stored in database correctly set'));
|
234
|
|
235
|
// Check the product listing
|
236
|
$this->pass(t('Test the product form after editing a product'));
|
237
|
$this->assertTrue($this->url == url('admin/commerce/products/' . $product->product_id . '/edit', array('absolute' => TRUE)), t('Landing page after save is the list of products'));
|
238
|
$this->assertText(t('Product saved.'), t('%message message is present', array('%message' => t('Product saved'))));
|
239
|
$this->assertFieldByName('sku', $edit['sku'], t('SKU field has the correct value'));
|
240
|
$this->assertFieldByName('title', $edit['title'], t('Title field has the correct value'));
|
241
|
$this->assertFieldByName('commerce_price[und][0][amount]', $edit['commerce_price[und][0][amount]'], t('Price field has the correct value'));
|
242
|
$this->assertFieldByName('status', $edit['status'], t('Status field is present'));
|
243
|
$this->assertFieldById('edit-submit', t('Save product'), t('Save product button is present'));
|
244
|
$this->assertRaw(l(t('Cancel'), 'admin/commerce/products'), t('Cancel link is present'));
|
245
|
}
|
246
|
|
247
|
/**
|
248
|
* Test the delete link in the product form.
|
249
|
*/
|
250
|
public function testCommerceProductUICancelEditProduct() {
|
251
|
// Login with store admin.
|
252
|
$this->drupalLogin($this->store_admin);
|
253
|
|
254
|
// Access to the admin product list.
|
255
|
$this->drupalGet('admin/commerce/products/add/product');
|
256
|
|
257
|
// Click on cancel link.
|
258
|
$this->clickLink(t('Cancel'));
|
259
|
|
260
|
$this->assertTrue($this->url == url('admin/commerce/products', array('absolute' => TRUE)), t('Landing page after cancel is the product listing page'));
|
261
|
}
|
262
|
|
263
|
/**
|
264
|
* Test deleting a product.
|
265
|
*/
|
266
|
public function testCommerceProductUIDeleteProduct() {
|
267
|
// Create dummy product.
|
268
|
$product = $this->createDummyProduct('PROD-01', 'Product One');
|
269
|
|
270
|
// Login with normal user.
|
271
|
$this->drupalLogin($this->store_customer);
|
272
|
|
273
|
// Access to the delete product page.
|
274
|
$this->drupalGet('admin/commerce/products/' . $product->product_id . '/delete');
|
275
|
|
276
|
$this->assertResponse(403, t('Normal user is not able to access the product deletion page'));
|
277
|
|
278
|
// Login with store admin.
|
279
|
$this->drupalLogin($this->store_admin);
|
280
|
|
281
|
// Access to the delete product page.
|
282
|
$this->drupalGet('admin/commerce/products/' . $product->product_id . '/delete');
|
283
|
|
284
|
$this->assertResponse(200, t('Store admin user can access the product delete page'));
|
285
|
|
286
|
// Check the integrity of the product delete confirmation form.
|
287
|
$this->pass('Test the product delete confirmation form:');
|
288
|
$this->assertTitle(t('Are you sure you want to delete !title?', array('!title' => $product->title)) . ' | Drupal', t('The confirmation message is displayed'));
|
289
|
$this->assertText($product->sku, t('SKU of the product is present'));
|
290
|
$this->assertText($product->title, t('Title of the product is present'));
|
291
|
$this->assertText(t('Deleting this product cannot be undone.', array('@sku' => $product->sku)), t('A warning notifying the user about the action can\'t be undone is displayed.'));
|
292
|
$this->assertFieldById('edit-submit', t('Delete'), t('Delete button is present'));
|
293
|
$this->assertText(t('Cancel'), t('Cancel is present'));
|
294
|
|
295
|
// Delete the product
|
296
|
$this->drupalPost(NULL, array(), t('Delete'));
|
297
|
|
298
|
// Check for the product in database.
|
299
|
$deleted_product = commerce_product_load_multiple(array($product->product_id), array(), TRUE);
|
300
|
$this->assertFalse(reset($deleted_product), t('After deleting it, the product is no more in database'));
|
301
|
|
302
|
$this->assertTrue($this->url == url('admin/commerce/products', array('absolute' => TRUE)), t('Landing page after deleting a product is the product listing page'));
|
303
|
|
304
|
// Check if the product is present in the product listing.
|
305
|
$this->assertRaw(t('%title has been deleted.', array('%title' => $product->title)), t('\'Product has been deleted\' message is displayed'));
|
306
|
$this->assertNoText($product->sku, t('Product SKU is not present'));
|
307
|
$this->assertText(t('No products have been created yet.'), t('Empty product listing message is displayed'));
|
308
|
}
|
309
|
|
310
|
|
311
|
/**
|
312
|
* Test trying to delete a product associated with a Line Item.
|
313
|
*/
|
314
|
public function testCommerceProductUIDeleteProductLineItem() {
|
315
|
// Create dummy product.
|
316
|
$product = $this->createDummyProduct('PROD-01', 'Product One');
|
317
|
|
318
|
// Associate the product in an order.
|
319
|
$order = $this->createDummyOrder($this->store_customer->uid, array($product->product_id => 1));
|
320
|
|
321
|
// Login with store admin.
|
322
|
$this->drupalLogin($this->store_admin);
|
323
|
|
324
|
// Access to the edit product page.
|
325
|
$this->drupalGet('admin/commerce/products/' . $product->product_id . '/delete');
|
326
|
|
327
|
$this->pass('Assertions for trying to delete a product associated to a line item:');
|
328
|
$this->assertText(t('This product is referenced by a line item on Order @order_num and therefore cannot be deleted. Disable it instead.', array('@order_num' => $order->order_id)), t('Product delete restriction message is displayed correctly'));
|
329
|
$this->assertFieldByXPath('//input[@id="edit-submit" and @disabled="disabled"]', NULL, t('Delete button is present and is disabled'));
|
330
|
}
|
331
|
|
332
|
/**
|
333
|
* Test the access to the product types listing page.
|
334
|
*/
|
335
|
public function testCommerceProductUIAccessProductTypes() {
|
336
|
// Login with normal user.
|
337
|
$this->drupalLogin($this->store_customer);
|
338
|
|
339
|
// Access to the product types listing.
|
340
|
$this->drupalGet('admin/commerce/products/types');
|
341
|
|
342
|
$this->assertResponse(403, t('Normal user is not able to access the product types listing page'));
|
343
|
|
344
|
// Login with store admin.
|
345
|
$this->drupalLogin($this->store_admin);
|
346
|
|
347
|
// Access to the product types listing.
|
348
|
$this->drupalGet('admin/commerce/products/types');
|
349
|
|
350
|
$this->assertResponse(200, t('Store admin user can access the product types listing page'));
|
351
|
|
352
|
// Ensure that the link for create product types is in place.
|
353
|
$this->assertText(t('Add product type'), t('\'Add product type\' link is present in the admin list page'));
|
354
|
|
355
|
// Get all the product types and check if they are listed.
|
356
|
$product_types = commerce_product_types();
|
357
|
foreach ($product_types as $type) {
|
358
|
$this->assertText($type['name'], t('%type is present in the product type listing', array('%type' => $type['name'])));
|
359
|
}
|
360
|
}
|
361
|
|
362
|
/**
|
363
|
* Test adding a new product type.
|
364
|
*/
|
365
|
public function testCommerceProductUIAddProductType() {
|
366
|
// Login with normal user.
|
367
|
$this->drupalLogin($this->store_customer);
|
368
|
|
369
|
// Access to the product types add form.
|
370
|
$this->drupalGet('admin/commerce/products/types/add');
|
371
|
|
372
|
$this->assertResponse(403, t('Normal user is not able to access the product types add page'));
|
373
|
|
374
|
// Login with store admin.
|
375
|
$this->drupalLogin($this->store_admin);
|
376
|
|
377
|
// Access to the product types add form.
|
378
|
$this->drupalGet('admin/commerce/products/types/add');
|
379
|
|
380
|
$this->assertResponse(200, t('Store admin user can access the product types add page'));
|
381
|
|
382
|
// Create an additional product type.
|
383
|
$edit = array(
|
384
|
'product_type[name]' => 'New Product Type',
|
385
|
'product_type[type]' => 'new_product_type',
|
386
|
);
|
387
|
$this->drupalPost(NULL, $edit, t('Save product type'));
|
388
|
|
389
|
// Load all product types.
|
390
|
commerce_product_types_reset();
|
391
|
$product_types = commerce_product_types();
|
392
|
|
393
|
// Check if the product type has been created in database and if it appears
|
394
|
// in the product types listing.
|
395
|
$this->assertTrue(!empty($product_types[$edit['product_type[type]']]), t('Product type has been correctly created'));
|
396
|
$this->assertEqual($this->url, url('admin/commerce/products/types', array('absolute' => TRUE)), t('Redirect page after creating a product type is the product types listing'));
|
397
|
$this->assertText(t('Product type saved'), t('Message after saving a new product type is displayed'));
|
398
|
$this->assertText($edit['product_type[name]'], t('Product type just created appears in product types listing'));
|
399
|
|
400
|
// Test the Add and save fields.
|
401
|
// Access to the product types add form.
|
402
|
$this->drupalGet('admin/commerce/products/types/add');
|
403
|
$edit = array(
|
404
|
'product_type[name]' => 'Additional Product Type',
|
405
|
'product_type[type]' => 'additional_product_type',
|
406
|
);
|
407
|
$this->drupalPost(NULL, $edit, t('Save and add fields'));
|
408
|
|
409
|
$this->assertEqual($this->url, url('admin/commerce/products/types/' . strtr($edit['product_type[type]'], '_', '-') . '/fields', array('absolute' => TRUE)), t('Redirect page after creating a product type using \'Save and add fields\' button is the product type field manage screen'));
|
410
|
$this->assertText(t('Product type saved'), t('Message after saving a new product type is displayed'));
|
411
|
$this->assertText(t('Product SKU'), t('SKU field is present in the product type manage fields screen'));
|
412
|
$this->assertText(t('Title'), t('Title field is present in the product type manage fields screen'));
|
413
|
$this->assertText(t('Status'), t('Status field is present in the product type manage fields screen'));
|
414
|
|
415
|
// Check the field instances for that content type.
|
416
|
field_cache_clear();
|
417
|
$field_instances = field_info_instances('commerce_product', $edit['product_type[type]']);
|
418
|
foreach ($field_instances as $instance) {
|
419
|
$this->assertText($instance['label'], t('Field %field is present in the product type manage fields screen', array('%field' => $instance['label'])));
|
420
|
}
|
421
|
}
|
422
|
|
423
|
/**
|
424
|
* Edit a product type.
|
425
|
*/
|
426
|
public function testCommerceProductUIEditProductType() {
|
427
|
// Login with normal user.
|
428
|
$this->drupalLogin($this->store_customer);
|
429
|
|
430
|
// Access to the product types edit form.
|
431
|
$this->drupalGet('admin/commerce/products/types/product/edit');
|
432
|
|
433
|
$this->assertResponse(403, t('Normal user is not able to access the product types edit page'));
|
434
|
|
435
|
// Login with store admin.
|
436
|
$this->drupalLogin($this->store_admin);
|
437
|
|
438
|
// Access to the product types edit form.
|
439
|
$this->drupalGet('admin/commerce/products/types/product/edit');
|
440
|
|
441
|
$this->assertResponse(200, t('Store admin user can access the product types edit page'));
|
442
|
|
443
|
// Load all product types.
|
444
|
$product_types = commerce_product_types();
|
445
|
|
446
|
$this->assertFieldById('edit-product-type-name', $product_types['product']['name'], t('Product type name appears in the correct field of product type edit form'));
|
447
|
$this->assertFieldById('edit-product-type-description', $product_types['product']['description'], t('Product type description appears in the correct field of product type edit form'));
|
448
|
}
|
449
|
|
450
|
/**
|
451
|
* Delete a product type.
|
452
|
*/
|
453
|
public function testCommerceProductUIDeleteProductType() {
|
454
|
// Login with normal user.
|
455
|
$this->drupalLogin($this->store_customer);
|
456
|
|
457
|
// Access to the delete page for a product type.
|
458
|
$this->drupalGet('admin/commerce/products/types/product/delete');
|
459
|
|
460
|
$this->assertResponse(403, t('Normal user is not able to access delete page for the product type'));
|
461
|
|
462
|
// Login with store admin.
|
463
|
$this->drupalLogin($this->store_admin);
|
464
|
|
465
|
// Access to the delete page for a product type.
|
466
|
$this->drupalGet('admin/commerce/products/types/product/delete');
|
467
|
|
468
|
$this->assertResponse(200, t('Store admin can access delete page for the product type'));
|
469
|
|
470
|
// Load all product types.
|
471
|
$product_types = commerce_product_types();
|
472
|
|
473
|
// Check the integrity of the product type delete confirmation form.
|
474
|
$this->pass('Test the product type delete confirmation form:');
|
475
|
$this->assertTitle(t('Are you sure you want to delete the !name product type?', array('!name' => $product_types['product']['name'])) . ' | Drupal', t('The confirmation message is displayed'));
|
476
|
$this->assertText(t('This action cannot be undone'), t('A warning notifying the user about the action can\'t be undone is displayed.'));
|
477
|
$this->assertFieldById('edit-submit', t('Delete'), t('Delete button is present'));
|
478
|
$this->assertText(t('Cancel'), t('Cancel is present'));
|
479
|
|
480
|
// Delete the product type
|
481
|
$this->drupalPost(NULL, array(), t('Delete'));
|
482
|
|
483
|
$this->assertTrue($this->url == url('admin/commerce/products/types', array('absolute' => TRUE)), t('Landing page after deleting a product is the product types listing page'));
|
484
|
|
485
|
// Check if the product is present in the product listing.
|
486
|
$this->assertRaw(t('The product type %name has been deleted.', array('%name' => $product_types['product']['name'])), t('\'Product type has been deleted\' message is displayed'));
|
487
|
|
488
|
// Reload all product types.
|
489
|
commerce_product_types_reset();
|
490
|
$product_types = commerce_product_types();
|
491
|
// Look for the product type.
|
492
|
$this->assertTrue(empty($product_types['product']), t('Product type doesn\'t exist anymore after deletion'));
|
493
|
}
|
494
|
|
495
|
/**
|
496
|
* Delete a product type that already has products.
|
497
|
*/
|
498
|
public function testCommerceProductUIDeleteProductTypeWithProducts() {
|
499
|
// Create dummy product.
|
500
|
$product = $this->createDummyProduct('PROD-01', 'Product One');
|
501
|
|
502
|
// Login with store admin.
|
503
|
$this->drupalLogin($this->store_admin);
|
504
|
|
505
|
// Access to the delete page for a product type.
|
506
|
$this->drupalGet('admin/commerce/products/types/product/delete');
|
507
|
|
508
|
// Load product types.
|
509
|
$product_types = commerce_product_types();
|
510
|
|
511
|
// As the product type has at least one product, it souldn't permit to be
|
512
|
// deleted.
|
513
|
$this->pass(t('Product type has at least one product, test the validation messages:'));
|
514
|
$this->assertTitle(t('Cannot delete the !name product type', array('!name' => $product_types['product']['name'])) . ' | Drupal', t('Validation title of the page displayed correctly.'));
|
515
|
|
516
|
// Get the count of products of the type
|
517
|
$query = new EntityFieldQuery();
|
518
|
|
519
|
$query->entityCondition('entity_type', 'commerce_product', '=')
|
520
|
->entityCondition('bundle', $product_types['product']['type'], '=')
|
521
|
->count();
|
522
|
|
523
|
$count = $query->execute();
|
524
|
|
525
|
$message = format_plural($count,
|
526
|
'There is 1 product of this type. It cannot be deleted.',
|
527
|
'There are @count products of this type. It cannot be deleted.'
|
528
|
);
|
529
|
|
530
|
$this->assertText($message, t('Display the reason why the product type cannot be deleted and show the number of products related to it'));
|
531
|
}
|
532
|
|
533
|
/**
|
534
|
* Access to the manage fields admin screen.
|
535
|
*/
|
536
|
public function testCommerceProductUIProductTypeManageFields() {
|
537
|
// Login with normal user.
|
538
|
$this->drupalLogin($this->store_customer);
|
539
|
|
540
|
// Access to the product type manage fields screen.
|
541
|
$this->drupalGet('admin/commerce/products/types/product/fields');
|
542
|
|
543
|
$this->assertResponse(403, t('Normal user is not able to access the product type manage fields screen'));
|
544
|
|
545
|
// Login with store admin.
|
546
|
$this->drupalLogin($this->store_admin);
|
547
|
|
548
|
// Access to the product type manage fields screen.
|
549
|
$this->drupalGet('admin/commerce/products/types/product/fields');
|
550
|
|
551
|
$this->assertResponse(200, t('Store admin user can access the product type manage fields screen'));
|
552
|
}
|
553
|
|
554
|
/**
|
555
|
* Access to the display fields admin screen.
|
556
|
*/
|
557
|
public function testCommerceProductUIProductTypeDisplayFields() {
|
558
|
// Login with normal user.
|
559
|
$this->drupalLogin($this->store_customer);
|
560
|
|
561
|
// Access to the product type display fields screen.
|
562
|
$this->drupalGet('admin/commerce/products/types/product/display');
|
563
|
|
564
|
$this->assertResponse(403, t('Normal user is not able to access the product type display fields screen'));
|
565
|
|
566
|
// Login with store admin.
|
567
|
$this->drupalLogin($this->store_admin);
|
568
|
|
569
|
// Access to the product type display fields screen.
|
570
|
$this->drupalGet('admin/commerce/products/types/product/display');
|
571
|
|
572
|
$this->assertResponse(200, t('Store admin user can access the product type display fields screen'));
|
573
|
}
|
574
|
}
|