ApiMediaControllersPostTest fails intermittently due to date-dependent itok in expected image URL
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3587922. -->
Reported by: [justafish](https://www.drupal.org/user/161058)
Related to !1035 !1032
>>>
<p><code>Drupal\Tests\canvas\Kernel\Controller\ApiMediaControllersPostTest::testPost</code> fails intermittently in CI with a mismatch on the itok query parameter in the src URL returned by the media upload API. The itok is computed with a date-based upload folder. </p>
<p>First seen here: <a href="https://git.drupalcode.org/project/canvas/-/jobs/9609943">https://git.drupalcode.org/project/canvas/-/jobs/9609943</a><br>
and reproduced locally:</p>
<pre>❯ ddev exec -d /var/www/html/modules/contrib/canvas composer run phpunit -- tests/src/Kernel/Controller/ApiMediaControllersPostTest.php<br>> ./tests/scripts/phpunit.sh 'tests/src/Kernel/Controller/ApiMediaControllersPostTest.php'<br>PHPUnit 11.5.55 by Sebastian Bergmann and contributors.<br><br>Runtime: PHP 8.4.20<br>Configuration: /var/www/html/modules/contrib/canvas/phpunit.xml.dist<br><br>FF... 5 / 5 (100%)<br><br>Time: 00:28.944, Memory: 118.23 MB<br><br>There were 2 failures:<br><br>1) Drupal\Tests\canvas\Kernel\Controller\ApiMediaControllersPostTest::testPost with data set "Create a new image" ('image', ['gracie-big.jpg', 'Gracie Dog', 'Gracie Dog in its most happy state'], [1, ['::SITE_DIR_BASE_URL::/files/:...xv7Qhl', 'Gracie Dog in its most happy state', 3000, 2595]])<br>Failed asserting that two arrays are identical.<br>--- Expected<br>+++ Actual<br>@@ @@<br> 'id' => 1,<br> 'uuid' => '197d0907-6527-4941-a3e9-9e03163f5f54',<br> 'inputs_resolved' => Array &1 [<br>- 'src' => '::SITE_DIR_BASE_URL::/files/::MEDIA_FOLDER::/gracie-big.jpg?alternateWidths=::SITE_DIR_BASE_URL::/files/styles/canvas_parametrized_width--%7Bwidth%7D/public/::MEDIA_FOLDER::/gracie-big.jpg.avif%3Fitok%3Dh5xv7Qhl',<br>+ 'src' => '::SITE_DIR_BASE_URL::/files/::MEDIA_FOLDER::/gracie-big.jpg?alternateWidths=::SITE_DIR_BASE_URL::/files/styles/canvas_parametrized_width--%7Bwidth%7D/public/::MEDIA_FOLDER::/gracie-big.jpg.avif%3Fitok%3DYbWUs9wV',<br> 'alt' => 'Gracie Dog in its most happy state',<br> 'width' => 3000,<br> 'height' => 2595,<br> ],<br> ]<br><br>/var/www/html/modules/contrib/canvas/tests/src/Kernel/Controller/ApiMediaControllersPostTest.php:132<br><br>2) Drupal\Tests\canvas\Kernel\Controller\ApiMediaControllersPostTest::testPost with data set "Create a new image without alt nor title" ('image', ['gracie-big.jpg'], [1, ['::SITE_DIR_BASE_URL::/files/:...xv7Qhl', '', 3000, 2595]])<br>Failed asserting that two arrays are identical.<br>--- Expected<br>+++ Actual<br>@@ @@<br> 'id' => 1,<br> 'uuid' => 'dcdc9b19-1be8-4de9-b689-325d4a2b816b',<br> 'inputs_resolved' => Array &1 [<br>- 'src' => '::SITE_DIR_BASE_URL::/files/::MEDIA_FOLDER::/gracie-big.jpg?alternateWidths=::SITE_DIR_BASE_URL::/files/styles/canvas_parametrized_width--%7Bwidth%7D/public/::MEDIA_FOLDER::/gracie-big.jpg.avif%3Fitok%3Dh5xv7Qhl',<br>+ 'src' => '::SITE_DIR_BASE_URL::/files/::MEDIA_FOLDER::/gracie-big.jpg?alternateWidths=::SITE_DIR_BASE_URL::/files/styles/canvas_parametrized_width--%7Bwidth%7D/public/::MEDIA_FOLDER::/gracie-big.jpg.avif%3Fitok%3DYbWUs9wV',<br> 'alt' => '',<br> 'width' => 3000,<br> 'height' => 2595,<br> ],<br> ]<br><br>/var/www/html/modules/contrib/canvas/tests/src/Kernel/Controller/ApiMediaControllersPostTest.php:132<br><br>FAILURES!<br>Tests: 5, Assertions: 150, Failures: 2.<br>Script ./tests/scripts/phpunit.sh handling the phpunit event returned with error code 1<br>Failed to execute command `composer run phpunit -- tests/src/Kernel/Controller/ApiMediaControllersPostTest.php`: exit status 1</pre>
issue