FileSystemRequirementsTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Drupal\KernelTests\Core\File;
  3. use Drupal\Component\FileSystem\FileSystem;
  4. use Drupal\KernelTests\KernelTestBase;
  5. /**
  6. * @group File
  7. * @group legacy
  8. */
  9. class FileSystemRequirementsTest extends KernelTestBase {
  10. /**
  11. * Modules to enable.
  12. *
  13. * @var array
  14. */
  15. public static $modules = ['system'];
  16. /**
  17. * {@inheritdoc}
  18. */
  19. protected $strictConfigSchema = FALSE;
  20. /**
  21. * {@inheritdoc}
  22. */
  23. protected function setUp() {
  24. parent::setUp();
  25. $this->setInstallProfile('standard');
  26. }
  27. /**
  28. * Tests requirements warnings.
  29. *
  30. * @expectedDeprecation The 'system.file' config 'path.temporary' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Set 'file_temp_path' in settings.php instead. See https://www.drupal.org/node/3039255
  31. */
  32. public function testFileSystemRequirements() {
  33. $this->config('system.file')
  34. ->set('path.temporary', $this->randomMachineName())
  35. ->save(TRUE);
  36. $requirements = $this->checkSystemRequirements();
  37. $this->assertEquals('Deprecated configuration', (string) $requirements['temp_directory']['value']);
  38. $this->assertEquals('You are using deprecated configuration for the temporary files path.', (string) $requirements['temp_directory']['description'][0]['#markup']);
  39. $this->assertStringStartsWith('Remove the configuration and add the following', (string) $requirements['temp_directory']['description'][1]['#markup']);
  40. $this->config('system.file')
  41. ->set('path.temporary', FileSystem::getOsTemporaryDirectory())
  42. ->save(TRUE);
  43. $requirements = $this->checkSystemRequirements();
  44. $this->assertEquals('Deprecated configuration', (string) $requirements['temp_directory']['value']);
  45. $this->assertEquals('You are using deprecated configuration for the temporary files path.', (string) $requirements['temp_directory']['description'][0]['#markup']);
  46. $this->assertEquals('Your temporary directory configuration matches the OS default and can be safely removed.', (string) $requirements['temp_directory']['description'][1]['#markup']);
  47. }
  48. /**
  49. * Tests if settings are set, there are not warnings.
  50. */
  51. public function testSettingsExist() {
  52. $this->setSetting('file_temp_path', $this->randomMachineName());
  53. $requirements = $this->checkSystemRequirements();
  54. $this->assertArrayNotHasKey('temp_directory', $requirements);
  55. }
  56. /**
  57. * Checks system runtime requirements.
  58. *
  59. * @return array
  60. * An array of system requirements.
  61. */
  62. protected function checkSystemRequirements() {
  63. module_load_install('system');
  64. return system_requirements('runtime');
  65. }
  66. }