I was playing with the UbercartTestCase found in uc_cart/uc_cart.test and noticed that there is no way to extend this class and make any changes to the setUp process (like enabling other contrib modules). This is because when you attempt to call parent::setUp(/*<with your list of modules>*/) the list of modules are ignored and replaced with the list UbercartTestCase setUp provides,

On the other hand when you extend the DrupalWebTestCase, the parent::setUp function accepts the names of modules as arguments to enable for each test.

I'm not sure if my solution is the best way to do this, but I managed to find a way to modify the setUp function to also process any arguments it receives when calling parent::setUp() using the following code:

-    // Enable the core Ubercart modules and dependencies.
-    parent::setUp('uc_store', 'uc_cart', 'ca', 'uc_order', 'uc_product', 'token');
+    // Enable the core Ubercart modules and dependencies and any other modules passed as arguments.
+    $args = array_merge(func_get_args(), array('uc_store', 'uc_cart', 'ca', 'uc_order', 'uc_product', 'token'));
+    call_user_func_array(array('parent', 'setUp'), $args);

This is only a small change but it just makes it that slightly bit easier to write simpletests for ubercart.

CommentFileSizeAuthor
uc_cart-test.patch799 bytesunivate

Comments

Island Usurper’s picture

Status: Needs review » Fixed

Makes sense to me. Thanks, and committed.

I wonder why the list of modules isn't given as an array to setUp() in the first place. Seems like that would make it easier to add more parameters in the future.

Oh well. We'll keep following core's lead here.

Status: Fixed » Closed (fixed)
Issue tags: -Simpletest

Automatically closed -- issue fixed for 2 weeks with no activity.