diff --git a/core/modules/file/tests/src/Functional/DownloadTest.php b/core/modules/file/tests/src/Functional/DownloadTest.php index ca5c4634f0..10f99d7dbe 100644 --- a/core/modules/file/tests/src/Functional/DownloadTest.php +++ b/core/modules/file/tests/src/Functional/DownloadTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\file\Functional; +use Drupal\Core\Site\Settings; + /** * Tests for download/file transfer functions. * @@ -70,7 +72,7 @@ protected function doPrivateFileTransferTest() { $this->assertResponse(200, 'Correctly allowed access to a file when file_test provides headers.'); // Test that the file transferred correctly. - $this->assertEqual($contents, $this->content, 'Contents of the file are correct.'); + $this->assertSession()->responseContains($contents); // Deny access to all downloads via a -1 header. file_test_set_return('download', -1); @@ -173,4 +175,20 @@ private function checkUrl($scheme, $directory, $filename, $expected_url) { $file->delete(); } + /** + * Changes in memory settings. + * + * @param $name + * The name of the setting to return. + * @param $value + * The value of the setting. + * + * @see \Drupal\Core\Site\Settings::get() + */ + protected function settingsSet($name, $value) { + $settings = Settings::getAll(); + $settings[$name] = $value; + new Settings($settings); + } + } diff --git a/core/modules/file/tests/src/Functional/FileFieldRSSContentTest.php b/core/modules/file/tests/src/Functional/FileFieldRSSContentTest.php index 5ebbe0b121..26d14dbfb4 100644 --- a/core/modules/file/tests/src/Functional/FileFieldRSSContentTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldRSSContentTest.php @@ -60,12 +60,12 @@ public function testFileFieldRSSContent() { $this->drupalGet('rss.xml'); $uploaded_filename = str_replace('public://', '', $node_file->getFileUri()); $selector = sprintf( - 'enclosure[url="%s"][length="%s"][type="%s"]', + 'enclosure[@url="%s"][@length="%s"][@type="%s"]', file_create_url("public://$uploaded_filename", ['absolute' => TRUE]), $node_file->getSize(), $node_file->getMimeType() ); - $this->assertTrue(!empty($this->cssSelect($selector)), 'File field RSS enclosure is displayed when viewing the RSS feed.'); + $this->assertNotNull($this->getSession()->getDriver()->find('xpath', $selector), 'File field RSS enclosure is displayed when viewing the RSS feed.'); } } diff --git a/core/modules/file/tests/src/Functional/FilePrivateTest.php b/core/modules/file/tests/src/Functional/FilePrivateTest.php index bee95560e5..1e335eaf43 100644 --- a/core/modules/file/tests/src/Functional/FilePrivateTest.php +++ b/core/modules/file/tests/src/Functional/FilePrivateTest.php @@ -142,9 +142,7 @@ public function testPrivateFile() { $this->drupalGet($file_url); $this->assertResponse(200, 'Confirmed that the anonymous uploader has access to the temporary file.'); // Close the prior connection and remove the session cookie. - $this->curlClose(); - $this->curlCookies = []; - $this->cookies = []; + $this->getSession()->reset(); $this->drupalGet($file_url); $this->assertResponse(403, 'Confirmed that another anonymous user cannot access the temporary file.'); @@ -172,9 +170,7 @@ public function testPrivateFile() { $this->drupalGet($file_url); $this->assertResponse(200, 'Confirmed that the anonymous uploader has access to the file whose references were removed.'); // Close the prior connection and remove the session cookie. - $this->curlClose(); - $this->curlCookies = []; - $this->cookies = []; + $this->getSession()->reset(); $this->drupalGet($file_url); $this->assertResponse(403, 'Confirmed that another anonymous user cannot access the file whose references were removed.'); @@ -195,9 +191,7 @@ public function testPrivateFile() { $this->drupalGet($file_url); $this->assertResponse(200, 'Confirmed that the anonymous uploader has access to the permanent file that is referenced by a published node.'); // Close the prior connection and remove the session cookie. - $this->curlClose(); - $this->curlCookies = []; - $this->cookies = []; + $this->getSession()->reset(); $this->drupalGet($file_url); $this->assertResponse(200, 'Confirmed that another anonymous user also has access to the permanent file that is referenced by a published node.'); @@ -222,9 +216,7 @@ public function testPrivateFile() { $this->drupalGet($file_url); $this->assertResponse(403, 'Confirmed that the anonymous uploader cannot access the permanent file when it is referenced by an unpublished node.'); // Close the prior connection and remove the session cookie. - $this->curlClose(); - $this->curlCookies = []; - $this->cookies = []; + $this->getSession()->reset(); $this->drupalGet($file_url); $this->assertResponse(403, 'Confirmed that another anonymous user cannot access the permanent file when it is referenced by an unpublished node.'); } diff --git a/core/modules/file/src/Tests/SaveUploadFormTest.php b/core/modules/file/tests/src/Functional/SaveUploadFormTest.php similarity index 95% rename from core/modules/file/src/Tests/SaveUploadFormTest.php rename to core/modules/file/tests/src/Functional/SaveUploadFormTest.php index 6d51198a7f..6ac441770e 100644 --- a/core/modules/file/src/Tests/SaveUploadFormTest.php +++ b/core/modules/file/tests/src/Functional/SaveUploadFormTest.php @@ -1,8 +1,10 @@ set('file_test.disable_error_collection', TRUE); - $this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit')); - $this->assertResponse(200, 'Received a 200 response for posted test file.'); - $this->assertRaw(t('File upload error. Could not move uploaded file.'), 'Found the failure message.'); - $this->assertRaw(t('Epic upload FAIL!'), 'Found the failure message.'); + $this->drupalPostFormHack('file-test/save_upload_from_form_test', $edit, t('Submit')); + $this->assertContains(t('File upload error. Could not move uploaded file.')->render(), (string) $this->postResponse->getBody(), 'Found the failure message.'); + $this->assertContains(t('Epic upload FAIL!')->render(), $this->postResponse->getBody(), 'Found the failure message.'); // Uploading failed. Now check the log. $this->drupalGet('admin/reports/dblog'); @@ -433,12 +440,11 @@ public function testCombinedErrorMessages() { 'extensions' => 'jpeg', ]; - $this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit')); - $this->assertResponse(200, 'Received a 200 response for posted test file.'); - $this->assertRaw(t('Epic upload FAIL!'), 'Found the failure message.'); + $this->drupalPostFormHack('file-test/save_upload_from_form_test', $edit, t('Submit')); + $this->assertContains(t('Epic upload FAIL!')->render(), (string) $this->postResponse->getBody(), 'Found the failure message.'); // Search for combined error message followed by a formatted list of messages. - $this->assertRaw(t('One or more files could not be uploaded.') . '