When trying to extend the DrupalWebTestCase, setUp could only be called by the class extending, and arguments from inherited classes are ignored.
In may case I'm extending DrupalWebTestCase to create DrupaServiceTestCase, being responsible of configuring the services module to test the implmentation modules: node_service, system_service, and so..

So DrupalServiceTestCase will enable modules: services, xmlrpc_server, services_keyauth, user_service and system_service, all required to do service requests. Later on, each test file will only enable the implementaion module: parent::setUp('comment_service') to perform the tests.

As setUp() only accept arguments (they are later collected using func_get_args) there is no way for DrupalServiceTestCase (in this example) to include modules from the test cases when calling the parent::setUp from the test cases. Actually, it's possible, but only 1 module can be included. I foreseen that when creating the views_service test case, view_service and views modules should have to be enabled, and this is currently impossible.

Comments

ilo’s picture

I'm creating the issue after an IRC conversation with boombatower

boombatower’s picture

Assigned: Unassigned » boombatower
Status: Active » Needs review
StatusFileSize
new1.42 KB

Tested on blog modules by changing its argument to an array and it worked fine, bot will test if more common syntax still works.

ilo’s picture

Thanks for taking this so fast, boombatower..

Note: There is a typo in the comment

* arguments containing the modules to enabl enable for the duration of the

boombatower’s picture

StatusFileSize
new1.41 KB

Good call.

damien tournoud’s picture

Status: Needs review » Needs work

If you really want to change the signature, just make setUp() accept only one $modules arguments.

Anyway, regarding the original issue: calling call_user_func_array(array($this, 'parent::setUp'), $modules) should work.

ilo’s picture

I tried using call_user_func_array that but didn't work (probably my fault). Will try again (thanks for recalling me on this).

I guess using only an array as argument is the best solution, and for sure will break currently existing tests.

boombatower’s picture

The reason I didn't switch it...was due to the fact that we are past API changes...so not sure if that will get in since it will require all tests to be changed.

boombatower’s picture

Project: Drupal core » SimpleTest
Version: 7.x-dev » 7.x-2.x-dev
Component: simpletest.module » Code

Lets go the full way and do just array.

boombatower’s picture

Status: Needs work » Needs review
StatusFileSize
new1.23 KB
boombatower’s picture

Status: Needs review » Fixed

Committed.

boombatower’s picture

Will need to followup by changing tests.

ilo’s picture

Thank you very much for the work!

yched’s picture

I'm not sure of the exact meaning of Simpletest contrib 7.x branch as opposed to D7 core, but I'd really support the change. The current setUp($module_1, $module_2, ...) syntax forces convoluted code to build helper classes extending DrupalWebTestCase while allowing subclasses to enable their own custom set of modules.

from field.test:

class FieldTestCase extends DrupalWebTestCase {
function setUp() {
// Call parent::setUp().
$args = func_get_args();
call_user_func_array(array('parent', 'setUp'), $args);

// do stuff...
}
}

Status: Fixed » Closed (fixed)

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

yched’s picture

damien tournoud’s picture

Project: SimpleTest » Drupal core
Version: 7.x-2.x-dev » 7.x-dev
Component: Code » simpletest.module
Assigned: boombatower » Unassigned
Status: Closed (fixed) » Patch (to be ported)

Let's reconsider this for core.

boombatower’s picture

If we do we can use PGP to make a quick script to update all tests.

I will be providing a merge patch between simpletest 2.x and HEAD once I get browser integration complete. Doesn't directly related to this issue, but since it was moved back from 2.x just to keep everyone informed.

chx’s picture

Category: feature » bug
Priority: Normal » Critical
Status: Patch (to be ported) » Needs review
StatusFileSize
new587 bytes

This is surprisingly simple and per http://drupal.org/node/644628#comment-2578850 makes a lot of testcases unusable.

robloach’s picture

Status: Needs review » Reviewed & tested by the community
webchick’s picture

Status: Reviewed & tested by the community » Needs work

Let's get rid of that ugly-assed workaround in FieldTestCase::setUp() while we're at it.

chx’s picture

Status: Needs work » Needs review
StatusFileSize
new2.53 KB
yched’s picture

Status: Needs review » Reviewed & tested by the community

Yay.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, setup_array_too.patch, failed testing.

chx’s picture

Status: Needs work » Needs review
StatusFileSize
new2.53 KB
boombatower’s picture

Status: Needs review » Reviewed & tested by the community
scor’s picture

Status: Reviewed & tested by the community » Needs work

#24 does not apply any longer. Also, the EOL whitespace below needs to be removed:

+++ modules/simpletest/drupal_web_test_case.php	2010-02-11 16:06:15 +0000
@@ -1089,7 +1089,9 @@ class DrupalWebTestCase extends DrupalTe
+   *   Either a single array containing a list of modules to enabled or a ¶
aspilicious’s picture

StatusFileSize
new2.69 KB

Just a reroll, don't ask me to explain this...

aspilicious’s picture

Status: Needs work » Needs review
boombatower’s picture

Status: Needs review » Reviewed & tested by the community

Shall we?

effulgentsia’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.62 KB

Sorry. Couldn't help doing a little cleanup. Minor code change from #27, but still a code change, so back to "needs review".

yched’s picture

+++ modules/simpletest/drupal_web_test_case.php	26 Mar 2010 15:06:37 -0000
@@ -1159,10 +1160,12 @@ class DrupalWebTestCase extends DrupalTe
-    // Install modules needed for this test.
-    if ($modules = func_get_args()) {
-      module_enable($modules, TRUE);
+    // Install modules needed for this test. This could have been passed in as
+    // either a single array argument or a variable number of string arguments.
+    if (!is_array($modules)) {
+      $modules = func_get_args();
     }
+    module_enable($modules, TRUE);

This will run module_enable($modules) even if $modules is an empty array ? Not sure this is a big deal though.

Other than that, looks good to me.

Powered by Dreditor.

effulgentsia’s picture

StatusFileSize
new3.53 KB

With #31.

yched’s picture

Status: Needs review » Reviewed & tested by the community

RTBC if green.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, setup_array_too-610072-32.patch, failed testing.

yched’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new3.54 KB

Simple reroll - RTBC if green.

dries’s picture

I would be nice to add a @todo to remove the legacy stuff in D8.

boombatower’s picture

Seems like a good idea, since that is the plan.

yched’s picture

StatusFileSize
new3.66 KB

Added the @todo.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

This has been hanging around awhile and is holding up other tests. Since the only additional requirements Dries gave in #36 was to add the todo, and this was to-done ;), committed to HEAD.

Status: Fixed » Closed (fixed)

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