You are here

function CommerceProductCRUDTestCase::testCommerceProductRevisions in Commerce Core 7

Test product revision management.

File

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

Class

CommerceProductCRUDTestCase
Test the product and product type CRUD.

Code

function testCommerceProductRevisions() {
  $new_product = commerce_product_new('product');
  $new_product->sku = $this
    ->randomName(10);
  $new_product->type = 'product';
  $new_product->title = $this
    ->randomName(10);
  $new_product->uid = 1;
  commerce_product_save($new_product);

  // Ensure commerce_product_save() returns an entity with the revision_id set.
  $this
    ->assertNotNull($new_product->revision_id, 'Revision id was created after first save.');

  // Ensure that on update with the revision set to TRUE a new revision is
  // created.
  $old_revision_id = $new_product->revision_id;
  $new_product->revision = TRUE;
  $new_product->title = $this
    ->randomName(10);
  commerce_product_save($new_product);
  $this
    ->assertNotEqual($old_revision_id, $new_product->revision_id, 'New revision was created');

  // Ensure that on update with the revision set to FALSE a new revision is
  // not created.
  $old_revision_id = $new_product->revision_id;
  $new_product->revision = FALSE;
  $new_product->title = $this
    ->randomName(10);
  commerce_product_save($new_product);
  $this
    ->assertEqual($old_revision_id, $new_product->revision_id, 'No new revision was created');
}