You are here

function CommerceProductCRUDTestCase::testCommerceProductTokens in Commerce Core 7

Test product Token replacement.

File

modules/product/tests/commerce_product.test, line 187
Unit tests for the commerce product module.

Class

CommerceProductCRUDTestCase
Test the product and product type CRUD.

Code

function testCommerceProductTokens() {
  $product = commerce_product_new('product');
  $creator = $this
    ->drupalCreateUser();
  $product->sku = $this
    ->randomName(10);
  $product->title = $this
    ->randomName(10);
  $product->uid = $creator->uid;
  commerce_product_save($product);
  $this
    ->assertEqual(token_replace('[commerce-product:product-id]', array(
    'commerce-product' => $product,
  )), $product->product_id, '[commerce-product:product-id] was replaced with the product ID.');
  $this
    ->assertEqual(token_replace('[commerce-product:sku]', array(
    'commerce-product' => $product,
  )), $product->sku, '[commerce-product:sku] was replaced with the SKU.');
  $this
    ->assertEqual(token_replace('[commerce-product:type]', array(
    'commerce-product' => $product,
  )), $product->type, '[commerce-product:type] was replaced with the product type.');
  $this
    ->assertEqual(token_replace('[commerce-product:type-name]', array(
    'commerce-product' => $product,
  )), commerce_product_type_get_name($product->type), '[commerce-product:type-name] was replaced with the product type.');
  $this
    ->assertEqual(token_replace('[commerce-product:title]', array(
    'commerce-product' => $product,
  )), $product->title, '[commerce-product:title] was replaced with the title.');
  $this
    ->assertNotIdentical(strpos(token_replace('[commerce-product:edit-url]', array(
    'commerce-product' => $product,
  )), url('admin/commerce/products/' . $product->product_id . '/edit')), FALSE, '[commerce-product:edit-url] was replaced with the edit URL.');
  $this
    ->assertEqual(token_replace('[commerce-product:creator:uid]', array(
    'commerce-product' => $product,
  )), $product->uid, '[commerce-product:creator:uid] was replaced with the uid of the creator.');
  $this
    ->assertEqual(token_replace('[commerce-product:creator:name]', array(
    'commerce-product' => $product,
  )), check_plain(format_username($creator)), '[commerce-product:creator:name] was replaced with the name of the author.');
  $this
    ->assertEqual(token_replace('[commerce-product:created]', array(
    'commerce-product' => $product,
  )), format_date($product->created, 'medium'), '[commerce-product:created] was replaced with the created date.');
  $this
    ->assertEqual(token_replace('[commerce-product:changed]', array(
    'commerce-product' => $product,
  )), format_date($product->changed, 'medium'), '[commerce-product:changed] was replaced with the changed date.');
}