Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT Behat test to test special characters in shortcode #1376

Conversation

sabina-talipova
Copy link
Contributor

@sabina-talipova
Copy link
Contributor Author

Require PR

@GuySartorelli
Copy link
Member

I've rerun the behat tests but they're failing. Have confirmed that behat is running against the recent changes, so there's either something wrong with the test or the new logic.

@sabina-talipova sabina-talipova force-pushed the pulls/4.13/behat-test-special-characters branch 4 times, most recently from 244e294 to 90734a8 Compare August 8, 2023 02:46
@sabina-talipova
Copy link
Contributor Author

Fixed

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this still isn't working as expected.

I would expect to see My alt updated & saved in the HTML, but this test shows My alt updated & saved which is incorrect.

We should also add to the behat test what happens on the front-end, to validate that the frontend markup has alt="My alt updated & saved" and not alt="My alt updated & saved" or alt="My alt updated & saved".

@sabina-talipova sabina-talipova force-pushed the pulls/4.13/behat-test-special-characters branch 8 times, most recently from 47e336b to 21b1081 Compare August 8, 2023 23:09
@sabina-talipova
Copy link
Contributor Author

Follow [TinyMC documentation] (https://www.tiny.cloud/docs/tinymce/6/content-filtering/#entities) and this:

The base entities <, >, &, ', and " will always be entity encoded into their named equivalents.

So my assumption, when we just start to work on content and add new special characters TinyMC will always encoded them into their named equivalents. So this we see this here.
First string that I get before "Save" (named equivalents):

document.querySelector('textarea[name="Content"]').value
'<div class="captionImage leftAlone" style="width: 444px;">[image src="http://localhost:90/sink413x/assets/Uploads/GitHub-avatar-v2.jpeg" id="3" width="444" height="444" class="leftAlone ss-htmleditorfield-file image" alt="Batman &amp; Robin"]\n<p class="caption leftAlone">Batman &amp; Robin</p>\n</div>'

Second string that I get after "Save" (entities):

document.querySelector('textarea[name="Content"]').value
'<div class="captionImage leftAlone" style="width: 444px;">[image src="/sink413x/assets/Uploads/GitHub-avatar-v2.jpeg" id="3" width="444" height="444" class="leftAlone ss-htmleditorfield-file image" alt="Batman & Robin"]\n<p class="caption leftAlone">Batman & Robin</p>\n</div>'

Third string that I get after I made some changes, but not "Save" yet (named equivalents):

document.querySelector('textarea[name="Content"]').value
'<div class="captionImage leftAlone" style="width: 444px;">[image src="/sink413x/assets/Uploads/GitHub-avatar-v2.jpeg" id="3" width="444" height="444" class="leftAlone ss-htmleditorfield-file image" alt="Batman &amp; Robin"]\n<p class="caption leftAlone">Batman &amp; Robin &amp; Co</p>\n</div>'

This string we pass to the server from the client :

<div class="captionImage leftAlone" style="width: 444px;">[image src="/sink413x/assets/Uploads/GitHub-avatar-v2.jpeg" id="3" width="444" height="444" class="leftAlone ss-htmleditorfield-file image" alt="Batman &amp; Robin"]
<p class="caption leftAlone">Batman &amp; Robin &amp; Co</p>
</div>

This string we store in DB:

<div class="captionImage leftAlone" style="width: 444px;">[image src="/sink413x/assets/Uploads/GitHub-avatar-v2.jpeg" id="3" width="444" height="444" class="leftAlone ss-htmleditorfield-file image" alt="Batman &amp; Robin"]
<p class="caption leftAlone">Batman &amp; Robin &amp; Co</p>

It looks like TinyMC convert html entities into named equivalents in whole content every time when we edit it. When we return & as is from DB (I updated &amp; with & in string in DB), then TinyMC shows it as is, but encode it to &amp; as soon as we make any small changes (add 'Space').

So for behat test we should expect that after "Save" we will get My alt updated & saved instead of My alt updated &amp; saved. I add some test to show all this explanation above.

@sabina-talipova sabina-talipova force-pushed the pulls/4.13/behat-test-special-characters branch 3 times, most recently from f600e84 to 5e321bb Compare August 9, 2023 00:26
tests/behat/features/insert-an-image.feature Show resolved Hide resolved
Comment on lines 134 to 135
And I should see an "img[alt='My alt updated &amp; saved']" element
And I should see an "img[title='My title text updated &amp; saved']" element
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not seem like it, but this actually means we're still double encoding. These should be queryable as img[alt='My alt updated & saved'] and img[title='My title text updated & saved']

I've gone back and re-run my manual tests. It turns out that the inspector in both firefox and chrome shows the decoded version of the string. So I saw this:
Screenshot from 2023-08-10 09-48-40
alt="some &amp; thing"

But the actual value (seen by right clicking and selecting "Edit as HTML") was this:
Screenshot from 2023-08-10 09-48-52
alt="some &amp;amp; thing"

So we're still double encoding. Sorry I didn't catch it before merging the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes that were made are correct, but they fixed problem in CMS itself. Current problem happens now when we display Content on a page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix it and update Behat tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you, please review this PR

@sabina-talipova sabina-talipova force-pushed the pulls/4.13/behat-test-special-characters branch from 5e321bb to f9b11d7 Compare August 10, 2023 02:11
@sabina-talipova
Copy link
Contributor Author

Tests require this PR

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - it's green now the changes are merged.

@GuySartorelli GuySartorelli merged commit b50e1d5 into silverstripe:1.13 Aug 14, 2023
12 checks passed
@GuySartorelli GuySartorelli deleted the pulls/4.13/behat-test-special-characters branch August 14, 2023 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants