View source
<?php
class CommerceBackofficeProductWebTestCase extends DrupalWebTestCase {
function createProductVariationType() {
$name = $this
->randomName();
$type = strtolower($name);
$edit = array(
'product_type[name]' => $name,
'product_type[type]' => $type,
);
$this
->drupalPost('admin/commerce/config/product-variation-types/add', $edit, t('Save product variation type'));
commerce_product_types_reset();
$variation_type = commerce_product_type_load($type);
$this
->assertEqual($variation_type['type'], $type, 'Type saved.');
$instance = field_info_instance('node', 'field_product', $variation_type['type']);
$instance['widget'] = array(
'active' => 1,
'module' => 'inline_entity_form',
'settings' => array(
'fields' => array(),
'type_settings' => array(
'allow_existing' => 0,
'autogenerate_title' => 1,
'delete_references' => 1,
'match_operator' => 'CONTAINS',
'use_variation_language' => 1,
),
),
'type' => 'inline_entity_form',
);
field_update_instance($instance);
return $variation_type;
}
function createProductDisplay($variation_type) {
$title = $this
->randomName();
$sku = $this
->randomName();
$price = mt_rand(1, 100);
$edit = array(
'title' => $title,
'field_product[und][form][sku]' => $sku,
'field_product[und][form][commerce_price][und][0][amount]' => $price,
);
$this
->drupalPost('node/add/' . $variation_type, $edit, t('Save'));
$node = $this
->drupalGetNodeByTitle($title);
$wrapper = entity_metadata_wrapper('node', $node);
$this
->assertEqual($wrapper->field_product[0]->sku
->value(), $sku, 'Sku saved.');
$this
->assertEqual($wrapper->field_product[0]->commerce_price->amount
->value(), $price * 100);
return $node;
}
}
class CommerceBackofficeProductTestCase extends CommerceBackofficeProductWebTestCase {
public static function getInfo() {
return array(
'name' => 'Commerce backoffice product interface',
'description' => 'Test the commerce backoffice product interface.',
'group' => 'Commerce backoffice product',
);
}
function setUp() {
parent::setUp('inline_entity_form', 'commerce_backoffice_product');
$this->admin_user = $this
->drupalCreateUser(array(
'administer product types',
));
$this
->drupalLogin($this->admin_user);
$this->variationType = $this
->createProductVariationType();
node_type_cache_reset();
}
function testProductDisplay() {
drupal_static_reset('checkPermissions');
$admin_user = $this
->drupalCreateUser(array(
'create ' . $this->variationType['type'] . ' content',
'create commerce_product entities of bundle ' . $this->variationType['type'],
));
$this
->drupalLogin($admin_user);
$productDisplay = $this
->createProductDisplay($this->variationType['type']);
$this
->drupalGet('node/' . $productDisplay->nid);
$this
->assertResponse(200);
}
}