Problem/Motivation

Part of the #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset() effort for usages of drupal_static() and drupal_static_reset() in \Drupal\Tests\image\Functional\ImageEffectsTest tests.

  • Most of the methods from ImageEffectsTest are not doing any HTTP request. The exception is ::testEffectFormValidationErrors() but its scope could be tested with Kernel rather than Functional test.
  • No method from ToolkitTest is doing HTTP requests

.

Proposed resolution

  • Convert ImageEffectsTest into a Kernel test.
  • Convert ToolkitTest into a Kernel test.
  • Deprecate \Drupal\FunctionalTests\Image\ToolkitTestBase.
  • Add a new trait \Drupal\Tests\Traits\Core\ToolkitTestTrait to provide reusable code.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A

CommentFileSizeAuthor
#70 3035518-69.interdiff.txt761 bytesclaudiu.cristea
#69 3035518-69.patch29.94 KBclaudiu.cristea
#68 3035518-68-8.9.x.patch29.94 KBclaudiu.cristea
#62 3035518-61-20percent.txt26.04 KBmondrake
#62 interdiff_52-61.txt7.83 KBmondrake
#61 interdiff_57-61.txt7.77 KBridhimaabrol24
#61 3035518-61.patch29.95 KBridhimaabrol24
#57 interdiff_52-57.txt2.75 KBDeepak Goyal
#57 3035518-57.patch30.17 KBDeepak Goyal
#54 54.txt24.85 KBmondrake
#52 interdiff_50-52.txt1.56 KBridhimaabrol24
#52 3035518-52.patch30.07 KBridhimaabrol24
#50 interdiff_45-50.txt4.53 KBridhimaabrol24
#50 3035518-50.patch30.06 KBridhimaabrol24
#45 interdiff_42-45.txt1.77 KBravi.shankar
#45 3035518-45.patch30.01 KBravi.shankar
#42 interdiff-3035518-40-42.txt959 bytesmrinalini9
#42 3035518-42.patch30 KBmrinalini9
#40 3035518-40.patch29.99 KBHardik_Patel_12
#37 3035518-37.patch29.81 KBManuel Garcia
#37 interdiff-3035518-35-37.txt3.33 KBManuel Garcia
#35 interdiff-3035518-31-35.txt877 bytespguillard
#35 3035518-35.patch29.02 KBpguillard
#31 035518-31.interdiff.txt1.46 KBpguillard
#31 3035518-31.patch29.01 KBpguillard
#29 3035518-28.patch28.92 KBclaudiu.cristea
#29 3035518-28.interdiff.txt3.61 KBclaudiu.cristea
#22 3035518-22.patch23.67 KBclaudiu.cristea
#22 3035518-22.interdiff.txt3.11 KBclaudiu.cristea
#21 3035518-21.patch27.43 KBclaudiu.cristea
#21 3035518-21.interdiff.txt3.83 KBclaudiu.cristea
#17 3035518-17.interdiff.txt8.04 KBclaudiu.cristea
#17 3035518-17.patch27.37 KBclaudiu.cristea
#14 3037031-12.interdiff.txt25.24 KBclaudiu.cristea
#14 3037031-12.patch51.69 KBclaudiu.cristea
#9 3035518-9.patch26.65 KBclaudiu.cristea
#9 3035518-9.interdiff.txt5 KBclaudiu.cristea
#5 3035518-5.interdiff.txt25.06 KBclaudiu.cristea
#5 3035518-5.patch25.77 KBclaudiu.cristea
#2 3035518-2.patch3.86 KBclaudiu.cristea
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

Status: Active » Needs review
FileSize
3.86 KB

Here, I started by converting testImageEffectsCaching() as this would satisfy #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset() .

claudiu.cristea’s picture

Title: Move move some tests from the functional ImageEffectsTest to a new kernel test class » Move some tests from the functional ImageEffectsTest to a new kernel test class

Title fixing.

Status: Needs review » Needs work

The last submitted patch, 2: 3035518-2.patch, failed testing. View results

claudiu.cristea’s picture

Title: Move some tests from the functional ImageEffectsTest to a new kernel test class » Split tests from the functional ImageEffectsTest & ToolkitTest as kernel tests
Issue summary: View changes
Status: Needs work » Needs review
FileSize
25.77 KB
25.06 KB

