function RequirementsTest::testUploadRequirements
Same name in other branches
- 11.x core/modules/file/tests/src/Kernel/RequirementsTest.php \Drupal\Tests\file\Kernel\RequirementsTest::testUploadRequirements()
Tests the file upload requirements.
File
-
core/
modules/ file/ tests/ src/ Kernel/ RequirementsTest.php, line 28
Class
- RequirementsTest
- Tests the file requirements.
Namespace
Drupal\Tests\file\KernelCode
public function testUploadRequirements() : void {
if (\extension_loaded('uploadprogress')) {
$this->markTestSkipped('We are testing only when the uploadprogress extension is not loaded.');
}
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler */
$moduleHandler = $this->container
->get('module_handler');
$moduleHandler->loadInclude('file', 'install');
// Test unspecified server software.
$this->setServerSoftware(NULL);
$requirements = \file_requirements('runtime');
$this->assertNotEmpty($requirements);
$this->assertEquals('Upload progress', (string) $requirements['file_progress']['title']);
$this->assertEquals('Not enabled', (string) $requirements['file_progress']['value']);
$this->assertEquals('Your server is not capable of displaying file upload progress. File upload progress requires an Apache server running PHP with mod_php or Nginx with PHP-FPM.', (string) $requirements['file_progress']['description']);
// Test Apache + mod_php.
$this->setServerSoftware('Apache mod_php');
$requirements = \file_requirements('runtime');
$this->assertNotEmpty($requirements);
$this->assertEquals('Not enabled', (string) $requirements['file_progress']['value']);
$this->assertEquals('Your server is capable of displaying file upload progress, but does not have the required libraries. It is recommended to install the <a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress library</a>.', (string) $requirements['file_progress']['description']);
// Test Apache + mod_fastcgi.
$this->setServerSoftware('Apache mod_fastcgi');
$requirements = \file_requirements('runtime');
$this->assertNotEmpty($requirements);
$this->assertEquals('Not enabled', (string) $requirements['file_progress']['value']);
$this->assertEquals('Your server is not capable of displaying file upload progress. File upload progress requires PHP be run with mod_php or PHP-FPM and not as FastCGI.', (string) $requirements['file_progress']['description']);
// Test Nginx.
$this->setServerSoftware('Nginx');
$requirements = \file_requirements('runtime');
$this->assertNotEmpty($requirements);
$this->assertEquals('Not enabled', (string) $requirements['file_progress']['value']);
$this->assertEquals('Your server is capable of displaying file upload progress, but does not have the required libraries. It is recommended to install the <a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress library</a>.', (string) $requirements['file_progress']['description']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.