Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / tests / Drupal / Tests / Listeners / DeprecationListenerTrait.php
1 <?php
2
3 namespace Drupal\Tests\Listeners;
4
5 use Drupal\Tests\Traits\ExpectDeprecationTrait;
6 use PHPUnit\Framework\TestCase;
7
8 /**
9  * Removes deprecations that we are yet to fix.
10  *
11  * @internal
12  *   This class will be removed once all the deprecation notices have been
13  *   fixed.
14  */
15 trait DeprecationListenerTrait {
16   use ExpectDeprecationTrait;
17
18   protected function deprecationStartTest($test) {
19     if ($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase) {
20       if ($this->willBeIsolated($test)) {
21         putenv('DRUPAL_EXPECTED_DEPRECATIONS_SERIALIZE=' . tempnam(sys_get_temp_dir(), 'exdep'));
22       }
23     }
24   }
25
26   /**
27    * Reacts to the end of a test.
28    *
29    * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
30    *   The test object that has ended its test run.
31    * @param float $time
32    *   The time the test took.
33    */
34   protected function deprecationEndTest($test, $time) {
35     /** @var \PHPUnit\Framework\Test $test */
36     if ($file = getenv('DRUPAL_EXPECTED_DEPRECATIONS_SERIALIZE')) {
37       putenv('DRUPAL_EXPECTED_DEPRECATIONS_SERIALIZE');
38       $expected_deprecations = file_get_contents($file);
39       if ($expected_deprecations) {
40         $test->expectedDeprecations(unserialize($expected_deprecations));
41       }
42     }
43     if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
44       $util_test_class = class_exists('PHPUnit_Util_Test') ? 'PHPUnit_Util_Test' : 'PHPUnit\Util\Test';
45       $method = $test->getName(FALSE);
46       if (strpos($method, 'testLegacy') === 0
47         || strpos($method, 'provideLegacy') === 0
48         || strpos($method, 'getLegacy') === 0
49         || strpos(get_class($test), '\Legacy')
50         || in_array('legacy', $util_test_class::getGroups(get_class($test), $method), TRUE)) {
51         // This is a legacy test don't skip deprecations.
52         return;
53       }
54
55       // Need to edit the file of deprecations to remove any skipped
56       // deprecations.
57       $deprecations = file_get_contents($file);
58       $deprecations = $deprecations ? unserialize($deprecations) : [];
59       $resave = FALSE;
60       foreach ($deprecations as $key => $deprecation) {
61         if (in_array($deprecation[1], static::getSkippedDeprecations())) {
62           unset($deprecations[$key]);
63           $resave = TRUE;
64         }
65       }
66       if ($resave) {
67         file_put_contents($file, serialize($deprecations));
68       }
69     }
70   }
71
72   /**
73    * Determines if a test is isolated.
74    *
75    * @param \PHPUnit_Framework_TestCase|\PHPUnit\Framework\TestCase $test
76    *   The test to check.
77    *
78    * @return bool
79    *   TRUE if the isolated, FALSE if not.
80    */
81   private function willBeIsolated($test) {
82     if ($test->isInIsolation()) {
83       return FALSE;
84     }
85
86     $r = new \ReflectionProperty($test, 'runTestInSeparateProcess');
87     $r->setAccessible(TRUE);
88
89     return $r->getValue($test);
90   }
91
92   /**
93    * A list of deprecations to ignore whilst fixes are put in place.
94    *
95    * Do not add any new deprecations to this list. All deprecation errors will
96    * eventually be removed from this list.
97    *
98    * @return string[]
99    *   A list of deprecations to ignore.
100    *
101    * @internal
102    *
103    * @todo Fix all these deprecations and remove them from this list.
104    *   https://www.drupal.org/project/drupal/issues/2959269
105    *
106    * @see https://www.drupal.org/node/2811561
107    */
108   public static function getSkippedDeprecations() {
109     return [
110       'The Twig_Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.',
111       'Install profile will be a mandatory parameter in Drupal 9.0.',
112       'The revision_user revision metadata key is not set.',
113       'The revision_created revision metadata key is not set.',
114       'The revision_log_message revision metadata key is not set.',
115       'MigrateCckField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.',
116       'MigrateCckFieldPluginManager is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateFieldPluginManager instead.',
117       'MigrateCckFieldPluginManagerInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateFieldPluginManagerInterface instead.',
118       'The "plugin.manager.migrate.cckfield" service is deprecated. You should use the \'plugin.manager.migrate.field\' service instead. See https://www.drupal.org/node/2751897',
119       'Drupal\system\Tests\Update\DbUpdatesTrait is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use \Drupal\FunctionalTests\Update\DbUpdatesTrait instead. See https://www.drupal.org/node/2896640.',
120       'Using "null" for the value of node "count" of "Drupal\Core\Template\TwigNodeTrans" is deprecated since version 1.25 and will be removed in 2.0.',
121       'Using "null" for the value of node "options" of "Drupal\Core\Template\TwigNodeTrans" is deprecated since version 1.25 and will be removed in 2.0.',
122       'Using "null" for the value of node "plural" of "Drupal\Core\Template\TwigNodeTrans" is deprecated since version 1.25 and will be removed in 2.0.',
123       'Providing settings under \'handler_settings\' is deprecated and will be removed before 9.0.0. Move the settings in the root of the configuration array. See https://www.drupal.org/node/2870971.',
124       'AssertLegacyTrait::getAllOptions() is scheduled for removal in Drupal 9.0.0. Use $element->findAll(\'xpath\', \'option\') instead.',
125       'assertNoPattern() is deprecated and scheduled for removal in Drupal 9.0.0. Use $this->assertSession()->responseNotMatches($pattern) instead. See https://www.drupal.org/node/2864262.',
126       'Using UTF-8 route patterns without setting the "utf8" option is deprecated since Symfony 3.2 and will throw a LogicException in 4.0. Turn on the "utf8" route option for pattern "/system-test/Ȅchȏ/meφΩ/{text}".',
127       'Using UTF-8 route patterns without setting the "utf8" option is deprecated since Symfony 3.2 and will throw a LogicException in 4.0. Turn on the "utf8" route option for pattern "/somewhere/{item}/over/the/קainbow".',
128       'Using UTF-8 route patterns without setting the "utf8" option is deprecated since Symfony 3.2 and will throw a LogicException in 4.0. Turn on the "utf8" route option for pattern "/place/meφω".',
129       'Using UTF-8 route patterns without setting the "utf8" option is deprecated since Symfony 3.2 and will throw a LogicException in 4.0. Turn on the "utf8" route option for pattern "/PLACE/meφω".',
130       'The Drupal\editor\Plugin\EditorBase::settingsFormValidate method is deprecated since version 8.3.x and will be removed in 9.0.0.',
131       'The Drupal\migrate\Plugin\migrate\process\Migration is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use Drupal\migrate\Plugin\migrate\process\MigrationLookup',
132       'Drupal\system\Plugin\views\field\BulkForm is deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Use \Drupal\views\Plugin\views\field\BulkForm instead. See https://www.drupal.org/node/2916716.',
133       'The numeric plugin for watchdog.wid field is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Must use standard plugin instead. See https://www.drupal.org/node/2876378.',
134       'Using an instance of "Twig_Filter_Function" for filter "testfilter" is deprecated since version 1.21. Use Twig_SimpleFilter instead.',
135       'The Twig_Function class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead.',
136       'Using an instance of "Twig_Function_Function" for function "testfunc" is deprecated since version 1.21. Use Twig_SimpleFunction instead.',
137       'The Twig_Function class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead.',
138       'The Twig_Filter_Function class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFilter instead.',
139       'The Twig_Filter class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFilter instead.',
140       'The Twig_Function_Function class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead.',
141       'Referencing the "twig_extension_test.test_extension" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.',
142       'Passing in arguments the legacy way is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Provide the right parameter names in the method, similar to controllers. See https://www.drupal.org/node/2894819',
143       'DateField is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\datetime\Plugin\migrate\field\DateField instead.',
144       'The Drupal\editor\Plugin\EditorBase::settingsFormSubmit method is deprecated since version 8.3.x and will be removed in 9.0.0.',
145       'CommentVariable is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d6\NodeType instead.',
146       'CommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d7\NodeType instead.',
147       'CommentVariablePerCommentType is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.x. Use \Drupal\node\Plugin\migrate\source\d6\NodeType instead.',
148       'The Drupal\migrate_drupal\Plugin\migrate\source\d6\i18nVariable is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use Drupal\migrate_drupal\Plugin\migrate\source\d6\VariableTranslation',
149       'Implicit cacheability metadata bubbling (onto the global render context) in normalizers is deprecated since Drupal 8.5.0 and will be removed in Drupal 9.0.0. Use the "cacheability" serialization context instead, for explicit cacheability metadata bubbling. See https://www.drupal.org/node/2918937',
150       'Adding or retrieving messages prior to the container being initialized was deprecated in Drupal 8.5.0 and this functionality will be removed before Drupal 9.0.0. Please report this usage at https://www.drupal.org/node/2928994.',
151       'The "serializer.normalizer.file_entity.hal" normalizer service is deprecated: it is obsolete, it only remains available for backwards compatibility.',
152       'The Symfony\Component\ClassLoader\ApcClassLoader class is deprecated since Symfony 3.3 and will be removed in 4.0. Use `composer install --apcu-autoloader` instead.',
153       // The following deprecation is not triggered by DrupalCI testing since it
154       // is a Windows only deprecation. Remove when core no longer uses
155       // WinCacheClassLoader in \Drupal\Core\DrupalKernel::initializeSettings().
156       'The Symfony\Component\ClassLoader\WinCacheClassLoader class is deprecated since Symfony 3.3 and will be removed in 4.0. Use `composer install --apcu-autoloader` instead.',
157       'The Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler class is deprecated since Symfony 3.4 and will be removed in 4.0. Implement `SessionUpdateTimestampHandlerInterface` or extend `AbstractSessionHandler` instead.',
158       'The "session_handler.write_check" service relies on the deprecated "Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler" class. It should either be deprecated or its implementation upgraded.',
159       'Not setting the strict option of the Choice constraint to true is deprecated since Symfony 3.4 and will throw an exception in 4.0.',
160     ];
161   }
162
163 }