With patch

Drupal test run
---------------

Tests to be run:
 - Node and user token replacement (Drupal\system\Tests\System\TokenReplaceTest)
 - Token replacement unit test (Drupal\system\Tests\System\TokenReplaceUnitTest)

Test run started:
 Monday, January 21, 2013 - 23:20

Test summary
------------

Node and user token replacement 6 passes, 0 fails, and 0 exceptions
Token replacement unit test 30 passes, 0 fails, and 0 exceptions

Test run duration: 6 sec

real	0m6.435s
user	0m5.087s
sys	0m0.352s

without patch

Drupal test run
---------------

Tests to be run:
 - Token replacement (Drupal\system\Tests\System\TokenReplaceTest)

Test run started:
 Monday, January 21, 2013 - 23:22

Test summary
------------

Token replacement 36 passes, 0 fails, and 0 exceptions

Test run duration: 19 sec

real	0m20.438s
user	0m16.275s
sys	0m0.930s

Comments

alexpott’s picture

Status: Active » Needs review

Go bot...

sun’s picture

Issue tags: +Test suite performance
berdir’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceUnitTest.phpundefined
@@ -0,0 +1,140 @@
+    // Install default system configuration.
+    config_install_default_config('module', 'system');

This should now use $this->installConfig()

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new11.27 KB

Re-roll.

berdir’s picture

Issue tags: -Test suite performance

#4: token-unit-test-1895018-4.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Test suite performance

The last submitted patch, token-unit-test-1895018-4.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new11.97 KB

Re-roll. We have separate tests for nodes and users, so I converted the useful parts over (clear option, sanitize) and dropped the other test)

Should also be easy to extract a base class for token tests and convert all the other token tests to DUBT.

Before

$ php core/scripts/run-tests.sh --url http://d8/ --class "Drupal\system\Tests\System\TokenReplaceTest"

Drupal test run
---------------

Tests to be run:
 - Token replacement (Drupal\system\Tests\System\TokenReplaceTest)

Test run started:
 Saturday, August 10, 2013 - 16:17

Test summary
------------

Token replacement 36 passes, 0 fails, and 0 exceptions

Test run duration: 22 sec

After

$ php core/scripts/run-tests.sh --url http://d8/ --class "Drupal\system\Tests\System\TokenReplaceUnitTest"

Drupal test run
---------------

Tests to be run:
 - Token replacement unit test (Drupal\system\Tests\System\TokenReplaceUnitTest)

Test run started:
 Saturday, August 10, 2013 - 16:16

Test summary
------------

Token replacement unit test 44 passes, 0 fails, and 0 exceptions

Test run duration: 1 sec
dawehner’s picture

