function CommerceOrderCRUDTestCase::testCommerceOrderTokens in Commerce Core 7
Test order Token replacement.
File
- modules/
order/ tests/ commerce_order.test, line 102 - Unit tests for the commerce order module.
Class
- CommerceOrderCRUDTestCase
- Test the order and order type CRUD.
Code
function testCommerceOrderTokens() {
$creator = $this
->drupalCreateUser();
$order = commerce_order_new($creator->uid);
$order->mail = $this
->generateEmail();
$order->order_number = $this
->randomName(10);
$order->hostname = $this
->randomName(10);
$order->placed = REQUEST_TIME;
commerce_order_save($order);
$this
->assertEqual(token_replace('[commerce-order:order-id]', array(
'commerce-order' => $order,
)), $order->order_id, '[commerce-order:order-id] was replaced with the order ID.');
$this
->assertEqual(token_replace('[commerce-order:mail]', array(
'commerce-order' => $order,
)), $order->mail, '[commerce-order:mail] was replaced with the mail.');
$this
->assertEqual(token_replace('[commerce-order:hostname]', array(
'commerce-order' => $order,
)), $order->hostname, '[commerce-order:hostname] was replaced with the hostname.');
$this
->assertEqual(token_replace('[commerce-order:type]', array(
'commerce-order' => $order,
)), $order->type, '[commerce-order:type] was replaced with the order type.');
$this
->assertEqual(token_replace('[commerce-order:type-name]', array(
'commerce-order' => $order,
)), commerce_order_type_get_name($order->type), '[commerce-order:type-name] was replaced with the order type.');
$this
->assertEqual(token_replace('[commerce-order:order-number]', array(
'commerce-order' => $order,
)), $order->order_number, '[commerce-order:order-number] was replaced with the order number.');
$this
->assertNotIdentical(strpos(token_replace('[commerce-order:edit-url]', array(
'commerce-order' => $order,
)), url('admin/commerce/orders/' . $order->order_id . '/edit')), FALSE, '[commerce-order:edit-url] was replaced with the edit URL.');
$this
->assertEqual(token_replace('[commerce-order:owner:uid]', array(
'commerce-order' => $order,
)), $order->uid, '[commerce-order:owner:uid] was replaced with the uid of the owner.');
$this
->assertEqual(token_replace('[commerce-order:owner:name]', array(
'commerce-order' => $order,
)), check_plain(format_username($creator)), '[commerce-order:owner:name] was replaced with the name of the owner.');
$this
->assertEqual(token_replace('[commerce-order:created]', array(
'commerce-order' => $order,
)), format_date($order->created, 'medium'), '[commerce-order:created] was replaced with the created date.');
$this
->assertEqual(token_replace('[commerce-order:placed]', array(
'commerce-order' => $order,
)), format_date($order->placed, 'medium'), '[commerce-order:placed] was replaced with the placed date.');
$this
->assertEqual(token_replace('[commerce-order:changed]', array(
'commerce-order' => $order,
)), format_date($order->changed, 'medium'), '[commerce-order:changed] was replaced with the changed date.');
}