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

[TASK] Test universal selector with combinators #743

Merged
merged 1 commit into from
Sep 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## x.y.z

### Added
- Test universal selector with combinators
([#723](https://github.com/MyIntervals/emogrifier/issues/723),
[#743](https://github.com/MyIntervals/emogrifier/pull/743))
- Preserve `display: none` elements with `-emogrifier-keep` class
([#252](https://github.com/MyIntervals/emogrifier/issues/252),
[#737](https://github.com/MyIntervals/emogrifier/pull/737))
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ Emogrifier currently supports the following
* [type](https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors)
* [class](https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors)
* [ID](https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors)
* [universal](https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors):
* [universal](https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors)
(partial support)
* [attribute](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors):
* presence
* exact value match
Expand All @@ -348,7 +349,12 @@ Emogrifier currently supports the following

The following selectors are not implemented yet:

* [universal](https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors)
* [universal](https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors):
* with
[child combinator](https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator)
* as ancestor with
[descendant combinator](https://developer.mozilla.org/en-US/docs/Web/CSS/Descendant_combinator)
(e.g. `p *` is supported but `* p` is not)
* [case-insensitive attribute value](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors#case-insensitive)
* [general sibling](https://developer.mozilla.org/en-US/docs/Web/CSS/General_sibling_selectors)
* [pseudo-classes](https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes)
Expand Down
18 changes: 18 additions & 0 deletions tests/Unit/CssInlinerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public function matchedCssDataProvider()
'ID => with ID' => ['#p4 { %1$s }', '<p class="p-4" id="p4" style="%1$s">'],
'type & ID => type with ID' => ['p#p4 { %1$s }', '<p class="p-4" id="p4" style="%1$s">'],
'universal => HTML' => ['* { %1$s }', '<html style="%1$s">'],
'universal => element with parent and children' => ['* { %1$s }', '<p class="p-1" style="%1$s">'],
'universal => leaf element' => ['* { %1$s }', '<span style="%1$s">'],
'attribute presence => with attribute' => ['[title] { %1$s }', '<span title="bonjour" style="%1$s">'],
'attribute exact value, double quotes => with exact attribute match' => [
'[title="bonjour"] { %1$s }',
Expand Down Expand Up @@ -358,6 +360,16 @@ public function matchedCssDataProvider()
'child (without space before or after >) => direct child' => ['p>span { %1$s }', '<span style="%1$s">'],
'descendant => child' => ['p span { %1$s }', '<span style="%1$s">'],
'descendant => grandchild' => ['body span { %1$s }', '<span style="%1$s">'],
'adjacent universal => 2nd of many' => ['p + * { %1$s }', '<p class="p-2" style="%1$s">'],
'adjacent universal => last of many' => ['p + * { %1$s }', '<p class="p-7" style="%1$s">'],
'adjacent of universal => 2nd of many' => ['* + p { %1$s }', '<p class="p-2" style="%1$s">'],
'adjacent of universal => last of many' => ['* + p { %1$s }', '<p class="p-7" style="%1$s">'],
// broken: child universal => direct child
// broken: child of universal => direct child
'descendent universal => child' => ['p * { %1$s }', '<span style="%1$s">'],
'descendent universal => grandchild' => ['body * { %1$s }', '<span style="%1$s">'],
// broken: descandant of universal => child
// broken: descandant of universal => grandchild
'descendent attribute presence => with attribute' => [
'body [title] { %1$s }',
'<span title="bonjour" style="%1$s">',
Expand Down Expand Up @@ -625,6 +637,12 @@ public function nonMatchedCssDataProvider()
'child => not parent' => ['span > html { %1$s }', '<html>'],
'descendant => not sibling' => ['span span { %1$s }', '<span>'],
'descendant => not parent' => ['p body { %1$s }', '<body>'],
'adjacent universal => not 1st of many' => ['p + * { %1$s }', '<p class="p-1">'],
'adjacent universal => not last of many' => ['.p-2 + * { %1$s }', '<p class="p-7">'],
'adjacent universal => not previous of many' => ['.p-2 + * { %1$s }', '<p class="p-1">'],
'adjacent of universal => not 1st of many' => ['* + p { %1$s }', '<p class="p-1">'],
'descendent universal => not parent' => ['p *', '<body>'],
'descendent universal => not self' => ['p *', '<p class="p-1">'],
'descendent type & attribute value with ^ => not element with only substring match in attribute value' => [
'p span[title^=njo] { %1$s }',
'<span title="bonjour">',
Expand Down
18 changes: 18 additions & 0 deletions tests/Unit/EmogrifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ public function matchedCssDataProvider()
'ID => with ID' => ['#p4 { %1$s }', '<p class="p-4" id="p4" style="%1$s">'],
'type & ID => type with ID' => ['p#p4 { %1$s }', '<p class="p-4" id="p4" style="%1$s">'],
'universal => HTML' => ['* { %1$s }', '<html style="%1$s">'],
'universal => element with parent and children' => ['* { %1$s }', '<p class="p-1" style="%1$s">'],
'universal => leaf element' => ['* { %1$s }', '<span style="%1$s">'],
'attribute presence => with attribute' => ['[title] { %1$s }', '<span title="bonjour" style="%1$s">'],
'attribute exact value, double quotes => with exact attribute match' => [
'[title="bonjour"] { %1$s }',
Expand Down Expand Up @@ -659,6 +661,16 @@ public function matchedCssDataProvider()
'child (without space before or after >) => direct child' => ['p>span { %1$s }', '<span style="%1$s">'],
'descendant => child' => ['p span { %1$s }', '<span style="%1$s">'],
'descendant => grandchild' => ['body span { %1$s }', '<span style="%1$s">'],
'adjacent universal => 2nd of many' => ['p + * { %1$s }', '<p class="p-2" style="%1$s">'],
'adjacent universal => last of many' => ['p + * { %1$s }', '<p class="p-7" style="%1$s">'],
'adjacent of universal => 2nd of many' => ['* + p { %1$s }', '<p class="p-2" style="%1$s">'],
'adjacent of universal => last of many' => ['* + p { %1$s }', '<p class="p-7" style="%1$s">'],
// broken: child universal => direct child
// broken: child of universal => direct child
'descendent universal => child' => ['p * { %1$s }', '<span style="%1$s">'],
'descendent universal => grandchild' => ['body * { %1$s }', '<span style="%1$s">'],
// broken: descandant of universal => child
// broken: descandant of universal => grandchild
// broken: descendent attribute presence => with attribute
// broken: descendent attribute exact value => with exact attribute match
// broken: descendent type & attribute presence => with type & attribute
Expand Down Expand Up @@ -833,6 +845,12 @@ public function nonMatchedCssDataProvider()
'child => not parent' => ['span > html { %1$s }', '<html>'],
'descendant => not sibling' => ['span span { %1$s }', '<span>'],
'descendant => not parent' => ['p body { %1$s }', '<body>'],
'adjacent universal => not 1st of many' => ['p + * { %1$s }', '<p class="p-1">'],
'adjacent universal => not last of many' => ['.p-2 + * { %1$s }', '<p class="p-7">'],
'adjacent universal => not previous of many' => ['.p-2 + * { %1$s }', '<p class="p-1">'],
'adjacent of universal => not 1st of many' => ['* + p { %1$s }', '<p class="p-1">'],
'descendent universal => not parent' => ['p *', '<body>'],
'descendent universal => not self' => ['p *', '<p class="p-1">'],
'descendent type & attribute value with ^ => not element with only substring match in attribute value' => [
'p span[title^=njo] { %1$s }',
'<span title="bonjour">',
Expand Down