@@ -99,33 +76,63 @@ function testSystemTokenRecognition() {
+  function testClear() {

This should have a visilbity

@@ -99,33 +76,63 @@ function testSystemTokenRecognition() {
+    $source = '[site:name]';
+    // No user passed in, should be untouched.
+    $source .= '[user:name]';
+    // Non-existing token.
+    $source .= '[bogus:token]';

It is good to not test all kind of tokens but just the ones which take care that the generic functionality is ensured.

@@ -99,33 +76,63 @@ function testSystemTokenRecognition() {
+    $target = check_plain(config('system.site')->get('name'));
...
+    $safe_slogan = filter_xss_admin($slogan);
...
+    $tests['[site:mail]'] = config('system.site')->get('mail');

At least here where code is not really moved let's replace check_plain/config/filter_xss_admin

@@ -99,33 +76,63 @@ function testSystemTokenRecognition() {
+    $slogan = '<blink>Slogan</blink>';

OT: Sadly < blink > got removed from firefox.

berdir’s picture

StatusFileSize
new25.32 KB

Had some more fun with this. Changed to use methods, config factory, function visibility, extracted a base class and also converted the node token replace tests to DUBT. Most of the others are a bit ugly and rely on web helper methods to create comments, terms, upload files and all kinds of crazyness.

Status: Needs review » Needs work
Issue tags: -Test suite performance

The last submitted patch, token-unit-test-1895018-9.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
Issue tags: +Test suite performance

#9: token-unit-test-1895018-9.patch queued for re-testing.

berdir’s picture

Title: Convert some token tests to DrupalUnitTestBase » Convert token API and node token tests to DrupalUnitTestBase

Updating title.

berdir’s picture

StatusFileSize
new21.41 KB

Re-roll. #2026339: Remove text_sanitize() since we have TextProcessed as an EntityNG computed property will conflict with this one again but less ugly, just applies the same change for the processed field.

Status: Needs review » Needs work

The last submitted patch, token-unit-test-1895018-13.patch, failed testing.

steveoliver’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Needs a reroll

berdir’s picture

Issue tags: +Novice

This should be quite easy.

danylevskyi’s picture

Status: Needs work » Needs review
Issue tags: -Novice, -Needs reroll
StatusFileSize
new24.09 KB

Status: Needs review » Needs work

The last submitted patch, 1895018-18.patch, failed testing.

berdir’s picture

+++ b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php
@@ -21,30 +30,36 @@ public static function getInfo() {
+    $this->installSchema('user', array('users_roles'));

You can remove this line, then it should work.

berdir’s picture

Issue tags: +Novice, +Needs reroll

Tagging for reroll

danylevskyi’s picture

Status: Needs work » Needs review
StatusFileSize
new618 bytes
new24.03 KB

Status: Needs review » Needs work

The last submitted patch, 1895018-22.patch, failed testing.

berdir’s picture

The drop is always moving :)

Thanks for the re-roll, now try adding node_revision to the tables from node.module.

ceardach’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new3.45 KB
new23.99 KB

Added node_revision to the tables list. Also converted $node->getBCEntity() to merely $node since the EntityBCDecorator class has been removed.

dawehner’s picture

Just a couple of nitpicks found.

  1. +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php
    @@ -58,41 +72,40 @@ function testNodeTokenReplacement() {
    +    $tests['[node:created:since]'] = format_interval(REQUEST_TIME - $node->getCreatedTime(), 2, $this->languageInterface->id);
    +    $tests['[node:changed:since]'] = format_interval(REQUEST_TIME - $node->getChangedTime(), 2, $this->languageInterface->id);
    

    Time for a short advertisement: #2111349: Move format_plural to the string translation service and format_interval to the date service.

  2. +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php
    @@ -58,41 +72,40 @@ function testNodeTokenReplacement() {
    -    $settings['body'] = array(array('value' => $this->randomName(32), 'summary' => ''));
    ...
    +      'body' => array(array('value' => $this->randomName(32), 'format' => 'plain_text')),
    

    So if you don't specify the summary you end up with an empty summary? This makes sense.

  3. +++ b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceUnitTest.php
    @@ -0,0 +1,163 @@
    +    $tests['[date:short]'] = format_date($date, 'short', '', NULL, $this->languageInterface->id);
    +    $tests['[date:medium]'] = format_date($date, 'medium', '', NULL, $this->languageInterface->id);
    +    $tests['[date:long]'] = format_date($date, 'long', '', NULL, $this->languageInterface->id);
    +    $tests['[date:custom:m/j/Y]'] = format_date($date, 'custom', 'm/j/Y', NULL, $this->languageInterface->id);
    

    Just in case you want to touch these lines, there is a service for format_date.

  4. +++ b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceUnitTest.php
    @@ -0,0 +1,163 @@
    +  }
    +}
    

    Let's make an empty line between here.

  5. +++ b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceUnitTestBase.php
    @@ -0,0 +1,48 @@
    +  public static $modules = array('system');
    +
    +  public function setUp() {
    

    According to https://drupal.org/node/325974 we do now have @inheritdoc on the setUp method as well.

  6. +++ b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceUnitTestBase.php
    @@ -0,0 +1,48 @@
    +    $this->languageInterface = language(Language::TYPE_INTERFACE);
    

    You could directly replace that with return \Drupal::languageManager()->getLanguage(Language::TYPE_INTERFACE);

ceardach’s picture

Status: Needs review » Needs work
berdir’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new24.22 KB
new2.35 KB

Re-rolled, using format() and formatInterval() of the date service. That one seems important enough to deserve a Drupal::date() method...

Status: Needs review » Needs work

The last submitted patch, 28: 1895018-28.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new24.26 KB
new1.75 KB

Variable naming fail.

sun’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Novice

Awesome - RTBC it it comes back green.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3274283 and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

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

yesct’s picture

We are finding the $languageInterface property name confusing. This issue changed $language_interface to languageInterface in some places, and looking at the patch here, it added:

+  /**
+   * The interface language.
+   *
+   * @var \Drupal\Core\Language\Language
+   */
+  protected $languageInterface;

it seems like it's really the interface language (not a LanguageInterface).

So we have the issue: #2270339: $languageInterface is a misleading variable name in TokenReplaceUnitTestBase
Feedback there would be helpful on the new name.