From fa81641914d0a5bd02020ff249a7071565aa10d2 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Fri, 9 Oct 2020 11:30:59 +0100
Subject: [PATCH] Issue #3175112 by alexpott, longwave: hold_test module
 creates files in incorrect place leading to possible random errors

(cherry picked from commit 5e27a9f44c8d2e763930bcd74065cb7e7f7b67ee)
---
 .../tests/modules/hold_test/hold_test.module  |  6 ++++--
 .../modules/hold_test/hold_test.services.yml  |  1 +
 .../EventSubscriber/HoldTestSubscriber.php    | 19 ++++++++++++++++++-
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/core/modules/system/tests/modules/hold_test/hold_test.module b/core/modules/system/tests/modules/hold_test/hold_test.module
index 867eacf90612..e08141edf97e 100644
--- a/core/modules/system/tests/modules/hold_test/hold_test.module
+++ b/core/modules/system/tests/modules/hold_test/hold_test.module
@@ -12,7 +12,8 @@
  *   TRUE - enable hold, FALSE - disable hold.
  */
 function hold_test_request($status) {
-  file_put_contents(\Drupal::root() . '/sites/default/files/simpletest/hold_test_request.txt', $status);
+  $site_path = \Drupal::getContainer()->getParameter('site.path');
+  file_put_contents($site_path . '/hold_test_request.txt', $status);
 }
 
 /**
@@ -22,5 +23,6 @@ function hold_test_request($status) {
  *   TRUE - enable hold, FALSE - disable hold.
  */
 function hold_test_response($status) {
-  file_put_contents(\Drupal::root() . '/sites/default/files/simpletest/hold_test_response.txt', $status);
+  $site_path = \Drupal::getContainer()->getParameter('site.path');
+  file_put_contents($site_path . '/hold_test_response.txt', $status);
 }
diff --git a/core/modules/system/tests/modules/hold_test/hold_test.services.yml b/core/modules/system/tests/modules/hold_test/hold_test.services.yml
index 88e7babdff32..309f21929118 100644
--- a/core/modules/system/tests/modules/hold_test/hold_test.services.yml
+++ b/core/modules/system/tests/modules/hold_test/hold_test.services.yml
@@ -1,5 +1,6 @@
 services:
   hold_test.response:
     class: Drupal\hold_test\EventSubscriber\HoldTestSubscriber
+    arguments: ['%site.path%']
     tags:
       - { name: event_subscriber }
diff --git a/core/modules/system/tests/modules/hold_test/src/EventSubscriber/HoldTestSubscriber.php b/core/modules/system/tests/modules/hold_test/src/EventSubscriber/HoldTestSubscriber.php
index 332f4c00b9a8..a9160a46146a 100644
--- a/core/modules/system/tests/modules/hold_test/src/EventSubscriber/HoldTestSubscriber.php
+++ b/core/modules/system/tests/modules/hold_test/src/EventSubscriber/HoldTestSubscriber.php
@@ -13,6 +13,23 @@ class HoldTestSubscriber implements EventSubscriberInterface {
   const HOLD_REQUEST = 'request';
   const HOLD_RESPONSE = 'response';
 
+  /**
+   * The site path.
+   *
+   * @var string
+   */
+  protected $sitePath;
+
+  /**
+   * HoldTestSubscriber constructor.
+   *
+   * @param string $site_path
+   *   The site path.
+   */
+  public function __construct(string $site_path) {
+    $this->sitePath = $site_path;
+  }
+
   /**
    * Request hold.
    */
@@ -34,7 +51,7 @@ public function onRespond() {
    *   Type of hold.
    */
   protected function hold($type) {
-    $path = \Drupal::root() . "/sites/default/files/simpletest/hold_test_$type.txt";
+    $path = "{$this->sitePath}/hold_test_$type.txt";
     do {
       $status = (bool) file_get_contents($path);
     } while ($status && (NULL === usleep(100000)));
-- 
GitLab