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 nameviews.view.<machine_name>.yml
- Implement
setUp
and callViewTestData::importTestViews()
passing the module containing the default test view.
- add the view machine name on the
- It is recommended define the test calss on
Drupal\file\Tests\Views namespace
. - Mention how to use
dataSet()
andviewsData()
. - 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
- at
User interface changes
None.
API changes
None.