Problem/Motivation

I was working on #2937166: Improve count() for ContentEntity source plugin and just wanted to reduce the repetitive code.
This is just changing a test to make it easier to read and maintain by converting it to use a dataprovider.

Steps to reproduce

Proposed resolution

Use a dataprovider for the 4 tests of the constructor

Remaining tasks

Review
Commit

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3200534

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

quietone created an issue. See original summary.

quietone’s picture

Status: Active » Needs review

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

StatusFileSize
new11.46 KB
new3.55 KB

I have followed the iinstructions for Rebasing a merge request and am not able to push changes. So I give up.

Here is a patch.

quietone’s picture

Issue summary: View changes
Issue tags: +Drupal South

Tagging for Drupal South. Good for someone who knows or whats to learn about using a dataprovider for a test. The test is there, this is just converting it to use a dataprovider.

quietone’s picture

Issue tags: -Drupal South +DrupalSouth

Use the right tag!

kristen pol’s picture

Status: Needs review » Needs work

Thanks for the patch. Here's some feedback (mostly nitpicks):

  1. +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
    @@ -88,155 +88,47 @@ class ContentEntityTest extends KernelTestBase {
    +        'The entity type (node_type) is not supported. The "content_entity" source plugin only supports content entities.',
    

    Nitpick: Add quotes around node_type?

  2. +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
    @@ -88,155 +88,47 @@ class ContentEntityTest extends KernelTestBase {
    +        \InvalidArgumentException::class,
    

    Nitpick: Include class to avoid backslash to be consistent with InvalidPluginDefinitionException.

  3. +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
    @@ -88,155 +88,47 @@ class ContentEntityTest extends KernelTestBase {
    +        'A bundle was provided but the entity type (user) is not bundleable.',
    

    Nitpick: Add quotes around user?

  4. +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
    @@ -88,155 +88,47 @@ class ContentEntityTest extends KernelTestBase {
    +        \InvalidArgumentException::class,
    

    Same as above.

  5. +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
    @@ -88,155 +88,47 @@ class ContentEntityTest extends KernelTestBase {
    +        'The provided bundle (foo) is not valid for the (node) entity type.',
    

    Nitpick: Add quotes around foo and node?

  6. +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
    @@ -527,4 +424,102 @@ protected function migrationDefinition($plugin_id, array $configuration = []) {
    +   * Setup for the tests.
    

    Nitpick: Since the function is called prepare and there is no longer a setUp function, consider rewording.

  7. +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
    @@ -527,4 +424,102 @@ protected function migrationDefinition($plugin_id, array $configuration = []) {
    +  protected function prepare() {
    

    Note: Looking through other code, didn't find any other protected function called prepare except in HtmlRenderer but the other prepare functions were not used for tests. The only other test-related prepare function I saw was in MultilingualReviewPageTestBase which is public. But, since this is for internal processing, protected seems okay.

  8. +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
    @@ -527,4 +424,102 @@ protected function migrationDefinition($plugin_id, array $configuration = []) {
    +    );
    +    // Create a term reference field on user.
    

    Nitpick: Add an empty line above comment.

  9. +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
    @@ -527,4 +424,102 @@ protected function migrationDefinition($plugin_id, array $configuration = []) {
    +    // Create some data.
    

    Nitpick: Could use a better comment.

  10. +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
    @@ -527,4 +424,102 @@ protected function migrationDefinition($plugin_id, array $configuration = []) {
    +    $term = Term::create([
    

    Nitpick: Consider adding a comment.

  11. +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
    @@ -527,4 +424,102 @@ protected function migrationDefinition($plugin_id, array $configuration = []) {
    +    $this->anon = User::create([
    

    Unclear where $this->anon is being used.

  12. +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
    @@ -527,4 +424,102 @@ protected function migrationDefinition($plugin_id, array $configuration = []) {
    +    $node = Node::create([
    

    Nitpick: Consider adding a comment.

  13. +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
    @@ -527,4 +424,102 @@ protected function migrationDefinition($plugin_id, array $configuration = []) {
    +    $this->sourcePluginManager = $this->container->get('plugin.manager.migrate.source');
    

    Nitpick: Consider adding a comment.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new1.4 KB
new11.62 KB

@Kristen Pol, thank you for the review.

I think that these are out of scope, beyond what is needed to rearrange the test to use a data provider.
1, 3, 5: These would require changes to ContentEntity.
2, 4: \InvalidArgumentException is the class.
7. Haha, it seems I like to use 'prepare'
11. True. This was added in #3187318: ContentEntity source plugin should exclude user with uid "0" and I think that if we want to add a comment it should be as a follow up to that.

What I have modified are:
6. Changed the comment.
8, 9, 10, 12, 13 I think these are out of scope but have added them because adding comments is usually a good idea and I don't think this conflicts with any other issue. There is one larger comment and the beginning of the block adding this 'extra' data.

Done
9. This is also out of scope

longwave’s picture

Would it be cleaner to break the constructor test out into its own test class, and move prepare() back to setUp()? The constructor test is testing different things to the other test methods.

quietone’s picture

StatusFileSize
new6.13 KB

@longwave, I thought about that but as we see I didn't. Since you suggested I have done so.

This patch moves the constructor tests to a new file. To stay within scope it does not make the changes to the comments suggested in #8. That can be done in another issue.

There is no interdiff because this is a new approach.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

This makes the conversion simple and straightforward now.

quietone’s picture

The changes to the comments suggested in #8 are now in #3229734: Improve test and add comments to ContentEntityTest

alexpott’s picture

Version: 9.3.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed c14450bc96 to 9.3.x and d6ead31b37 to 9.2.x. Thanks!

Backported to 9.2.x because this is about tests only.

  • alexpott committed c14450b on 9.3.x
    Issue #3200534 by quietone, longwave, Kristen Pol: Use dataprovider for...

  • alexpott committed d6ead31 on 9.2.x
    Issue #3200534 by quietone, longwave, Kristen Pol: Use dataprovider for...

Status: Fixed » Closed (fixed)

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