Move generatePermutations out of testbase into a trait.

generatePermutations is needed for the conversion of simpletests to phpunit. Lets move it to a trait so tests can use it when needed.

Scope:
Move generatePermutations out of TestBase into a Trait
Make TestBase use that trait
Remove the usages in Unit and Kernel tests of the static call to the method and make them use the trait.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Lendude created an issue. See original summary.

Lendude’s picture

Here we go.

Lendude’s picture

Status: Active » Needs review
dawehner’s picture

+++ b/core/tests/Drupal/Tests/Traits/Core/GeneratePermutationsTrait.php
@@ -0,0 +1,59 @@
+
+namespace Drupal\Tests\Traits\Core;
+
+/**
+ * Adds ability to convert a list of parameters into a stack of permutations.
+ */
+trait GeneratePermutationsTrait {

Aren't permissions a user module feature?

Lendude’s picture

Aren't permissions a user module feature?

Yes they are, not sure what that has to do with this patch :)

It's 'Permutations' not 'permissions'.

dawehner’s picture

Well, this means that the trait should be part of user module ...

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

I'm horrible, I totally misread it.

michielnugter’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, found 2 nits.

+++ b/core/tests/Drupal/Tests/Traits/Core/GeneratePermutationsTrait.php
@@ -0,0 +1,59 @@
+   * // Result:
+   * $permutations == array(
+   *   array('one' => 0, 'two' => 2),
+   *   array('one' => 1, 'two' => 2),
+   *   array('one' => 0, 'two' => 3),
+   *   array('one' => 1, 'two' => 3),
+   * )
+   * @endcode

Seems the example code wasn't updated on:
- TestBase::generatePermutations
- New array format

dawehner’s picture

@michielnugter
Well, does that mean we should really touch it here? There is an issue to fix that bit.

Lendude’s picture

Status: Needs work » Needs review
FileSize
1.06 KB
7.06 KB
+++ b/core/tests/Drupal/Tests/Traits/Core/GeneratePermutationsTrait.php
@@ -0,0 +1,59 @@
+   * $permutations = TestBase::generatePermutations($parameters);

I think this is the thing that needs a fix really, because that is just wrong after this change, and then we might as well update the array notation while we are at it, right?

Here we go.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Fair.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 4bd9426 to 8.4.x and eb88922 to 8.3.x. Thanks!

Backported to 8.3.x as this is test-only code and no API is changed. TestBase::generatePermutations still exists.

diff --git a/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php b/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php
index 3b90e82..1e0fd72 100644
--- a/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php
+++ b/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php
@@ -10,7 +10,6 @@
 use Drupal\entity_test\Entity\EntityTest;
 use Drupal\field\Entity\FieldConfig;
 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
-use Drupal\simpletest\TestBase;
 use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
 use Drupal\user\Entity\Role;
 use Drupal\user\RoleInterface;
diff --git a/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php
index a30acd1..8a0a0f5 100644
--- a/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php
+++ b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php
@@ -6,7 +6,6 @@
 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
 use Drupal\Core\Url;
 use Drupal\node\NodeInterface;
-use Drupal\simpletest\TestBase;
 use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
 use Drupal\Tests\UnitTestCase;
 

Removed unused uses on commit.

  • alexpott committed 4bd9426 on 8.4.x
    Issue #2881012 by Lendude, dawehner, michielnugter: Move...

  • alexpott committed eb88922 on 8.3.x
    Issue #2881012 by Lendude, dawehner, michielnugter: Move...

Status: Fixed » Closed (fixed)

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