Expanded the scope to cover also \Drupal\FunctionalTests\Image\ToolkitTest.

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

dww’s picture

Status: Needs review » Needs work

Mostly looks good. Definitely +1 to Kernel-ifying these if possible. :)

Disclaimers:
- This is my first time ever looking at any of these particular tests.
- I didn't closely verify that all the functions that got moved around are exact replicas, nothing got lost, etc. I assume it's cool, but a closer review would be great before RTBC.

Some questions/concerns/nits:

  1. +++ b/core/modules/image/tests/modules/image_module_test/image_module_test.module
    @@ -16,12 +16,12 @@ function image_module_test_file_download($uri) {
    +  global $image_module_test_counter;
    +  // Increase the test counter, signaling that image effects were processed,
    +  // rather than being served from the cache.
    +  $image_module_test_counter++;
    

    Would love to see $image_module_test_counter declared explicitly, with a very clear phpDoc comment about it, why it's a raw global like this, @see to where it's used, etc.

  2. +++ b/core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php
    @@ -2,12 +2,19 @@
    +@trigger_error('The ' . __NAMESPACE__ . '\ToolkitTestBase is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. There is no replacement provided as toolkit operations should be tested as kernel tests. See https://www.drupal.org/node/3035573.', E_USER_DEPRECATED);
    

    "The ...\ToolKitTestBase class is deprecated...".

    Also, should we mention ToolkitTestTrait here as a partial replacement?

  3. +++ b/core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php
    @@ -2,12 +2,19 @@
    + *   no replacement provided as toolkit operations should be tested as kernel
    + *   tests.
    

    Same here: mention the new Trait?

  4. +++ b/core/tests/Drupal/Tests/Traits/Core/ToolkitTestTrait.php
    @@ -0,0 +1,87 @@
    + * Provides common methods for tests dealing with image toolkits.
    

    Seems like this should say it's got \Drupal::state() dependencies so no one tries to use it in a Unit test, right?

    In fact, seems like it depends on the image_test module being enabled, too, right? I'm only inferring that from reading this patch.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
5 KB
26.65 KB

@dww, thank you for review.

#8.1, 2, 3: Fixed.

#8.4: That is a very good point. I moved the trait under the Kernel tests namespace and stated in the docblock that is designed for kernel tests.

claudiu.cristea’s picture

Issue tags: +phpunit initiative
andypost’s picture

Status: Needs review » Needs work

Nice idea, just needs more polishing

  1. +++ b/core/modules/image/tests/modules/image_module_test/image_module_test.module
    @@ -16,12 +16,16 @@ function image_module_test_file_download($uri) {
    +  // Variable accessed from the ImageEffectsTest::testImageEffectsCaching() test
    +  // and used to signal if the image effect plugin definitions were computed or
    +  // were retrieved from the cache.
    +  // @see \Drupal\Tests\image\Kernel\ImageEffectsTest::testImageEffectsCaching()
    +  global $image_module_test_counter;
    +  // Increase the test counter, signaling that image effects were processed,
    +  // rather than being served from the cache.
    +  $image_module_test_counter++;
    
    +++ b/core/modules/image/tests/src/Kernel/ImageEffectsTest.php
    @@ -0,0 +1,201 @@
    +    // Variable incremented in image_module_test_image_effect_info_alter() every
    +    // time the image effect plugin definitions are recomputed.
    +    // @see image_module_test_image_effect_info_alter()
    +    global $image_module_test_counter;
    

    instead of new global makes sense to use state service as other tests doing

  2. +++ b/core/modules/image/tests/src/Kernel/ImageEffectsTest.php
    @@ -0,0 +1,201 @@
    +    // @todo: Need to test upscaling.
    ...
    +    // @todo should test the keyword offsets.
    ...
    +    // @todo: Need to test with 'random' => TRUE
    

    todos needs follow-up issue link

  3. +++ b/core/modules/image/tests/src/Kernel/ImageEffectsTest.php
    @@ -0,0 +1,201 @@
    +   * Test the 'image_crop' effect.
    ...
    +   * Test the 'image_scale_and_crop' effect with an anchor.
    ...
    +   * Test the 'image_desaturate' effect.
    ...
    +   * Test the image_rotate_effect() function.
    

    s/Test/Tests

  4. +++ b/core/modules/image/tests/src/Kernel/ImageEffectsTest.php
    @@ -0,0 +1,201 @@
    +    $manager = $this->container->get('plugin.manager.image.effect');
    +    $effects = $manager->getDefinitions();
    ...
    +    $manager = $this->container->get('plugin.manager.image.effect');
    +    $effect = $manager->createInstance($effect_name, ['data' => $data]);
    

    I bet that this manager could be a protected variable instantiated in setUp()

dww’s picture

#11.1 is a much better solution to #8.1, thanks! :)
+1 to the rest of #11, too.

Cheers,
-Derek

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
51.69 KB
25.24 KB

Thank you, @andypost,

True, #11.1 is a far more better solution.

#11.2: Added #3040887: Improve and add missed scenarios in ImageEffectsTest.

#11.3, 4: Fixed.

andypost’s picture

Status: Needs review » Needs work

@claudiu.cristea looks you're mixed patch & interdiff from locale module

claudiu.cristea’s picture

@andypost :)

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
27.37 KB
8.04 KB

Yeah, sorry.

claudiu.cristea’s picture

Issue tags: +functional2kernel
kim.pepper’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/image/tests/src/Functional/ImageEffectsTest.php
    @@ -3,186 +3,19 @@
    +class ImageEffectsTest extends BrowserTestBase {
    

    Can this be a kerneltest too? Or maybe https://www.previousnext.com.au/blog/drupal-8-ftw-it-test-or-it-form-act...

  2. +++ b/core/modules/image/tests/src/Kernel/ImageEffectsTest.php
    @@ -0,0 +1,219 @@
    +    $this->imageEffectPluginManager = \Drupal::service('plugin.manager.image.effect');
    

    We can get this from $this->container->get()

  3. +++ b/core/modules/image/tests/src/Kernel/ImageEffectsTest.php
    @@ -0,0 +1,219 @@
    +    $state = \Drupal::state();
    

    We can get this from $this->container->get(). Possibly in setUp() ?

  4. +++ b/core/tests/Drupal/KernelTests/Core/Image/ToolkitTest.php
    @@ -0,0 +1,119 @@
    +    /** @var \Drupal\Core\ImageToolkit\ImageToolkitInterface $toolkit */
    

    We can do assert($toolkit instanceof ImageToolkitInterface) instead.

claudiu.cristea’s picture

Status: Needs work » Needs review
Issue tags: -Testing system, -functional2kernel
FileSize
3.83 KB
27.43 KB

#11.1:

Can this be a kerneltest too? Or maybe ...

No, unfortunately. That test tests a core form. A kernel test implements FormInterface and provides its own form only for testing purposes. But in this case we test a specific form. Mocking the ImageEffectEditForm in the test would be too much as that might change in the future and it gives me the feeling the we would mock too much. This should stay as a functional test.

#11.2: Fixed.

#11.3: Fixed but kept as local variable as the other tests doesn't require the state service.

#11.4:: Fixed.

claudiu.cristea’s picture

Title: Split tests from the functional ImageEffectsTest & ToolkitTest as kernel tests » Convert ImageEffectsTest & ToolkitTest into Kernel tests
Issue summary: View changes
Issue tags: +@deprecated
FileSize
3.11 KB
23.67 KB

OK, finally addressed also #20.1.

This means that functional ImageEffectsTest is completely gone and I had to fix also the issue title, summary and the change notice.

kim.pepper’s picture

Status: Needs review » Reviewed & tested by the community

Nice! LGTM

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: 3035518-22.patch, failed testing. View results

Lendude’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated fail

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php
    @@ -2,12 +2,21 @@
    -use Drupal\Component\Render\FormattableMarkup;
    +@trigger_error('The ' . __NAMESPACE__ . '\ToolkitTestBase class is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. There is no replacement provided as functional test base class because toolkit operations should be tested as kernel tests. \Drupal\KernelTests\Core\Image\ToolkitTestTrait trait has been added to provide a similar functionality for toolkit kernel tests. See https://www.drupal.org/node/3035573.', E_USER_DEPRECATED);
    

    We shouldn't be removing the use statement here - that'll break this test base class.

  2. +++ b/core/tests/Drupal/KernelTests/Core/Image/ToolkitTest.php
    --- /dev/null
    +++ b/core/tests/Drupal/KernelTests/Core/Image/ToolkitTestTrait.php
    

    This is not the correct namespace for test traits. They can go in core/tests/Drupal/Tests/Traits/Core now - so let's add an Image directory in there and move this.

  3. +++ b/core/tests/Drupal/KernelTests/Core/Image/ToolkitTestTrait.php
    @@ -0,0 +1,89 @@
    +    \Drupal::state()->delete('image_test.results');
    ...
    +    return $this->container->get('state')->get('image_test.results', []);
    ...
    +    $image_factory = $this->container->get('image.factory');
    

    As this trait can be used by both kernel and functional tests this is probably better done with \Drupal at this point. It makes less assumptions about the properties of the class it is being used from.

claudiu.cristea’s picture

Issue tags: -phpunit initiative +Novice
claudiu.cristea’s picture

Status: Needs work » Needs review
Issue tags: -Novice

Fixed remarks from #26.

claudiu.cristea’s picture

FileSize
3.61 KB
28.92 KB

Forgot the patch.

klausi’s picture

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

Looks good to me, just some minor stuff we should fix:

  1. +++ /dev/null
    @@ -1,89 +0,0 @@
    -    $this->assertIdentical('foo_derived', $blur->getPluginId(), "'Blur' operation overwritten by derivative.");
    -    $this->assertIdentical('bar', $invert->getPluginId(), '"Invert" operation inherited from base plugin.');
    

    This is a bit sad that we lose the nice messages. We can still pass them in the new phpunit methods, right? Can we just keep them?

  2. +++ b/core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php
    @@ -2,12 +2,22 @@
    + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. There is
    

    Format is "@deprecated in drupal:8.8.0 and is removed from drupal:9.0.0.", see #3024461: Adopt consistent deprecation format for core and contrib deprecation messages. Same for the trigger_error(), should use the new format.

I'm a bit concerned that we are throwing away all the messages with the converted assertions. Yes, sometimes they are a bit redundant, but in other cases they give very useful insight what the assertion does/expects. Any reason why you removed them?

pguillard’s picture

Status: Needs work » Needs review
FileSize
29.01 KB
1.46 KB

I fixed the 2 minor stuff suggested at #30..

claudiu.cristea’s picture

This is a bit sad that we lose the nice messages. We can still pass them in the new phpunit methods, right? Can we just keep them?

@klausi

There's a problem with keeping them. In Simpletest the assertion messages were described the SUCCESS of the assertion. Contrary, in PHPUnit, the message should describe the FAILURE. So, if we want to keep them we have to invert the logic in the message. Probably a good workaround, already used, would be to remove them from assertion but place them as a comment just above.

Manuel Garcia’s picture

Status: Needs review » Reviewed & tested by the community

This was RTBCed before, reviewed by @alexpott on #26, after which the concerns were addressed. Regarding the messages, I think the response on #32 is valid and is what we've been doing on other issues. So I think it's safe to go back to RTBC.

catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ /dev/null
@@ -1,223 +0,0 @@
-    $calls = $this->imageTestGetAllCalls();
-    $this->assertEqual($calls['scale'][0][0], 10, 'Width was passed correctly');
-    $this->assertEqual($calls['scale'][0][1], 10, 'Height was based off aspect ratio and passed correctly');
-  }

I think we should do claudiu's suggestion and convert these messages to comments. The assertions are not very self documenting by themselves given it relies on array index.

pguillard’s picture

Status: Needs work » Needs review
FileSize
29.02 KB
877 bytes

I applied claudiu's suggestion, was my mistake by the way.

catch’s picture

  1. +++ /dev/null
    @@ -1,223 +0,0 @@
    -
    -    // Check the parameters.
    -    $calls = $this->imageTestGetAllCalls();
    -    $this->assertEqual($calls['scale_and_crop'][0][0], 7.5, 'X was computed and passed correctly');
    -    $this->assertEqual($calls['scale_and_crop'][0][1], 0, 'Y was computed and passed correctly');
    -    $this->assertEqual($calls['scale_and_crop'][0][2], 5, 'Width was computed and passed correctly');
    -    $this->assertEqual($calls['scale_and_crop'][0][3], 10, 'Height was computed and passed correctly');
    -  }
    

    I think we need to convert most/all of the messages to comments though for example the messages above:

  2. +++ b/core/modules/image/tests/src/Kernel/ImageEffectsTest.php
    @@ -0,0 +1,245 @@
    +
    +    // Check the parameters.
    +    $calls = $this->imageTestGetAllCalls();
    +    $this->assertEquals(0, $calls['crop'][0][0]);
    +    $this->assertEquals(1, $calls['crop'][0][1]);
    +    $this->assertEquals(3, $calls['crop'][0][2]);
    +    $this->assertEquals(4, $calls['crop'][0][3]);
    +  }
    

    Are lost here. Really anything where we're asserting against array indexes should definitely be retained.

