Problem/Motivation
The simpletest \Drupal\content_moderation\Tests\ModerationStateNodeTypeTest::testEnablingOnExistingContent is passing but the very last assertion would fail if it was case insensitive. This is misleading unless you know that by enabling the content_moderation module the value attribute of the publish submit option changes from "Save and publish" to "Save and Publish".
You would be forgiven for believing that the intent of the last assertion was to determine that the text "Save and publish" does not appear in the raw HTML regardless of case.
$this->assertNoRaw('Save and publish');
When attempting to convert this to a BrowserTestBase this fails because assertNoRaw is case insensitive and because the intent of this test is not clear it means we needed clarification before proceeding with the conversion. See: #2864008: Convert web tests to browser tests for content_moderation module
Proposed resolution
Improve the test by adding a comment and perhaps be more explicit that the intent is to prove that enabling the content_moderation module has had the expected impact on the value attribute of the publish submit button
Comment | File | Size | Author |
---|---|---|---|
#16 | 2864060-16.patch | 2.26 KB | Lendude |
#16 | interdiff-2864060-15-16.txt | 1.61 KB | Lendude |
#15 | 2864060-15.patch | 2.22 KB | Lendude |
#15 | interdiff-2864060-14-15.txt | 2.06 KB | Lendude |
#14 | 2864060-14.patch | 2.21 KB | nlisgo |
Comments
Comment #2
nlisgo CreditAttribution: nlisgo commentedThis test only patch proves that there is a bug.
Comment #3
nlisgo CreditAttribution: nlisgo commentedComment #5
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedIf it's case insensitive, it should have passed. "Save and publish" is the button text when content moderation isn't installed and "Save and Publish" is the button text once it is installed, so I think this is correct.
An improvement we could make here is adding a property to our base class called $coreSaveButtonText and $moderationSaveButtonText to make it clear what the difference in case for these strings mean.
Comment #6
nlisgo CreditAttribution: nlisgo commented@Sam152, if this is the case then we should make it more explicit in a comment above the insertion because without that knowledge that the case changes after content_moderation is installed then a developer is going to assume that the intent of the test is to check that "save and publish" is not found in the html regardless of case.
I will refactor the patch in #2864008-2: Convert web tests to browser tests for content_moderation module so that it performs a case sensitive check.
Why is the text changed after content_moderation is installed????
Comment #7
nlisgo CreditAttribution: nlisgo commented@Sam152, another suggestion would be to check to refactor the test as follows:
Thoughts?
Comment #8
timmillwoodI like the sounds of #7.
Node: #2753717: Add select field to choose moderation state on entity forms also changes this part of the test, so not sure if it's worth just waiting for that to get in?
Comment #9
nlisgo CreditAttribution: nlisgo commentedHave improved the title and description of this issue. The patch implements the suggestion in #7.
Comment #10
timmillwoodComment #11
alexpottHmmm... I'm not sure that this is right I think the intention of the test was to ensure that a user without the
'use editorial transition publish'
couldn't use the publish transition. However the assertion broke when we did #2779647: Add a workflow component, ui module, and implement it in content moderation.I think we should create a user without that permission instead of doing
$this->drupalLogin($this->adminUser);
and then test for "Save and Publish" not being there. And then we should grant the user that permission and test that is. This way we'd prevent a similar future regression.Comment #12
Eric_A CreditAttribution: Eric_A commentedComment #13
nlisgo CreditAttribution: nlisgo commented@alexpott thanks for the clarification. We will need to modify the title and description again. I will try and give this some attention today.
Comment #14
nlisgo CreditAttribution: nlisgo commentedAddressing feedback in #11.
Comment #15
LendudeThe whole Role thing seems a little convoluted. Why not just create two users like this?
Comment #16
LendudeCleaned up the naming a bit.
Comment #18
nlisgo CreditAttribution: nlisgo commented@Lendude, I did wonder whether that would be a better approach. The test case certainly looks a lot cleaner.
Comment #19
timmillwoodMuch needed fix, looks good.
Comment #21
alexpottCommitted and pushed 73b750b to 8.4.x and deba11f to 8.3.x. Thanks!