From 530acb3616193a8886cf977d5d6dcf62bc9116e6 Mon Sep 17 00:00:00 2001
From: Helior Colorado <me@helior.info>
Date: Tue, 24 Apr 2012 20:26:53 -0700
Subject: [PATCH] Tests loading updated objects during EntityController::save
 method.

---
 modules/product/tests/commerce_product.test        |    6 ++++++
 .../product/tests/commerce_product_crud_test.info  |    6 ++++++
 .../tests/commerce_product_crud_test.module        |   10 ++++++++++
 3 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100644 modules/product/tests/commerce_product_crud_test.info
 create mode 100644 modules/product/tests/commerce_product_crud_test.module

diff --git a/modules/product/tests/commerce_product.test b/modules/product/tests/commerce_product.test
index 4a2e7d0..1d83506 100644
--- a/modules/product/tests/commerce_product.test
+++ b/modules/product/tests/commerce_product.test
@@ -19,6 +19,7 @@ class CommerceProductCRUDTestCase extends CommerceBaseTestCase {
 
   function setUp() {
     $modules = parent::setUpHelper('all');
+    $modules[] = 'commerce_product_crud_test';
     parent::setUp($modules);
 
     $this->site_admin = $this->createSiteAdmin();
@@ -104,6 +105,8 @@ class CommerceProductCRUDTestCase extends CommerceBaseTestCase {
    * Test the product CRUD functions.
    */
   function testCommerceProductCrud() {
+    global $commerce_product_crud_tests;
+
     // Ensure commerce_product_new() returns a new product.
     $new_product = commerce_product_new('product');
     $fields = array('product_id', 'sku', 'type', 'title', 'uid');
@@ -134,6 +137,9 @@ class CommerceProductCRUDTestCase extends CommerceBaseTestCase {
     $return = commerce_product_save($loaded_product);
     $this->assertIdentical($return, SAVED_UPDATED, 'commerce_product_save() successfully updated the product.');
 
+    // Ensure hooks invoked during the save operation can load identical objects.
+    $this->assertTrue($commerce_product_crud_tests['hook_update_identical_uid'], t('Invoked hooks during save operation can successfully load identical object.'));
+
     // Ensure commerce_product_load_by_sku() can load a product by SKU.
     $loaded_product_by_sku = commerce_product_load_by_sku($sku);
     $this->assertEqual($loaded_product_by_sku->product_id, $new_product->product_id, 'The ID of the product loaded via commerce_product_load_by_sku() matches the saved product ID.');
diff --git a/modules/product/tests/commerce_product_crud_test.info b/modules/product/tests/commerce_product_crud_test.info
new file mode 100644
index 0000000..473edcc
--- /dev/null
+++ b/modules/product/tests/commerce_product_crud_test.info
@@ -0,0 +1,6 @@
+name = "Commerce product crud test"
+description = "Support module for product related testing."
+package = Testing
+version = VERSION
+core = 7.x
+hidden = TRUE
diff --git a/modules/product/tests/commerce_product_crud_test.module b/modules/product/tests/commerce_product_crud_test.module
new file mode 100644
index 0000000..f8f5a4d
--- /dev/null
+++ b/modules/product/tests/commerce_product_crud_test.module
@@ -0,0 +1,10 @@
+<?php
+
+/**
+ * Implements hook_commerce_product_update().
+ */
+function commerce_product_crud_test_commerce_product_update($entity) {
+  global $commerce_product_crud_tests;
+  $product = commerce_product_load($entity->product_id);
+  $commerce_product_crud_tests['hook_update_identical_uid'] = $entity->uid === $product->uid;
+}
-- 
1.7.6

