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.
Problem/Motivation
Currently the test checks that text is not present on the page, however it does this as the anonymous user which gets an access denied on this page anyway.https://git.drupalcode.org/project/drupal/-/commit/b2320bc9d58ee9c5df269...
$this->drupalGet('admin/content/block/' . $loaded->id());
$this->assertSession()->pageTextNotContains($loaded->body->value);
pageTextNotContains() doesn't make sense here because the page is not available for anonymous user.
Steps to reproduce
NA
Proposed resolution
Login as $this->adminUser
in the test.
per @xjm in #22 extend test coverage
Remaining tasks
Implement
Review
User interface changes
NA
API changes
NA
Data model changes
NA
Release notes snippet
NA
Comment | File | Size | Author |
---|
Issue fork drupal-2791061
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
Chi CreditAttribution: Chi commentedComment #4
Chi CreditAttribution: Chi commentedComment #5
dawehnerDo you mind adding a
$this->assertResponse(200)
? I think this would clarify a bit more what is going on, as well as prevented the situation in the first place.Comment #6
Chi CreditAttribution: Chi commentedAdded
$this->assertResponse(200)
.Comment #16
smustgrave CreditAttribution: smustgrave at Mobomo commentedStill seems valid.
Rerolled
Comment #17
smustgrave CreditAttribution: smustgrave at Mobomo commentedComment #18
smustgrave CreditAttribution: smustgrave at Mobomo commentedComment #19
smustgrave CreditAttribution: smustgrave at Mobomo commentedReran for 10.1
Comment #21
joachim CreditAttribution: joachim as a volunteer commentedComment #22
xjmRead over the whole test and this makes sense. This highlights why it's always a good idea to have positive and negative assertion pairs, rather than just negative assertions.
To that end, could we change the test a bit further? Add a
pageTextContains()
assertion that asserts what block content should be there at this point in the test?It'd be even better to place the block, assert its content, change the default revision, and then assert its content.
It'd also be better not to use random machine names for the content of the two revisions, because there is a nonzero chance it could generate the same placeholder and cause a fail.
Comment #23
smustgrave CreditAttribution: smustgrave at Mobomo commented@xjm
not sure I follow the points
The block body is nothing when $this->assertSession()->pageTextNotContains($loaded->body->value);
is checked can add a fieldValueEquals if we really need to
Seems to be out of scope for this issue
RandomMachine name is only called once to set the body (which previously was empty) so not sure how there could be conflict?
Comment #24
smustgrave CreditAttribution: smustgrave at Mobomo commentedComment #26
smustgrave CreditAttribution: smustgrave at Mobomo commentedComment #27
smustgrave CreditAttribution: smustgrave at Mobomo commentedComment #28
acbramley CreditAttribution: acbramley at PreviousNext for Service NSW commentedIt's not clear to me from the comments or IS why exactly we need to login as the admin user?
Comment #29
larowlan+1 for logging in as a user with the minimum set of permissions rather than the admin user. Using the admin user masks subtle bugs.
Comment #30
smustgrave CreditAttribution: smustgrave at Mobomo commentedSlightly tweaked based on @larowlan comment in #29
Addressed feedback.
Comment #31
acbramley CreditAttribution: acbramley at PreviousNext for Service NSW commentedComment #32
acbramley CreditAttribution: acbramley at PreviousNext for Service NSW commentedUpdated the IS to be more accurate. I'm honestly questioning whether we need this test at all. It's testing the most arbitrary stuff and was first added in a very similar state 10 years ago https://git.drupalcode.org/project/drupal/-/commit/b2320bc9d58ee9c5df269...
What the test does (currently):
When I say redundant I mean it's probably tested elsewhere, or completely useless.
Setting to NW because honestly I reckon we ditch the test entirely after confirming we're covered elsewhere.
Comment #33
smustgrave CreditAttribution: smustgrave at Mobomo commentedSo just checking item 1 this appears to be the only test using setRevisionLogMessage and testing the message on the version-history page.
So not 100% sure it is covered elsewhere.
Comment #34
acbramley CreditAttribution: acbramley at PreviousNext for Service NSW commentedBut it doesn't check the version history page? It checks getRevisionLogMessage returns what was set in setUp
We do have other testing for the version history page though! https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/block...