Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We need to ensure that tips corresponding page elements to not get removed (or need to be adjusted).
We are to provide a TourTestBase class that will aid in the creation of tests for this.
Basic usage:
function testTourViewEditBasic() {
$this->drupalLogin($this->admin);
$this->drupalGet('foo');
$this->assertTourTips();
}
}
Advanced usage (in the case of multipage or targetting a subset of tips):
function testTourViewEditBasic() {
$this->drupalLogin($this->admin);
$this->drupalGet('foo');
$tips = array();
$tips[] = array('data-id' => 'foo');
$tips[] = array('data-id' => 'bar');
$tips[] = array('data-class' => 'baz');
$this->assertTourTips($tips);
}
}
We also provide a basic class that can be implemented to ensure all tips are available on a page (this is ideal for very simple one page tours):
/**
* @file
* Contains \Drupal\system\Tests\SystemTour.
*/
namespace Drupal\system\Tests;
use Drupal\tour\Tests\TourTestBasic;
/**
* Tests tour functionality.
*/
class SystemTour extends TourTestBasic {
protected $tips = array('/admin/modules' => array());
protected $permissions = array('administer modules', 'access tour');
public static $modules = array('tour');
public static function getInfo() {
return array(
'name' => 'Extend tour tests',
'description' => 'Tests the Extend tour.',
'group' => 'Tour',
);
}
}
Comment | File | Size | Author |
---|---|---|---|
#59 | 2028535-59-tour-test-unused.patch | 847 bytes | tstoeckler |
#56 | interdiff.txt | 2.96 KB | nick_schuch |
#56 | 2028535-55-tourtestbase.patch | 9.79 KB | nick_schuch |
#54 | interdiff.txt | 1.63 KB | nick_schuch |
#54 | 2028535-54-tourtestbase.patch | 7.26 KB | nick_schuch |
Comments
Comment #1
clemens.tolboomWe should validate tours for their schema as noted in #2027469: View UI Tour is not working and had a sandbox update.
Comment #2
clemens.tolboomI'm working on this.
Comment #3
clemens.tolboomAttached patch creates a base test for views_ui tour
It needs more testing on the currently available tours in the issue queue as some tours have module dependent tips
Comment #4
clemens.tolboomThis should not test for the aria values but the real page elements.
Comment #5
clemens.tolboomAttached patch add testing on tip targets pointed to by data-id and data-class but fails on data-class as those can sub selects.
Ie core/modules/views_ui/config/tour.tour.views-ui.yml has
For xpath to work that should be converted into something like
//p[contains(concat(" ",@class," "),concat(" ","sb-fs"," "))][contains(concat(" ",@class," "),concat(" ","bar"," "))]
taken from example on http://cowburn.info/2009/06/15/xpath-css-class/We should use http://symfony.com/doc/current/components/css_selector.html for this I guess :-/
Comment #6
clemens.tolboomLet's run the tests so it's failure become logged :-/
Comment #7
clemens.tolboomThis needs a rewrite on the class selectors.
1. Is it possible at all having both a data-id and data-class?
2. How to get a proper XPath expression on the mentioned 'long' data-class values?
Comment #9
clemens.tolboomAttached patch add https://github.com/symfony/CssSelector
Test assume only either data-id or data-class is used.
Comment #11
clemens.tolboomThis needs a rewrite as #1959660: Replace xpath() with WebTestBase::cssSelect() by leveraging Symfony CssSelector makes better change to get committed then #2030369: Add Symfony CssSelector to core as discussed in #1959660-23: Replace xpath() with WebTestBase::cssSelect() by leveraging Symfony CssSelector.
Comment #12
clemens.tolboomThis is now a bug fix issue too. Patch contains #1959660: Replace xpath() with WebTestBase::cssSelect() by leveraging Symfony CssSelector and fixed some new issues.
- The test pages did not contain the all tour target (data-id) elements. Which explains the failure of #9
- The id versus data-id is unclear. These should not be the same? It is at least confusing as we have tour/id, tip/id and data-id. That's a documentation issue and for Tour UI.
https://drupal.org/files/tour-test-base-2028535-12-do-not-test.patch is without #1959660: Replace xpath() with WebTestBase::cssSelect() by leveraging Symfony CssSelector
Comment #13
clemens.tolboomPatch from #12 needed reroll due to #1754246: Languages should be configuration entities
The idea is test whether the target for the tips are on the page. Should we still test for the existence of the tip?
$this->tipOnPage($tip['id'], $selector);
I added skip_ids when testing a tour.
One issue spring to mind: hook_tip_alter could add more tips on the page then function loadTours() fetches? That is hook_tour_tips_alter is not precessed by our
function loadTours()
?Comment #14
clemens.tolboomNeeds updated documentation.
Needs documentation.
Next is xpath versus cssSelect:
and
Why not using cssSelect here? This was partly due to time to change all. see also #1959660: Replace xpath() with WebTestBase::cssSelect() by leveraging Symfony CssSelector
Comment #15
nick_schuch CreditAttribution: nick_schuch commentedHi Clemens,
I have read through the patch and I think we might be able to refactor it to (instead of loading the yml file) check what tips are on the page and ensure it's elements are available.
Ill write a patch to demonstrate this more clearly but the basic idea is:
1) I go to the page.
2) I get the tips from the markup.
3) I then compare and ensure those tips have the ID on the page.
Ill continue reading through and will produce a patch.
Comment #16
clemens.tolboom@nick_schuch that's a way better way.
Scanning for the available tour tips then check their targets. These are not filtered out when testing.
I'm still puzzled how to note testers on hook_tour_tips_alter as that must trigger something for the translation workflow. Should we add a failure test when running tests manually? Can we?
Comment #17
clemens.tolboomComment #18
xjmLet's use a test view here instead of coupling this to the frontpage view. We can use the test views that already exist.
Comment #19
xjmAlso, the class name should be TourTestBase, not TourBaseTest.
Comment #20
nick_schuch CreditAttribution: nick_schuch commentedHere is my first patch that takes the approach discussed in #15 and #16. We should also add a test for Views UI here as a proof of concept.
Comment #21
xjmComment #22
nick_schuch CreditAttribution: nick_schuch commentedHere is the latest patch. We NEED the cssSelect() for tip evaluation (provided in #2030369).
This patch includes a working example of the base class in action.
I have also provided a fail for the instance when no tips are found on the page in which the check is instantiated. This will help with path matching fails eg. what we have with views right now.
I have attached a FAIL and PASS patch.
Comment #24
larowlan#1959660: Replace xpath() with WebTestBase::cssSelect() by leveraging Symfony CssSelector is where we're adding a cssSelect method, albeit just using the existing one provided by PHP Unit in core atm.
The Symfony one was originally proposed and rejected in that issue. #2030369: Add Symfony CssSelector to core is a duplicate in my opinion.
Looks like the tests didn't do what was expected :(
Comment #25
nick_schuch CreditAttribution: nick_schuch commentedThanks larowlan!!!!
Here we go. I have also refactored the existing Views UI tour test to use our new base class.
FAIL - I am breaking the Views UI tour intentionally to show the base class failing (cannot find tips).
PASS - Checks the page for tour tips and corresponding elements.
Comment #27
larowlanThis looks great
Needs to wrap at 80 chars
Example
Should this be wrapped in @code/@endcode?
Can we get a comment along the lines 'Tips are rendered as
<li> elements inside <ol id="tour">
' just to make it clear?$this->fail() is available
::cssSelect ftw
Do you think it would be possible to have another test class that extends this that looks for $this->tips and $this->paths?
Then each module could just extend that class and have the test write it self eg:
Thoughts?
Comment #28
nick_schuch CreditAttribution: nick_schuch commentedThat's a great idea!
Here is the patch :)
I have tested this against forum issue #1926296 with the following test class: https://gist.github.com/anonymous/a38ba00c172ac0a137d6 (it's in gist form because it's not appropriate for this issue and I will be committing it to the forum issue instead).
Comment #29
larowlanAwesome, a few nitpicks
Ouch whitespace
their :(
Don't use t in assert messages
the tour?
I think docblocks for ::setUp are frowned upon, so we should move this comment inside the function (inline comment)
Missing newline at end of file
edit: removed duplicate from dreditor
Comment #30
nick_schuch CreditAttribution: nick_schuch commentedHere are the fixes from #29.
Comment #31
larowlanMore nitpicks (sorry)
Needs a .
Missing newline
Comment #32
nick_schuch CreditAttribution: nick_schuch commentedHere we go. However, I must have not included the "new line" fix in my previous patch (I have it as a commit locally). It's in the full patch.
Comment #33
larowlanI think this is ready (unless bot says no)
Comment #34
clemens.tolboomWhen should one use the advanced version. I'd like some more documentation here.
This relates to hook_tour_tips_alter I guess.
iirc we tested for count($elements) === 1. Is it wrong to have more elements?
Why are these tips added? Should we document this for contrib coders?
Comment #35
nick_schuch CreditAttribution: nick_schuch commented1) The advanced example is for the testing of tours that use wildcards.
2) We are testing to make sure that an element does not disappear from the page.
3) These tips are added to the "tour_test" module. Which is enabled for testing tour. We are using the "container" to provide corresponding elements on the page.
Comment #36
clemens.tolboom@nick_schuch I guess I should have set this to needs works as I don't know what to do when writing a tour test. There is no documentation in the code.
Your answers from #35 should be into the patch to help 'people like me'
Comment #37
nick_schuch CreditAttribution: nick_schuch commentedHere is the patch as per #36.
The Tour API documentation page should be updated *after* this is committed to core. Otherwise people will start to write tests and get confused because it is not committed.
As per #28 this gist could be used for that documentation: https://gist.github.com/anonymous/a38ba00c172ac0a137d6
Comment #38
larowlanunless bot disagrees, this is back to RTBC
Comment #39
alexpottSo we're adding an abstract class we no use case in core - this is dangerous - we have no idea if it works. There should be at least one use case - just to test it.
Comment #40
nick_schuch CreditAttribution: nick_schuch commentedOk, I have removed the TourTestSimple and will implement in a different ticket which has Tour Tips to test.
I also found some additional checks for the assertTips for id's and classes (see interdiff).
Comment #41
larowlan!empty($elements) && count($elements) == 1?
I had to read that a few times to make sense of it
This would be better as assertFalse
Comment #42
nick_schuch CreditAttribution: nick_schuch commentedThanks larowlan!
Comment #43
larowlanUnless bot disagrees
Comment #44
xjm#42: 2028535-42-tourtestbase.patch queued for re-testing.
Comment #46
nick_schuch CreditAttribution: nick_schuch commented#42: 2028535-42-tourtestbase.patch queued for re-testing.
Comment #47
nick_schuch CreditAttribution: nick_schuch commentedUnrelated fails.
- HTTP response expected 204, actual 400
- Value 'aQ{aB`_-' is equal to value '"9Hs>XGN
Rerunning.
Comment #49
larowlanyeah see #2056713: Random test failure in Drupal\rest\Tests\NodeTest
Comment #50
larowlan#42: 2028535-42-tourtestbase.patch queued for re-testing.
Comment #51
larowlanBack to Rtbc
Comment #52
alexpottThe issue summary seems to be out of date as the code example uses methods which do not exist and are not added by this patch.
What's weird is that we've got usage of the advanced usage of this function. Therefore we have no idea if it works :) We need some usage in a test to confirm this works.
Comment #52.0
alexpottUpdated the example to patch #3
Comment #52.1
nick_schuch CreditAttribution: nick_schuch commentedUpdate summary to resemble new TourTestBase
Comment #53
nick_schuch CreditAttribution: nick_schuch commentedI have updated the issue summary. Will update the tests first thing tomorrow.
Comment #54
nick_schuch CreditAttribution: nick_schuch commentedThanks alexpott! Here is the addition to test the advanced implementation.
Comment #55
nick_schuch CreditAttribution: nick_schuch commentedComment #55.0
nick_schuch CreditAttribution: nick_schuch commentedFixes missing ?>
Comment #56
nick_schuch CreditAttribution: nick_schuch commentedThe following adds back in a class that will aid tour creators in writing tests for tip content.
I have also included an example in the description.
Comment #57
larowlanI've reviewed this in length several times and I think we have the best of both worlds here.
We have a new assert helper for use in complex and simple cases.
We have a TourTestBasic class that can be easily extended where all we care about is making sure the elements we're attaching tour tips to still exist on the page, ie to protect against markup/path changes breaking existing tours.
The class name was discussed in irc and I think TourTestBasic fits far better than TourTestSimple.
There's a tour sprint at DrupalGov in around 10 days or so, getting this in before then will be a huge win.
Comment #57.0
larowlanUpdate summary to include basic tour class example
Comment #58
Dries CreditAttribution: Dries commentedCommitted to 8.x. Thanks!
Comment #59
tstoecklerThis is actually unused.
We don't need to use something when inside the same namespace.
Comment #59.0
tstoecklerUpdate from TourTestSimple to TourTestBasic
Comment #60
dawehner59: 2028535-59-tour-test-unused.patch queued for re-testing.
Comment #61
star-szrFollow-up looks fine!
Comment #62
alexpottCommitted 9279766 and pushed to 8.x. Thanks!