View source
<?php
class CommerceReferenceTableFormatterTest extends CommerceBaseTestCase {
public static function getInfo() {
return array(
'name' => 'Reference Table Formatter Commerce',
'description' => 'Test the table formatter functionality with commerce.',
'group' => 'Reference Table Formatter',
);
}
function setUp() {
$modules = parent::setUpHelper('all');
$modules[] = 'reference_table_formatter';
parent::setUp($modules);
$this->site_admin = $this
->createUserWithPermissionHelper(array(
'site admin',
'store admin',
));
$this
->drupalLogin($this->site_admin);
$this->display_type = $this
->createDummyProductDisplayContentType('product_display', FALSE);
$this->products[1] = $this
->createDummyProduct('PROD-01', 'Product One', 2500);
$this->products[2] = $this
->createDummyProduct('PROD-02', 'Product Two', 3500);
$this
->drupalGet('admin/structure/types/manage/' . strtr($this->display_type->type, '_', '-') . '/fields');
$edit = array(
'fields[_add_new_field][label]' => 'Product',
'fields[_add_new_field][field_name]' => 'product',
'fields[_add_new_field][type]' => 'commerce_product_reference',
'fields[_add_new_field][widget_type]' => 'options_select',
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->drupalPost(NULL, array(), t('Save field settings'));
$this
->drupalPost(NULL, array(
'field[cardinality]' => FIELD_CARDINALITY_UNLIMITED,
), t('Save settings'));
field_cache_clear();
cache_clear_all();
$this->field_name = 'field_product';
$this->field = field_info_field($this->field_name);
$this->field_instance = field_info_instance('node', $this->field_name, $this->display_type->type);
}
public function testCommerceTableFormatter() {
$this
->drupalGet('admin/structure/types/manage/' . strtr($this->display_type->type, '_', '-') . '/display');
$edit = array(
'fields[field_product][type]' => 'reference_table_formatter',
'refresh_rows' => 'field_product',
);
$this
->drupalPostAJAX(NULL, $edit, array(
'op' => t('Refresh'),
));
$this
->drupalPost(NULL, array(), t('Save'));
$this
->drupalPost('node/add/' . strtr($this->display_type->type, '_', '-'), array(
'title' => 'A Product Display Node',
'field_product[und][]' => array(
$this->products[1]->product_id,
$this->products[2]->product_id,
),
), 'Save');
$this
->assertRaw('<th>Product ID</th><th>SKU</th><th>Title</th><th>Price</th>');
$this
->assertRaw('<td>1</td><td>PROD-01</td><td>Product One</td><td><div class="field field-name-commerce-price field-type-commerce-price field-label-hidden"><div class="field-items"><div class="field-item even">$25.00</div></div></div></td>');
$this
->assertRaw('<td>2</td><td>PROD-02</td><td>Product Two</td><td><div class="field field-name-commerce-price field-type-commerce-price field-label-hidden"><div class="field-items"><div class="field-item even">$35.00</div></div></div></td>');
}
}