Manuel Garcia’s picture

Appologies I was too hasty to set back to RTBC. Restoring all messages here as comments.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Hardik_Patel_12’s picture

Status: Needs review » Needs work

The last submitted patch, 40: 3035518-40.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mrinalini9’s picture

Status: Needs work » Needs review
FileSize
30 KB
959 bytes

Fixing test case failure issue in #40, please review.

klausi’s picture

Status: Needs review » Needs work

Drupal 9 was released, so we need to update the deprecation messages.

Why do we move the assertion messages to comments? We can leave them because assertEquals() has a message option as third parameter? I think having assertion messages is much better than comments because then you see them also in test output.

Hardik_Patel_12’s picture

Issue tags: -Bug Smash Initiative
ravi.shankar’s picture

Here I have updated the depreciation messages.

klausi’s picture

Thanks!

Can we also use the assertion messages instead of comments as I suggested in #43?

dww’s picture

Re: #43 / #46: See #3131946: [META] [policy] Remove PHPUnit assertion messages when possible, and standardize remaining messages -- not fully decided yet, but core is moving away from custom assertion messages when they add nothing over the default assertions from PHPUnit itself.

Hardik_Patel_12’s picture

Status: Needs work » Needs review

Moving back to Needs Review.

mondrake’s picture

It's not finalised yet, but at least two core committers are positive about #3154762: [policy, no patch] All new Drupal 10 code should use appropriate type hints wherever possible, so I would suggest to start that. Also, see #3138078: [D9.3 beta - w/c Nov 8, 2021] Add a 'void' return typehint to custom assert* methods.

  1. +++ b/core/modules/image/tests/src/Kernel/ImageEffectsTest.php
    @@ -0,0 +1,265 @@
    +  protected function assertImageEffect($effect_name, array $data) {
    

    should have a : void return typehint, and $effect_name a string typehint.

  2. +++ b/core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php
    @@ -2,12 +2,22 @@
    +@trigger_error('The ' . __NAMESPACE__ . '\ToolkitTestBase class is deprecated in Drupal 9.0.0 and will be removed before Drupal 10.0.0. There is no replacement provided as functional test base class because toolkit operations should be tested as kernel tests. \Drupal\KernelTests\Core\Image\ToolkitTestTrait trait has been added to provide a similar functionality for toolkit kernel tests. See https://www.drupal.org/node/3035573.', E_USER_DEPRECATED);
    ...
    + * @deprecated in drupal:9.0.0 and is removed from drupal:10.0.0. There is
    

    It's for deprecation in 9.1.0 now, and we miss a deprecation test.

  3. +++ b/core/tests/Drupal/KernelTests/Core/Image/ToolkitTest.php
    @@ -0,0 +1,123 @@
    +    $this->assertSame(TRUE, $calls['apply'][0][1]['p2']);
    

    $this->assertTrue

  4. +++ b/core/tests/Drupal/KernelTests/Core/Image/ToolkitTest.php
    @@ -0,0 +1,123 @@
    +    assert($toolkit instanceof ImageToolkitInterface);
    

    $this->assertInstanceOf

  5. +++ b/core/tests/Drupal/Tests/Traits/Core/Image/ToolkitTestTrait.php
    @@ -0,0 +1,89 @@
    +  protected function imageTestReset() {
    

    should have a : void return typehint.

  6. +++ b/core/tests/Drupal/Tests/Traits/Core/Image/ToolkitTestTrait.php
    @@ -0,0 +1,89 @@
    +  public function assertToolkitOperationsCalled(array $expected) {
    

    should have a : void return typehint.

  7. +++ b/core/tests/Drupal/Tests/Traits/Core/Image/ToolkitTestTrait.php
    @@ -0,0 +1,89 @@
    +  protected function imageTestGetAllCalls() {
    

    should have an : array return typehint.

  8. +++ b/core/tests/Drupal/Tests/Traits/Core/Image/ToolkitTestTrait.php
    @@ -0,0 +1,89 @@
    +  protected function getImage() {
    

    should have an : ImageInterface return typehint.

ridhimaabrol24’s picture

Status: Needs work » Needs review
FileSize
30.06 KB
4.53 KB

implementing suggestions from #49

mondrake’s picture

Status: Needs review » Needs work
  1. +++ b/core/tests/Drupal/KernelTests/Core/Image/ToolkitTest.php
    @@ -0,0 +1,123 @@
    +    $this->assertTrue(TRUE, $calls['apply'][0][1]['p2']);
    

    should be $this->assertTrue($calls['apply'][0][1]['p2']);

  2. +++ b/core/tests/Drupal/Tests/Traits/Core/Image/ToolkitTestTrait.php
    @@ -0,0 +1,89 @@
    +  protected function getImage(): \Drupal\Core\Image\ImageInterface {
    

    should be protected function getImage(): ImageInterface { and a use statement added at the top of the file with the fully qualified class name

ridhimaabrol24’s picture

Status: Needs work » Needs review
FileSize
30.07 KB
1.56 KB

Worked on #51

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Thanks

mondrake’s picture

FileSize
24.85 KB

A diff made using git diff --cached 9.1.x -M20% so to visually see what was changed from the functional version of the tests.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/image/tests/src/Kernel/ImageEffectsTest.php
    @@ -0,0 +1,265 @@
    +    $this->assertImageEffect('image_rotate', [
    +      'degrees' => 90,
    +      'bgcolor' => '#fff',
    +    ]);
    +    $this->assertToolkitOperationsCalled(['rotate']);
    ...
    +  /**
    +   * Asserts the effect processing of an image effect plugin.
    +   *
    +   * @param string $effect_name
    +   *   The name of the image effect to test.
    +   * @param array $data
    +   *   The data to be passed to the image effect.
    +   */
    +  protected function assertImageEffect(string $effect_name, array $data): void {
    

    The assertImageEffect method is always followed by an assertToolkitOperationsCalled(). I think think the signature for assertImageEffect should be:

    protected function assertImageEffect(array $expected_operations, string $effect_name, array $data): void {
    

    and it should call assertToolkitOperationsCalled() because without that call we're not really asserting the effect of processing an image effect plugin.

    And also does this method belong on the trait? I think it might be useful for modules that provide an image effect.

  2. +++ b/core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php
    @@ -2,12 +2,22 @@
    +@trigger_error('The ' . __NAMESPACE__ . '\ToolkitTestBase class is deprecated in Drupal 9.0.0 and will be removed before Drupal 10.0.0. There is no replacement provided as functional test base class because toolkit operations should be tested as kernel tests. \Drupal\KernelTests\Core\Image\ToolkitTestTrait trait has been added to provide a similar functionality for toolkit kernel tests. See https://www.drupal.org/node/3035573.', E_USER_DEPRECATED);
    

    This is not the correct format and doesn't have the correct versions.

  3. +++ b/core/tests/Drupal/KernelTests/Core/Image/ToolkitTest.php
    @@ -0,0 +1,123 @@
    +  /**
    +   * {@inheitdoc}
    +   */
    

    {inheritdoc}

  4. +++ b/core/tests/Drupal/Tests/Traits/Core/Image/ToolkitTestTrait.php
    @@ -0,0 +1,90 @@
    +  /**
    +   * Sets up an image with the custom toolkit.
    +   *
    +   * @return \Drupal\Core\Image\ImageInterface
    +   *   The image object.
    +   */
    +  protected function getImage(): ImageInterface {
    

    <3 the return typehinting. Nice to see on new stuff.

Deepak Goyal’s picture

Assigned: Unassigned » Deepak Goyal
Deepak Goyal’s picture

Assigned: Deepak Goyal » Unassigned
Status: Needs work » Needs review
FileSize
30.17 KB
2.75 KB

Hi @alexpott
Made changes please review.

alexpott’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/image/tests/src/Kernel/ImageEffectsTest.php
    @@ -0,0 +1,267 @@
    +  protected function assertImageEffect(array $expected_operations, string $effect_name, array $data): void {
    

    We need to change all the calls to this method to pass in the expected operations and we need to move the $this->assertToolkitOperationsCalled($expected_operations) inside this method.

    Also I suggested moving this to the trait as it looks helpful.

  2. +++ b/core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php
    @@ -2,12 +2,22 @@
    +@trigger_error('The ' . __NAMESPACE__ . '\ToolkitTestBase class is deprecated in Drupal 9.0.0 and will be removed before Drupal 10.0.0. There is no replacement provided as functional test base class because toolkit operations should be tested as kernel tests. \Drupal\KernelTests\Core\Image\ToolkitTestTrait trait has been added to provide a similar functionality for toolkit kernel tests. See https://www.drupal.org/node/3035573.', E_USER_DEPRECATION);
    

    E_USER_DEPRECATED was correct. The message should be:
    'The ' . __NAMESPACE__ . '\ToolkitTestBase class is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. . There is no replacement provided as functional test base class because toolkit operations should be tested as kernel tests. \Drupal\KernelTests\Core\Image\ToolkitTestTrait trait has been added to provide a similar functionality for toolkit kernel tests. See https://www.drupal.org/node/3035573.

  3. +++ b/core/modules/image/tests/src/Kernel/ImageEffectsTest.php
    @@ -250,12 +250,14 @@
    +   *   Collection of effects.
    

    This is not that see the documentation for assertToolkitOperationsCalled()

  4. +++ b/core/tests/Drupal/KernelTests/Core/Image/ToolkitTest.php
    @@ -17,7 +17,7 @@
    -   * {@inheitdoc}
    +   * {@inheritdoc}.
    

    No fullstop.

alexpott’s picture

@Deepak Goyal also when making changes to a test it is good practice to run the test before uploading a patch - if you'd done that you'll see that #57 is incomplete... you'll get lots of

TypeError: Argument 1 passed to Drupal\Tests\image\Kernel\ImageEffectsTest::assertImageEffect() must be of the type array, string given, called in core/modules/image/tests/src/Kernel/ImageEffectsTest.php on line 189
mondrake’s picture

Do we need a test for the deprecation of ToolkitTestBase?

ridhimaabrol24’s picture

Status: Needs work » Needs review
FileSize
29.95 KB
7.77 KB

Hi
Made changes as suggested in #55 and #58.
Please review.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
7.83 KB
26.04 KB

#55 looks addressed - #57 was way out of track, so here attaching an interdiff #52 -> #61 and again a patch with -M20% to see changes between functional and kernel.

#61 is RTBC for me.

EDIT - re. #60 I looked back at the 8.9.x branch and I could not find explicit tests for entirely deprecated base test classes.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed bf94a9e and pushed to 9.1.x. Thanks!

  • alexpott committed bf94a9e on 9.1.x
    Issue #3035518 by claudiu.cristea, ridhimaabrol24, pguillard, Deepak...

Status: Fixed » Closed (fixed)

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

claudiu.cristea’s picture

Very bad that this change was not backported to Drupal 8.9. We have a site transitioning from 8.9 to 9.2 and which runs a test extending ToolkitTestBase. So, in CI it runs on both 8.9 and 9.2. Now I need a lot of hocus-pocus to make it work.

claudiu.cristea’s picture

Version: 9.1.x-dev » 8.9.x-dev
Status: Closed (fixed) » Patch (to be ported)
Issue tags: +needs backport to 8.9.x

Let's try because of #66

claudiu.cristea’s picture

8.9.x reroll

claudiu.cristea’s picture

claudiu.cristea’s picture

FileSize
761 bytes

The interdiff

alexpott’s picture

@claudiu.cristea this is very unlikely to land in Drupal 8.9.x - it would have to be a completely different patch that didn't remove the old code and kept testing it.

I think you're probably better of patching 8.9.x for you own needs or doing some hocus-pocus.

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
xjm’s picture

Version: 9.3.x-dev » 9.1.x-dev
Status: Patch (to be ported) » Fixed

Drupal 8 is very end-of-life, so restoring status against 9.1.x.

Hardik_Patel_12’s picture

Status: Fixed » Closed (fixed)

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

quietone’s picture

Publish CR