You are here

public function CommerceMessageTokenTest::testTokenCustomMessageType in Commerce Message 7

File

./commerce_message.test, line 414

Class

CommerceMessageTokenTest

Code

public function testTokenCustomMessageType() {
  $message_type = message_type_create('foo', array(
    'message_text' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'Example text.\\n\\n!order-summary',
        ),
      ),
    ),
  ));
  $message_type
    ->save();
  $message = message_create('foo', array(), $this->store_admin);
  $message
    ->save();
  $this
    ->assertFalse(isset($message->arguments['!order-summary']));

  // Attach field to message type.
  $fields['message_commerce_order']['field'] = array(
    'type' => 'entityreference',
    'module' => 'entityreference',
    'cardinality' => '1',
    'translatable' => FALSE,
    'settings' => array(
      'target_type' => 'commerce_order',
      'handler' => 'base',
      'handler_settings' => array(
        'target_bundles' => array(),
        'sort' => array(
          'type' => 'property',
          'property' => 'order_id',
          'direction' => 'ASC',
        ),
      ),
    ),
    'locked' => TRUE,
  );
  $fields['message_commerce_order']['instances'][] = array(
    'entity_type' => 'message',
    'bundles' => array(
      'foo',
    ),
    'label' => 'Order',
    'required' => TRUE,
    'widget' => array(
      'type' => 'entityreference_autocomplete',
      'module' => 'entityreference',
      'settings' => array(
        'match_operator' => 'CONTAINS',
        'size' => '60',
        'path' => '',
      ),
    ),
    'settings' => array(),
    'display' => array(
      'default' => array(
        'label' => 'above',
        'type' => 'entityreference_label',
        'settings' => array(
          'link' => FALSE,
        ),
        'module' => 'entityreference',
        'weight' => 0,
      ),
    ),
  );
  foreach ($fields as $field_name => $info) {
    $field = $info['field'];
    $field += array(
      'field_name' => $field_name,
    );
    if (!field_info_field($field_name)) {
      field_create_field($field);
    }
    foreach ($info['instances'] as $instance) {
      foreach ($instance['bundles'] as $bundle) {
        $instance['bundle'] = $bundle;
        unset($instance['bundles']);
        $instance['field_name'] = $field_name;
        if (!field_info_instance($instance['entity_type'], $instance['field_name'], $instance['bundle'])) {
          field_create_instance($instance);
        }
      }
    }
  }
  $order = $this
    ->createDummyOrder();
  $message = message_create('foo', array(), $this->store_admin);
  $message
    ->wrapper()->message_commerce_order = $order;
  $message
    ->save();
  $this
    ->assertTrue(isset($message->arguments['!order-summary']));
}