Drupal 11 compatibility fixes for google_tag

Created on 16 June 2024, 10 months ago
Updated 9 August 2024, 8 months ago

Drupal 11 compatibility fixes for google_tag

📌 Task
Status

Fixed

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @naveenvalecha
  • Status changed to Needs review 10 months ago
  • 🇮🇳India sarwan_verma

    Hi@naveenvalecha,
    I have fixed this issue "Drupal 11 compatibility fixes for google_tag" and also attached patch ,
    please review and verify.

  • First commit to issue fork.
  • 🇺🇸United States jrglasgow Idaho

    I added the patch in #3 to the fork as well as removing reference to ,a href=" https://www.drupal.org/node/3418480 ">KernelTestBase::checkRequirements() in tests which is deprecated in 10.3 and removed in 11.

  • Pipeline finished with Failed
    9 months ago
    Total: 230s
    #224981
  • First commit to issue fork.
  • Pipeline finished with Failed
    9 months ago
    Total: 195s
    #227743
  • Pipeline finished with Failed
    9 months ago
    Total: 196s
    #227786
  • Pipeline finished with Failed
    9 months ago
    Total: 334s
    #227830
  • Pipeline finished with Failed
    9 months ago
    Total: 207s
    #231092
  • Pipeline finished with Failed
    9 months ago
    Total: 408s
    #231811
  • Pipeline finished with Failed
    9 months ago
    Total: 204s
    #231842
  • 🇮🇳India chandu7929 Pune

    All test has been fixed, I can see only one test failure on D11 which is due null value of entity(commerce_product_variation) being returned by $event->getEntity()->label() in CartEventSubscriber class, show below:

    /**
       * Displays an add to cart message.
       *
       * @param \Drupal\commerce_cart\Event\CartEntityAddEvent $event
       *   The add to cart event.
       */
      public function displayAddToCartMessage(CartEntityAddEvent $event) {
        $order = $event->getCart();
        $order_type_storage = $this->entityTypeManager->getStorage('commerce_order_type');
        /** @var \Drupal\commerce_order\Entity\OrderTypeInterface $order_type */
        $order_type = $order_type_storage->load($order->bundle());
        if ($order_type->getThirdPartySetting('commerce_cart', 'enable_cart_message', TRUE)) {
          $this->messenger->addMessage($this->t('@entity added to <a href=":url">your cart</a>.', [
            '@entity' => $event->getEntity()->label(),
            ':url' => Url::fromRoute('commerce_cart.page')->toString(),
          ]));
        }
      }

    This should be fixed at commerce end : https://www.drupal.org/project/commerce/issues/3462426 📌 Drupal 11 compatibility fixes for commerce Needs work

    Running phpunit tests for 'Google Tag' module.
    
    PHPUnit 10.5.28 by Sebastian Bergmann and contributors.
    
    Runtime:       PHP 8.3.7
    Configuration: /Users/developer/Sites/drupal11/web/core/phpunit.xml.dist
    
    DDEDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD                      44 / 44 (100%)
    
    Time: 00:53.465, Memory: 18.00 MB
    
    There was 1 error:
    
    1) Drupal\Tests\google_tag\Kernel\Events\CommerceCartEventsTest::testEvents
    TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /Users/developer/Sites/drupal11/web/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 256
    
    /Users/developer/Sites/drupal11/web/core/lib/Drupal/Component/Utility/Html.php:431
    /Users/developer/Sites/drupal11/web/core/lib/Drupal/Component/Render/FormattableMarkup.php:256
    /Users/developer/Sites/drupal11/web/core/lib/Drupal/Component/Render/FormattableMarkup.php:205
    /Users/developer/Sites/drupal11/web/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php:195
    /Users/developer/Sites/drupal11/web/core/lib/Drupal/Component/Utility/ToStringTrait.php:15
    /Users/developer/Sites/drupal11/web/core/lib/Drupal/Core/Messenger/Messenger.php:54
    /Users/developer/Sites/drupal11/web/modules/contrib/commerce/modules/cart/src/EventSubscriber/CartEventSubscriber.php:70
    /Users/developer/Sites/drupal11/vendor/symfony/event-dispatcher/EventDispatcher.php:246
    /Users/developer/Sites/drupal11/vendor/symfony/event-dispatcher/EventDispatcher.php:206
    /Users/developer/Sites/drupal11/vendor/symfony/event-dispatcher/EventDispatcher.php:56
    /Users/developer/Sites/drupal11/web/modules/contrib/commerce/modules/cart/src/CartManager.php:126
    /Users/developer/Sites/drupal11/web/modules/contrib/commerce/modules/cart/src/CartManager.php:87
    /Users/developer/Sites/drupal11/web/modules/contrib/google_tag/tests/src/Kernel/Events/CommerceCartEventsTest.php:48
    

    Note: I have ran the test on D11 by including require/require-dev modules using vcs path pulling a specific D11 compatible MR.

  • 🇮🇳India chandu7929 Pune

    Hence requesting review.

  • Status changed to Needs work 9 months ago
  • 🇮🇳India rajeshreeputra Pune

    Provided minor feedback on MR, please take a look.

  • Status changed to Needs review 9 months ago
  • Status changed to RTBC 9 months ago
  • 🇮🇳India rajeshreeputra Pune

    Changes looks good, verified with Drupal 11 and works fine. Hence moving ahead in RTBC.

  • Status changed to Needs work 8 months ago
  • 🇮🇳India vishalkhode

    The Nightwatch CI is failing, Hence, moving back to Needs Work.

  • Pipeline finished with Failed
    8 months ago
    Total: 51s
    #233837
  • Pipeline finished with Failed
    8 months ago
    Total: 257s
    #233879
  • Pipeline finished with Failed
    8 months ago
    Total: 985s
    #233909
  • 🇮🇳India chandu7929 Pune

    Now, CI runs agains D11 as well and we have only one failure which I have already mention in my comment #8, https://git.drupalcode.org/issue/google_tag-3454903/-/jobs/2227157

    The failure I was suspecting from commerce but its not, I'll see if its related to commerce_wishlist or google_tag itself.

  • First commit to issue fork.
  • 🇮🇳India vishalkhode

    @japerry I also figured out the cause of failing PHPUnit tests on Drupal 11. Even though we are assigning title while creating an entity of commerce_product_variant, it's always returning NULL. Because the preSave method of ProductVariation entity invoke generateTitle method and it returns NULL if no product if attached to product variant.
    Following patch fixes the error. Please include it.

    diff --git a/tests/src/Kernel/Events/CommerceCartEventsTest.php b/tests/src/Kernel/Events/CommerceCartEventsTest.php
    index 3662634..316169e 100644
    --- a/tests/src/Kernel/Events/CommerceCartEventsTest.php
    +++ b/tests/src/Kernel/Events/CommerceCartEventsTest.php
    @@ -5,6 +5,7 @@ declare(strict_types=1);
     namespace Drupal\Tests\google_tag\Kernel\Events;
     
     use Drupal\commerce_price\Price;
    +use Drupal\commerce_product\Entity\Product;
     use Drupal\commerce_product\Entity\ProductVariation;
     use Drupal\google_tag\Entity\TagContainer;
     use Drupal\Tests\commerce_cart\Kernel\CartKernelTestBase;
    @@ -35,13 +36,20 @@ final class CommerceCartEventsTest extends CartKernelTestBase {
           ],
         ])->save();
     
    +    $product = Product::create([
    +      'type' => 'default',
    +      'title' => $this->randomString(),
    +    ]);
    +    $product->save();
    +
         $variation = ProductVariation::create([
           'type' => 'default',
           'sku' => strtolower($this->randomMachineName()),
    -      'title' => $this->randomString(),
    +      'product_id' => $product->id(),
           'price' => new Price('12.00', 'USD'),
           'status' => 1,
         ]);
    +
         $variation->save();
     
         $cart = $this->cartProvider->createCart('default', $this->store);
    
  • Pipeline finished with Skipped
    8 months ago
    #234185
  • Status changed to Fixed 8 months ago
  • 🇺🇸United States japerry KVUO

    Thanks @vishalkhode! However, there are still remaining tests that are failing due to other modules not being D11 compatible. If there are things we need to fix after those modules get D11 support, we can re-visit it then.

    for now I think we're good to commit this. Fixed!

  • 🇮🇳India chandu7929 Pune

    Thanks @vishalkhode! However, there are still remaining tests that are failing due to other modules not being D11 compatible. If there are things we need to fix after those modules get D11 support, we can re-visit it then.

    This is because we have used lenient to fetch dependent modules which sometime pull incompatible modules version(for example: see my comment on scheduler 📌 Automated Drupal 11 compatibility fixes for scheduler Active ), those failing tests are already fixed in dev version of commerce module.

  • 🇺🇸United States japerry KVUO

    Correct, I'm not too worried about those tests failing for now -- but when commerce has a release they should automatically work here. If not, we can follow up with fixes in the tests or code if needed.

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

Production build 0.71.5 2024