Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 301969

Document how to make views unit tests

$
0
0

Problem/Motivation

While I was trying to figure out #1791970: Optionally detect tar.* as extension instead of * on views file extension field handler I noticed the procedure to make views unit test is a little tricky, and some maintainers agreed with me about that.

So, what I think we should be documented:

  • It is recommmended to use a custom module to test views handlers.
  • Those modules should live on module's tests/modules directory.
  • It is recommmended to define new views instead of reusing the ones provided by views and change them at runtime, unless there is a good reason behind that.
  • To have the defined view loaded you need to:
    • add the view machine name on the $testViews data member declaration
    • store the exported view on test module's test_views directory with file name views.view.<machine_name>.yml
    • Implement setUp and call ViewTestData::importTestViews() passing the module containing the default test view.
  • It is recommended define the test calss on Drupal\file\Tests\Views namespace.
  • Mention how to use dataSet() and viewsData().
  • Maybe an basic example (an extension of Drupal\views\Tests\BasicTest?).

Proposed resolution

Let's document it!

Remaining tasks

  • Decide where to document it. Current propposals:
    • at Drupal\views\Tests\ViewUnitTestBase
    • at Drupal\views\Tests\BasicTest

User interface changes

None.

API changes

None.


Viewing all articles
Browse latest Browse all 301969

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>