Running phpunit against 8.x HEAD

phpunit --filter AjaxCommandsTest
PHPUnit 3.7.21 by Sebastian Bergmann.

Configuration read from /Volumes/devdisk/dev/sites/drupal8alt.dev/core/phpunit.xml.dist

................EE.....

Time: 03:55, Memory: 38.25Mb

There were 2 errors:

1) Drupal\Tests\Core\Ajax\AjaxCommandsTest::testOpenDialogCommand
Array to string conversion

/Volumes/devdisk/dev/sites/drupal8alt.dev/core/modules/views/tests/Drupal/views/Tests/Controller/ViewAjaxControllerTest.php:188
/Volumes/devdisk/dev/sites/drupal8alt.dev/core/lib/Drupal/Core/Ajax/OpenDialogCommand.php:128
/Volumes/devdisk/dev/sites/drupal8alt.dev/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php:328
/usr/local/php5-5.4.16-20130615-025727/lib/php/PHPUnit/TextUI/Command.php:176
/usr/local/php5-5.4.16-20130615-025727/lib/php/PHPUnit/TextUI/Command.php:129

2) Drupal\Tests\Core\Ajax\AjaxCommandsTest::testOpenModalDialogCommand
Array to string conversion

/Volumes/devdisk/dev/sites/drupal8alt.dev/core/modules/views/tests/Drupal/views/Tests/Controller/ViewAjaxControllerTest.php:188
/Volumes/devdisk/dev/sites/drupal8alt.dev/core/lib/Drupal/Core/Ajax/OpenDialogCommand.php:128
/Volumes/devdisk/dev/sites/drupal8alt.dev/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php:352
/usr/local/php5-5.4.16-20130615-025727/lib/php/PHPUnit/TextUI/Command.php:176
/usr/local/php5-5.4.16-20130615-025727/lib/php/PHPUnit/TextUI/Command.php:129

FAILURES!
Tests: 23, Assertions: 21, Errors: 2.
CommentFileSizeAuthor
#4 2173171.4.patch749 bytesalexpott
#1 2173171.1.patch753 bytesalexpott

Comments

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new753 bytes

The problem is with the test version of drupal_render() in Drupal\views\Tests\Controller\ViewAjaxControllerTest. The AjaxCommandsTest results in drupal_render() being called with an array consisting of only an item keyed by #attached.

It is not necessary to cast the input to drupal_render() to a string if the #markup key does not exist.

This was broken by replacing drupal_get_library() with drupal_render() in \Drupal\Core\Ajax\OpenDialogCommand done by #2171071: Rename drupal_add_library() to _drupal_add_library() and remove its uses

Considering D8 is supposed to have PHP 5.4 as a minimum version this is critical.

Status: Needs review » Needs work

The last submitted patch, 1: 2173171.1.patch, failed testing.

DeFr’s picture

Returning an array from a drupal_render implementation feels like a bug coming ; concatenating the drupal_render output with a string and using various string functions on the return is supposed to work, but with this patch it'll trigger another "Array to string conversion" warning.

If it doesn't, it probably means that this code isn't really hit, and simply returning an empty string should work ?

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new749 bytes

@DeFr well with the current implementation in this patch all the tests pass on 5.3 and 5.4. Which is not the case for HEAD. Personally, I find the practice of mocking procedural functions in tests a bit distasteful especially for a function that has the side effects that drupal_render() can have. But we are where we are. It is really hard to know what the right thing to return here is - but I agree that we need to return a string as this is what drupal_render is supposed to do - so empty string it is.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

especially for a function that has the side effects that drupal_render() can have

Very true.

But, this change is fine for the unit test.

dawehner’s picture

Yes, we should commit this like that, but we are having an actual other problem: the drupal_render method is overridden multiple times with different behavior. I think we should avoid that from the ground up, see my patch in https://drupal.org/comment/8374925#comment-8374925

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks for the quick turnaround on this!

Status: Fixed » Closed (fixed)

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