Problem/Motivation

We created Views widget plugin but we're missing tests.

Proposed resolution

Create new test class for functional tests and create test case that clicks through View widget and checks if everything works as expected and entities are selected (events are emitted).

Remaining tasks

- write patch
- review

User interface changes

N/A

API changes

New test class and tests are added.

Comments

slashrsm’s picture

Issue tags: +Needs tests, +Novice
slashrsm’s picture

Issue tags: +Media Initiative, +sprint
slashrsm’s picture

Issue tags: -sprint +D8Media
devlada’s picture

Assigned: Unassigned » devlada

working on this...

marcoscano’s picture

Assigned: devlada » Unassigned

Freeing up the issue, please feel free to re-assign it if needed.

Please note that inside the patch uploaded in #2376643-4: Write functional tests for Upload widget there is a work-in-progress of this test, can be used as a starting point.

gaurav.goyal’s picture

Assigned: Unassigned » gaurav.goyal

Working on this.

gaurav.goyal’s picture

StatusFileSize
new3.37 KB

Initial patch for the starting point. Currently, it does not include the actual test case.

gaurav.goyal’s picture

Status: Active » Needs review

Changing status to Need review.

Status: Needs review » Needs work

The last submitted patch, 7: write_functional_tests-2376639-7.patch, failed testing.

The last submitted patch, 7: write_functional_tests-2376639-7.patch, failed testing.

gaurav.goyal’s picture

Status: Needs work » Needs review
StatusFileSize
new4.09 KB

Fixed module names and permissions.

Status: Needs review » Needs work

The last submitted patch, 11: write_functional_tests-2376639-11.patch, failed testing.

The last submitted patch, 11: write_functional_tests-2376639-11.patch, failed testing.

gaurav.goyal’s picture

Status: Needs work » Needs review
StatusFileSize
new12.15 KB

Updated patch. I've created a view and added its configuration file in entity_browser_test module.

Hoping it will come green this time :)

gaurav.goyal’s picture

Issue tags: +#drupalIndiaSprint
gaurav.goyal’s picture

StatusFileSize
new12.14 KB

Improved documentation of the patch.

thenchev’s picture

Status: Needs review » Needs work
  1. +++ b/src/Tests/EntityBrowserViewsWidgetWebTest.php
    @@ -0,0 +1,173 @@
    +/**
    + * @file
    + * Contains \Drupal\entity_browser\Tests\EntityBrowserViewsWidgetWebTest.
    + */
    

    No need for this anymore. Look at #2304909: Relax requirement for @file when using OO Class or Interface per file

  2. +++ b/src/Tests/EntityBrowserViewsWidgetWebTest.php
    @@ -0,0 +1,173 @@
    +  public static $modules = [
    +    'system',
    +    'user',
    +    'node',
    +    'file',
    +    'field_ui',
    +    'ctools',
    +    'views',
    +    'views_ui',
    +    'entity_reference',
    +    'entity_browser_test',
    +  ];
    

    You can remove system, user, file, field_ui, views, entity_reference

    we only have to define what we need the dependencies are loaded automatically.

  3. +++ b/src/Tests/EntityBrowserViewsWidgetWebTest.php
    @@ -0,0 +1,173 @@
    +  /**
    +   * Setup Environment.
    +   */
    

    You can just {@inheritdoc} here.

  4. +++ b/src/Tests/EntityBrowserViewsWidgetWebTest.php
    @@ -0,0 +1,173 @@
    +    $this->user = $this->drupalCreateUser([
    +      'administer site configuration',
    +      'administer nodes',
    +      'administer content types',
    +      'administer node fields',
    +      'bypass node access',
    +      'administer views',
    +      'access content',
    +      'administer users',
    +      'access user profiles',
    +      'administer permissions',
    +      'administer entity browsers',
    +      'administer display modes',
    +      'administer node display',
    +      'administer node form display',
    

    We probably don't need all of these. Check which are not needed and remove.

  5. +++ b/src/Tests/EntityBrowserViewsWidgetWebTest.php
    @@ -0,0 +1,173 @@
    +      'title_label' => 'An example Custom Content type.',
    

    Not really needed.

  6. +++ b/src/Tests/EntityBrowserViewsWidgetWebTest.php
    @@ -0,0 +1,173 @@
    +      'cardinality' => '-1',
    

    Do we need this?

  7. +++ b/src/Tests/EntityBrowserViewsWidgetWebTest.php
    @@ -0,0 +1,173 @@
    +    // Create a new entity browser.
    +    $entity_browser = $this->createEntityBrowser();
    

    Instead of creating an entity browser like this you could export it in the configuration synchronization and place it in the test module.

  8. +++ b/src/Tests/EntityBrowserViewsWidgetWebTest.php
    @@ -0,0 +1,173 @@
    +    // Add the permission to access to this entity_browser page to the user.
    +    $role = Role::load('authenticated');
    +    $role->grantPermission('access test_entity_browser entity browser pages');
    +    $role->save();
    

    If you export the browser you don't need this just add the permission when you create the user.

also if im not mistaken => 'checks if everything works as expected and entities are selected' We don't cover this part yet.

sylus’s picture

Because simpletest will be replaced with PHPUnit in 8.2.x should these tests instead leverage BrowserTestBase? Like the following:

http://cgit.drupalcode.org/video_embed_field/tree/tests/src/FunctionalJa...

Though I guess this would only be for 8.2.x branch? As the notes currently say:

"The main limitation of BrowserTestBase currently is that it cannot use JavaScript and AJAX. If your tests require that, you will need to use the old WebTestBase until JavaScript support is added to BrowserTestBase."

slashrsm’s picture

That would make a lot of sense.

slashrsm’s picture

Issue tags: +RC blocker
samuel.mortenson’s picture

StatusFileSize
new1.72 KB

Based on the feedback in #17 and that the current patch doesn't actually test the View widget, I've written a minimalist patch using BrowserTestBase (per #18) that just tests the submit functionality of the widget. We can expand upon this later by testing more complex use cases, but this is nice because it scopes the test coverage to the View widget. If people like what I've done here I can roll a similar patch for #2376643: Write functional tests for Upload widget.

samuel.mortenson’s picture

Status: Needs work » Needs review
slashrsm’s picture

StatusFileSize
new5.61 KB
new5.63 KB

Looks great. I added few asserts that ensure that expose filters are not completely broken. Since view uses AJAX for that I needed to convert to javascript test, which also revealed another missing dependency in iframe_selection library. Tests++

Status: Needs review » Needs work

The last submitted patch, 23: 2376639_23.patch, failed testing.

The last submitted patch, 23: 2376639_23.patch, failed testing.

slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new6.72 KB
new1.11 KB

Nice... this revealed another unrelated bug. Dropdown widget selector apparently doesn't work with view exposed filters. Even worse, I suspect that views exposed filters break in case of *any* element on the form with #ajax. This is not scope of this issue so for now just making sure that tests pass and will open separate issue for this bug.

I also suspect that View widget and No display selection display don't work correctly when other submit elements than the main one are on the form. Will also create follow-up for that.

slashrsm’s picture

Status: Needs review » Fixed
marcoscano’s picture

Status: Fixed » Closed (fixed)

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