While working on #1806334: Replace the node listing at /node with a view, I noticed that LocaleContentTest only uses the standard profile because it needs two content types.

By just creating content types when needed, it halved the test run times.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Status: Active » Needs review
FileSize
7.1 KB

See attached.

xjm’s picture

Excellent patch.

+++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleContentTest.phpundefined
@@ -198,12 +201,12 @@ function testContentTypeDirLang() {
-  protected function createNodeArticle($langcode) {
-    $this->drupalGet('node/add/article');
+  protected function createNode($langcode, $type) {
+    $this->drupalGet("node/add/$type");
     $node_title = $this->randomName();
     $node_body =  $this->randomName();
     $edit = array(
-      'type' => 'article',
+      'type' => $type,
       'title' => $node_title,
       'body' => array($langcode => array(array('value' => $node_body))),
       'langcode' => $langcode,

Maybe we can remove this helper entirely, and instead add an optional $langcode parameter to drupalCreateNode()? Edit: Or just make drupalCreateNode() use the langcode provided when generating a random body.

xjm’s picture

Issue tags: +Testing system, +VDC
xjm’s picture

Assigned: Unassigned » xjm

Discussed with @tim.plunkett in IRC; I'll add something along the lines of #3.

xjm’s picture

FileSize
8.14 KB
12.41 KB

Attached:

  • Updates WebTestBase::drupalCreateNode() to automatically use the provided langcode when generating a body. (This can of course be overridden.)
  • Adds a proper docblock and constants to WebTestBase::drupalCreateNode() while I'm at it.
  • Updates LocaleContentTest to get rid of the superfluous helper and just use drupalCreateNode() directly.
  • Removes t() from the assertions in the updated methods since this is going to collide with #1797364: Remove t() from assertion messages in tests for the locale module anyway.

Didn't test it locally; I don't yet guarantee there are no typos. ;)

Status: Needs review » Needs work

The last submitted patch, locale-1812170-6.patch, failed testing.

xjm’s picture

+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.phpundefined
@@ -186,27 +186,58 @@ function drupalGetNodeByTitle($title, $reset = FALSE) {
+    // If a langcode is provided in $settings, use it as the default language
+    // for generating a random body; otherwise, use LANGUAGE_NOT_SPECIFIED.
+    $langcode = (!empty($settings['langcode']) ? $settings['langcode'] : LANGUAGE_NOT_SPECIFIED;
...
+      'body'      => array($langcode => array(array())),
...
-      'langcode'  => LANGUAGE_NOT_SPECIFIED,
+      'langcode'  => $langcode,

Oh. Looking more closely, these lines might not actually be correct. Down below it does this:

  // Merge body field value and format separately.
  $body = array(
    'value' => $this->randomName(32), 
    'format' => filter_default_format(),
  );
  $settings['body'][$settings['langcode']][0] += $body;
xjm’s picture

And indeed there was a typo:

Parse error: syntax error, unexpected ';' in ./core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php on line 226
xjm’s picture

Status: Needs work » Needs review
FileSize
12.41 KB
9.17 KB

So, two versions; one includes the change to drupalCreateNode(); the other does not. Let's see if there's any difference as far as tests are concerned.

Status: Needs review » Needs work

The last submitted patch, locale-webtestbase-1812170-10.patch, failed testing.

xjm’s picture

Status: Needs work » Needs review
FileSize
9.17 KB

So that answers that question.

Status: Needs review » Needs work

The last submitted patch, locale-1812170-12.patch, failed testing.

xjm’s picture

Assigned: xjm » Unassigned
Status: Needs work » Needs review

There we go.

Filed #1812732: Use constants instead of integers in drupalCreateNode() and improve its documentation for the earlier cleanups and to better document the behavior with the langcodes.

xjm’s picture

Er. Where did you go, patch? Re-uploading...

chx’s picture

Status: Needs review » Reviewed & tested by the community

That looks good.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Yay, faster and more generally useful tests!

Boo, doesn't apply. ;(

xjm’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
9.9 KB

Just a rebase.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Yay! Committed and pushed to 8.x.

tim.plunkett’s picture

Hmm were you sure this was going to pass? Testbot has been running for over an hour due to the commits, without finishing once.

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