getProtectedFiles() as $file => $response_code) { $this->assertFileAccess($file, $response_code); } // Test that adding "/1" to a .php URL does not make it accessible. $this->drupalGet('core/lib/Drupal.php/1'); $this->assertResponse(403, "Access to core/lib/Drupal.php/1 is denied."); // Test that it is possible to have path aliases containing .php. $type = $this->drupalCreateContentType(); // Create an node aliased to test.php. $node = $this->drupalCreateNode([ 'title' => 'This is a node', 'type' => $type->id(), 'path' => '/test.php' ]); $node->save(); $this->drupalGet('test.php'); $this->assertResponse(200); $this->assertText('This is a node'); // Update node's alias to test.php/test. $node->path = '/test.php/test'; $node->save(); $this->drupalGet('test.php/test'); $this->assertResponse(200); $this->assertText('This is a node'); } /** * Asserts that a file exists and requesting it returns a specific response. * * @param string $path * Path to file. Without leading slash. * @param int $response_code * The expected response code. For example: 200, 403 or 404. * * @return bool * TRUE if the assertion succeeded, FALSE otherwise. */ protected function assertFileAccess($path, $response_code) { $result = $this->assertTrue(file_exists(\Drupal::root() . '/' . $path), "The file $path exists."); $this->drupalGet($path); $result = $result && $this->assertResponse($response_code, "Response code to $path is $response_code."); return $result; } /** * Tests that SVGZ files are served with Content-Encoding: gzip. */ public function testSvgzContentEncoding() { $this->drupalGet('core/modules/system/tests/logo.svgz'); $this->assertResponse(200); $header = $this->drupalGetHeader('Content-Encoding'); $this->assertEqual($header, 'gzip'); } }