CommentFileSizeAuthor
#60 interdiff-2870448-53-60.txt2.73 KByogeshmpawar
#60 2870448-60.patch27.05 KByogeshmpawar
#53 interdiff-52-53.txt6.4 KBAnonymous (not verified)
#53 2870448-53.patch27.09 KBAnonymous (not verified)
#52 interdiff-51-52.txt5.35 KBAnonymous (not verified)
#52 2870448-52.patch22.18 KBAnonymous (not verified)
#51 interdiff-50-51.txt2.29 KBAnonymous (not verified)
#51 2870448-51.patch24.45 KBAnonymous (not verified)
#50 interdiff-48-50.txt784 bytesAnonymous (not verified)
#50 2870448-50.patch36 KBAnonymous (not verified)
#48 interdiff-45-48.txt8.3 KBAnonymous (not verified)
#48 2870448-48.patch36.76 KBAnonymous (not verified)
#45 interdiff-42-45.txt1.67 KBAnonymous (not verified)
#45 2870448-45.patch42.77 KBAnonymous (not verified)
#42 interdiff-41-42.txt46.03 KBAnonymous (not verified)
#42 2870448-42.patch43.2 KBAnonymous (not verified)
#41 reroll_39-2870448-41.patch60.24 KBAnonymous (not verified)
#39 interdiff-33-39.txt1.38 KBAnonymous (not verified)
#39 2870448-39.patch52.56 KBAnonymous (not verified)
#39 interdiff-33-39-test-only.txt751 bytesAnonymous (not verified)
#39 2870448-39-test-only.patch52.24 KBAnonymous (not verified)
#33 interdiff-31-33.txt773 bytesAnonymous (not verified)
#33 2870448-33.patch52.09 KBAnonymous (not verified)
#31 2870448-31.patch51.64 KBAnonymous (not verified)
#31 interdiff-29-31.txt2.53 KBAnonymous (not verified)
#29 interdiff-27-29.txt1.16 KBAnonymous (not verified)
#29 2870448-29.patch52.75 KBAnonymous (not verified)
#27 interdiff-24-27.txt2.14 KBAnonymous (not verified)
#27 2870448-27.patch53.16 KBAnonymous (not verified)
#24 2870448-24.patch52.83 KBAnonymous (not verified)
#7 2870448-7.patch16.12 KBnaveenvalecha
#8 2870448-9.patch29.14 KBnaveenvalecha
#8 interdiff-2870448-7-9.txt15.93 KBnaveenvalecha
#9 2870448-11.patch28.39 KBnaveenvalecha
#9 interdiff-2870448-9-11.txt7.75 KBnaveenvalecha
#15 2870448-15.patch28.39 KBnaveenvalecha
#15 interdiff-2870448-9-15.txt7.75 KBnaveenvalecha
#18 2870448-18.patch45.08 KBAnonymous (not verified)
#18 interdiff-15-18.txt17.83 KBAnonymous (not verified)
#20 2870448-20.patch48.35 KBAnonymous (not verified)
#20 interdiff-18-20.txt6.46 KBAnonymous (not verified)
#22 2870448-22.patch48.38 KBAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

michielnugter created an issue. See original summary.

michielnugter’s picture

Status: Active » Postponed
michielnugter’s picture

dawehner’s picture

