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 :only-child #754

Merged
merged 1 commit into from
Sep 30, 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
[TASK] Test :only-child
And updated README to indicate it is supported.

Also removed ‘support’ for `:only-child` from `Emogrifier` class by adjusting
the `PSEUDO_CLASS_MATCHER` regex, so that rules with such selectors will be
copied to a `<style>` element.  (It is not supported in that class.)

Closes #747.
  • Loading branch information
JakeQZ committed Sep 30, 2019
commit 141f40e00eab6062069ac42b86c5b4546bdcc334
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
- Support and test `:only-child`
([#747](https://github.com/MyIntervals/emogrifier/issues/747),
[#754](https://github.com/MyIntervals/emogrifier/pull/754))
- Support and test `:nth-last-of-type`
([#747](https://github.com/MyIntervals/emogrifier/issues/747),
[#751](https://github.com/MyIntervals/emogrifier/pull/751))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ Emogrifier currently supports the following
`*:nth-last-of-type(2n)` which will behave as `*:nth-last-child(2n)`)
* [nth-of-type()](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-of-type)
(with a type)
* [only-child](https://developer.mozilla.org/en-US/docs/Web/CSS/:only-child)

The following selectors are not implemented yet:

Expand Down
2 changes: 1 addition & 1 deletion src/Emogrifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Emogrifier
*
* @var string
*/
const PSEUDO_CLASS_MATCHER = '(?:first|last|nth|only)-child|nth-of-type|not\\([[:ascii:]]*\\)';
const PSEUDO_CLASS_MATCHER = '(?:first|last|nth)-child|nth-of-type|not\\([[:ascii:]]*\\)';

/**
* @var string
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/CssInlinerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,12 @@ public function matchedCssDataProvider()
'body > :last-child { %1$s }',
'<p class="p-7" style="%1$s">',
],
':only-child => element without siblings' => [':only-child { %1$s }', '<span style="%1$s">'],
'type & :only-child => element without siblings' => ['span:only-child { %1$s }', '<span style="%1$s">'],
'child combinator & :only-child => element without siblings' => [
'p > :only-child { %1$s }',
'<span style="%1$s">',
],
':nth-child(even) => 2nd of many' => [':nth-child(even) { %1$s }', '<p class="p-2" style="%1$s">'],
':nth-child(even) => 4th of many' => [':nth-child(even) { %1$s }', '<p class="p-4" id="p4" style="%1$s">'],
':nth-child(2n) => 2nd of many' => [':nth-child(2n) { %1$s }', '<p class="p-2" style="%1$s">'],
Expand Down Expand Up @@ -799,6 +805,12 @@ public function nonMatchedCssDataProvider()
'type & :last-child => not 2nd of many' => ['p:last-child { %1$s }', '<p class="p-2">'],
'child combinator & :last-child => not 1st of many' => ['body > :last-child { %1$s }', '<p class="p-1">'],
'child combinator & :last-child => not 2nd of many' => ['body > :last-child { %1$s }', '<p class="p-2">'],
':only-child => not element with siblings' => [':only-child { %1$s }', '<p class="p-1">'],
'type & :only-child => not element with siblings' => ['p:only-child { %1$s }', '<p class="p-1">'],
'child combinator & :only-child => not element with siblings' => [
'body > :only-child { %1$s }',
'<p class="p-1">',
],
':nth-child(even) => not 1st of many' => [':nth-child(even) { %1$s }', '<p class="p-1">'],
':nth-child(even) => not 3rd of many' => [':nth-child(even) { %1$s }', '<div class="div-3">'],
':nth-child(2n) => not 1st of many' => [':nth-child(2n) { %1$s }', '<p class="p-1">'],
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/EmogrifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ public function matchedCssDataProvider()
'type & :first-child => 1st of many' => ['p:first-child { %1$s }', '<p class="p-1" style="%1$s">'],
// broken: last-child => last of many
'type & :last-child => last of many' => ['p:last-child { %1$s }', '<p class="p-7" style="%1$s">'],
// broken: only-child
// broken: nth-child without preceding component - OK if preceded by universal selector
':nth-child(even) => 2nd of many' => ['*:nth-child(even) { %1$s }', '<p class="p-2" style="%1$s">'],
':nth-child(even) => 4th of many' => ['*:nth-child(even) { %1$s }', '<p class="p-4" id="p4" style="%1$s">'],
Expand Down