We could convert part of the tests (aka. the tests which don't depend on views) already.

michielnugter’s picture

It's true that we can do a partial convert but getting views in first would enable this issue to be converted in 1 go. To prevent a lot of spin-offs I postponed all issues that require base classes from other issues. A lot of them will be solved with getting views in though.

The way I see it the conversion can already be started but has to wait on the Views issue before it can be finished. Is that workable?

michielnugter’s picture

Issue summary: View changes
Status: Postponed » Active

Discussed on IRC and we decided to place all tests that have a non-converted base class out of scope. Updated the IS to reflect that.

naveenvalecha’s picture

Status: Active » Needs review
FileSize
16.12 KB

Here's the start. This patch should fail.
FileFieldTestBase class has functions(assertFileExists & assertFileNotExists) which PHPUnit_Framework_TestCase class also have static methods. We need to rename these methods from FileFieldTestBase class as we couldn't rely on the PHPUnit_Framework_TestCase assert methods directly. Because PHPUnit_Framework_TestCase assertFileExists expects $filename to be string. However in FileFieldTestBase its a file object.

//Naveen

naveenvalecha’s picture

Here's the new patch which renamed the FileFieldTestBase methods
assertFileExists to assertFileExistsOnDisk
assertFileNotExists to assertFileNotExistsOnDisk

Next item:
- FileManagedFileElementTest should be split into javascript and BTB test
- FileFieldWidgetTest should be split into Javascript and BTB test
Remove these tests from this patch.

//Naveen

naveenvalecha’s picture

Here we go with more fixes and removed the FileManagedFileElementTest & FileFieldWidgetTest from this converstion patch.

//Naveen

The last submitted patch, 7: 2870448-7.patch, failed testing. View results

naveenvalecha’s picture

Issue tags: +phpunit initiative

The last submitted patch, 8: 2870448-9.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 9: 2870448-11.patch, failed testing. View results

naveenvalecha’s picture

Component: phpunit » file.module
naveenvalecha’s picture

Status: Needs work » Needs review
FileSize
28.39 KB
7.75 KB

Few more fixes.

Status: Needs review » Needs work

The last submitted patch, 15: 2870448-15.patch, failed testing. View results

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anonymous’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
45.08 KB
17.83 KB

Status: Needs review » Needs work

The last submitted patch, 18: 2870448-18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
48.35 KB
6.46 KB

Status: Needs review » Needs work

The last submitted patch, 20: 2870448-20.patch, failed testing. View results

Anonymous’s picture

Status: Needs work » Needs review
FileSize
48.38 KB
Anonymous’s picture

Patch with #2917885: Add drupalPostFormWithInvalidOptions() to BrowserTestBase and #2919352: Move methods from FileFieldTestBase to Trait.


Revert #8, because we looks like we not need to do it here. FileFieldTestBase override assertFileExists, and can works with objects.
Anonymous’s picture

Title: Convert web tests to browser tests for file module » [PP-2] Convert web tests to browser tests for file module

Added mark [PP-2], but not changed status, because maybe not everything is ready.

Status: Needs review » Needs work

The last submitted patch, 24: 2870448-24.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch, 27: 2870448-27.patch, failed testing. View results

Anonymous’s picture

Status: Needs work » Needs review
FileSize
52.75 KB
1.16 KB
dawehner’s picture

Nice progress!

  1. +++ b/core/modules/file/tests/src/Functional/DownloadTest.php
    @@ -70,17 +73,28 @@ protected function doPrivateFileTransferTest() {
    -    $this->assertEqual($contents, $this->content, 'Contents of the file are correct.');
    +    $this->assertSession()->responseContains($contents);
    

    Why do we switch from equals to contains?

  2. +++ b/core/modules/file/tests/src/Functional/DownloadTest.php
    @@ -172,4 +186,20 @@ private function checkUrl($scheme, $directory, $filename, $expected_url) {
    +  protected function settingsSet($name, $value) {
    

    This new method is used for \Drupal\file\Tests\DownloadTest::testFileCreateUrl which could be actually a kernel test, couldn't it? What about filing a follow up?

  3. +++ b/core/modules/file/tests/src/Functional/FilePrivateTest.php
    @@ -15,6 +15,7 @@
     class FilePrivateTest extends FileFieldTestBase {
     
    +
    

    🙃 Let's skip this additional new line :)

  4. +++ b/core/modules/file/tests/src/Functional/SaveUploadFormTest.php
    @@ -13,6 +15,12 @@
     class SaveUploadFormTest extends FileManagedTestBase {
    ...
    +  use DrupalPostFormWithInvalidOptionsTrait;
    

    I'm curious ... why is this $edit an invalid value here?

        $edit = [
          'file_subdir' => $test_directory,
          'files[file_test_upload]' => drupal_realpath($this->image->getFileUri())
        ];

    doesn't look too invalid for me, sorry for the dump question. This was done in #18 without much of an explanation.

Anonymous’s picture

Great points as always!

30.1: done.
30.2: follow up or fix it here - both variants ok for me.
30.3: done.
30.4: done, I really overdid it with a replacement)

Status: Needs review » Needs work

The last submitted patch, 31: 2870448-31.patch, failed testing. View results

Anonymous’s picture

Status: Needs work » Needs review
FileSize
52.09 KB
773 bytes

opps.

dawehner’s picture

30.2: follow up or fix it here - both variants ok for me.

Do you mind creating a follow up?

Anonymous’s picture

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

Anonymous’s picture

Title: [PP-2] Convert web tests to browser tests for file module » [PP-1] Convert web tests to browser tests for file module
Status: Reviewed & tested by the community » Postponed

@dawehner, thank you so much too!

Current patch contains two additional chunks from next issues:

  1. #2919352: Move methods from FileFieldTestBase to Trait
  2. #2917885: Add drupalPostFormWithInvalidOptions() to BrowserTestBase

I'm going to close first chunk as duplicate, because it's just a transfer of methods from the Class to the Trait. It's much better to do it right here to get a good test coverage.

But the second chunk is a trait with a new method, which most likely will need to be added separately. Therefore, I will add an additional test coverage there. And while to postpone this issue like [PP-1]. Correctly?

Anonymous’s picture

I took the Drupal\file\Tests\FileFieldDisplayTest::testNodeDisplay() to extend the test coverage of drupalPostFormWithInvalidOptions(), and came across an interesting thing.

// Uncheck the display checkboxes and go to the preview.
$edit[$field_name . '[0][display]'] = FALSE;
$edit[$field_name . '[1][display]'] = FALSE;
$this->drupalPostForm("node/$nid/edit", $edit, t('Preview'));
$this->clickLink(t('Back to content editing'));
$this->assertRaw($field_name . '[0][display]', 'First file appears as expected.');
$this->assertRaw($field_name . '[1][display]', 'Second file appears as expected.');

Why we cann't use BTB::drupalPostForm() here?
Because $field_name . '[1][display]' not found.

But why?
Because we add new file in 'Preview' request directly.

Okay. But then we go back and check both:

$this->clickLink(t('Back to content editing'));
$this->assertRaw($field_name . '[0][display]', 'First file appears as expected.');
$this->assertRaw($field_name . '[1][display]', 'Second file appears as expected.');

What do we want to get with these asserts?
By message, that both files 'appears as expected'.

But only the first file does exist. No second file.
$this->assertRaw($field_name . '[1][display]', 'Second file appears as expected.');
This assert is passed only because the upload form already has a hidden display field with that name. It's enough to check exist of $field_name. '[1] [description]' or directly the second file itself, for confirm it.

And what suggestions?
For check the work without saving form, we can to do 'Upload' request, and only then to do 'Preview' request. Like last part of testAddValuesForFieldWithExistValues() in #2917885-24: Add drupalPostFormWithInvalidOptions() to BrowserTestBase.

Anonymous’s picture

Here's what I proposed to do in #38. Now the test works correctly with drupalPostForm() too.

The last submitted patch, 39: 2870448-39-test-only.patch, failed testing. View results

Anonymous’s picture

Updated with latest version DrupalPostFormWithInvalidOptionsTrait from #2917885: Add drupalPostFormWithInvalidOptions() to BrowserTestBase.

The changes are not very readable, so here's a quick review:

  1. Do not move methods form FileFieldTestBase to Trait (we can do it in #2809503: Convert AJAX part of \Drupal\file\Tests\FileFieldWidgetTest to JavascriptTestBase or reopen #2919352: Move methods from FileFieldTestBase to Trait after fix current issue).
  2. Bit update phpdoc and variable name in uploadNodeFiles
    +   * @param bool $is_invalid
    +   *   FALSE (by default) using drupalPostForm()
    +   *   TRUE using drupalPostFormWithInvalidOptions().
    ...
    -   public function uploadNodeFiles(array $files, $field_name, $nid_or_type, $new_revision = TRUE, array $extras = [], $is_hack = FALSE) 
    +  public function uploadNodeFiles(array $files, $field_name, $nid_or_type, $new_revision = TRUE, array $extras = [], $is_invalid = FALSE) {
    

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

+++ b/core/modules/file/tests/src/Functional/DownloadTest.php
@@ -70,17 +73,28 @@ protected function doPrivateFileTransferTest() {
+    try {
+      $http_client->head($url);
+      $this->fail('Not correctly denied access to a file when file_test sets the header to -1.');
+    }
+    catch (RequestException $e) {
+      $this->assertSame(403, $e->getCode());
+    }
...
+    try {
+      $http_client->head($url);
+      $this->fail('Not correctly returned 404 response for a non-existent file.');
+    }
+    catch (RequestException $e) {
+      $this->assertSame(404, $e->getCode());
+    }

What about setting ['http_errors ' => FALSE] in guzzle? Wouldn't this be way more readable overall?

Anonymous’s picture

#44 it is nice idea! Thank you, @dawehner!

Status: Needs review » Needs work

The last submitted patch, 45: 2870448-45.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Anonymous’s picture

After epic #2346893: Duplicate AJAX wrapper around a file field we have one js-test FileFieldValidateTest::testAJAXValidationMessage().

How to do better?

  1. Leave the FileFieldValidateTest only with this one test, and include it in the scope of #2809503: Convert AJAX part of \Drupal\file\Tests\FileFieldWidgetTest to JavascriptTestBase
  2. Leave the full FileFieldValidateTest, and move it to separate issue or #2809503: Convert AJAX part of \Drupal\file\Tests\FileFieldWidgetTest to JavascriptTestBase.
  3. Convert FileFieldValidateTest::testAJAXValidationMessage() to JTB test here.
Anonymous’s picture

Status: Needs work » Needs review
FileSize
36.76 KB
8.3 KB

#47: FileFieldValidateTest::testAJAXValidationMessage() leave in WTB.


Replaced #2917885: Add drupalPostFormWithInvalidOptions() to BrowserTestBase on simplified version in BTB. BTB place because:
class FilePrivateTest extends FileFieldTestBase
class SaveUploadFormTest extends FileManagedTestBase

Both of them need in drupalPostFormWithInvalidOptions(). Other issues can be also need this API (example, #2949091: Multiple file field with all file extensions does not work).


Also removed extra parameter in FileFieldTestBase::uploadNodeFiles(). This parameter needs for #2809503: Convert AJAX part of \Drupal\file\Tests\FileFieldWidgetTest to JavascriptTestBase, but not now.

Status: Needs review » Needs work

The last submitted patch, 48: 2870448-48.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Anonymous’s picture

Title: [PP-1] Convert web tests to browser tests for file module » Convert web tests to browser tests for file module
Status: Needs work » Needs review
FileSize
36 KB
784 bytes

Opps, one unrelated change. (Edit: please ignore, incorrect branch compare Also strange, that the test run time increased by 5 minutes o_O. BTB::drupalPostForm() much slower than WTB::drupalPostForm()?)

Anonymous’s picture

Meh, decople FileFieldValidateTest looks ugly here, file to #2950187: Convert AJAX part of \Drupal\file\Tests\FileFieldValidateTest::testAJAXValidationMessage to JavascriptTestBase by analogy with other cases in IS.

Nit clean up.

Now the conversion is almost straight. But a couple of places:

  1. +++ b/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php
    @@ -97,15 +97,17 @@ public function testNodeDisplay() {
    -    $edit[$name] = \Drupal::service('file_system')->realpath($test_file->getFileUri());
    +    $edit_upload[$name] = \Drupal::service('file_system')->realpath($test_file->getFileUri());
    +    $this->drupalPostForm("node/$nid/edit", $edit_upload, t('Upload'));
    ...
    -    $this->drupalPostForm("node/$nid/edit", $edit, t('Preview'));
    +    $this->drupalPostForm(NULL, $edit, t('Preview'));
    ...
    +    $this->assertSession()->responseContains($field_name . '[1][description]', 'Description of second file appears as expected.');
    

    See #38.

  2. +++ b/core/tests/Drupal/Tests/BrowserTestBase.php
    @@ -1361,4 +1361,42 @@ protected function checkForMetaRefresh() {
    +  protected function drupalPostFormWithInvalidOptions($path, $edit, $submit) {
    

    Perhaps it's too arrogant to add this helper method right here, but who will tell me the best place?

Anonymous’s picture

Reroll after #2864035: Convert web tests to browser tests for rdf module.

Now without extra fixes in FileFieldTestBase, without new Trait, without new method in BrowserTestBase.

Anonymous’s picture

Took the FileFieldValidateTest from #2950187: Convert AJAX part of \Drupal\file\Tests\FileFieldValidateTest::testAJAXValidationMessage to JavascriptTestBase, because it is trivial convertion.

Created CR + updated @trigger_error message.

Converted *Update* test (trivial changes in path to fixtures).

Anonymous’s picture

From CR (or trigger_error):

\Drupal\file\Tests\FileFieldTestBase have been deprecated. Instead, use \Drupal\Tests\file\Functional\FileFieldTestBase

But we definitely need to convert the api-methods from the FileFieldTestBase class to the trait. Example for create JTB tests like #2809503: Convert AJAX part of \Drupal\file\Tests\FileFieldWidgetTest to JavascriptTestBase.

It may be better to move this class to trait right now, for avoid one more record like:

\Drupal\Tests\file\Functional\FileFieldTestBase have been deprecated. Instead, use trait \Drupal\Tests\file\Traits\FileFieldTestBaseTrait

?

Anonymous’s picture

#54: opps, I am lol. Move methods from class to trait does not mean, that class will be deprecated :)
So, we can make trait late.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

This looks great, I found a couple of places where we're using a t( where it's not needed, but since this is just a conversion, we should just do this and fix those later, if we get a phpcs rule for it.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/file/tests/src/Functional/DownloadTest.php
    @@ -25,16 +25,17 @@ public function testPublicFileTransfer() {
    +    $http_client = \Drupal::httpClient();
    
    @@ -70,17 +71,19 @@ protected function doPrivateFileTransferTest() {
    +    $http_client = $this->getSession()->getDriver()->getClient()->getClient();
    

    Why are we getting the client in different ways? Let's pick one.

  2. +++ b/core/modules/file/tests/src/Functional/FilePrivateTest.php
    @@ -92,8 +95,11 @@ public function testPrivateFile() {
    +    // Can't use drupalPostForm() for set hidden fields.
    

    to set I think.

Lendude’s picture

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
FileSize
27.05 KB
2.73 KB

Addressed changes mentioned in #57 by @alexpott & Thanks @Lendude for pointing out.
Added updated patch with an interdiff.

Lendude’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @yogeshmpawar! Feedback has been addressed, back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 6312fcb and pushed to 8.6.x. Thanks!

  • alexpott committed 6312fcb on 8.6.x
    Issue #2870448 by vaplas, naveenvalecha, yogeshmpawar, dawehner,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

quietone’s picture

publish the change record