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 :nth-last-child #750

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 `:nth-last-child`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking about it, it's not just tests being added. These are new features by virtue of the Symfony CssSelector component. So these last 3 CHANGELOG entries should in fact read “Support and test …”. I can change that in a separate PR.

([#747](https://github.com/MyIntervals/emogrifier/issues/747),
[#750](https://github.com/MyIntervals/emogrifier/pull/750))
- Test general sibling combinator
([#723](https://github.com/MyIntervals/emogrifier/issues/723),
[#745](https://github.com/MyIntervals/emogrifier/pull/745))
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ Emogrifier currently supports the following
* [first-child](https://developer.mozilla.org/en-US/docs/Web/CSS/:first-child)
* [last-child](https://developer.mozilla.org/en-US/docs/Web/CSS/:last-child)
* [not()](https://developer.mozilla.org/en-US/docs/Web/CSS/:not)
* [nth-child](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child)
* [nth-of-type](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-of-type)
* [nth-child()](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child)
* [nth-last-child()](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-last-child)
* [nth-of-type()](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-of-type)
(with a type, e.g. `p:nth-of-type(2n)` but not `*:nth-of-type(2n)` which
will behave as `*:nth-child(2n)`)

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 = '[\\w\\-]+\\-(?:child|type\\()|not\\([[:ascii:]]*\\)';
const PSEUDO_CLASS_MATCHER = '(?:first|last|nth|only)-child|nth(?:-last)?+-of-type|not\\([[:ascii:]]*\\)';

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

/**
* @var bool[]
Expand Down
67 changes: 67 additions & 0 deletions tests/Unit/CssInlinerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,46 @@ public function matchedCssDataProvider()
':nth-child(-n+3) => 2nd of many' => [':nth-child(-n+3) { %1$s }', '<p class="p-2" style="%1$s">'],
':nth-child(-n+3) => 3rd of many' => [':nth-child(-n+3) { %1$s }', '<div class="div-3" style="%1$s">'],
'type & :nth-child(even) => 2nd of many' => ['p:nth-child(even) { %1$s }', '<p class="p-2" style="%1$s">'],
':nth-last-child(even) => 2nd last of many' => [
':nth-last-child(even) { %1$s }',
'<p class="p-6" style="%1$s">',
],
':nth-last-child(even) => 4th last of many' => [
':nth-last-child(even) { %1$s }',
'<p class="p-4" id="p4" style="%1$s">',
],
':nth-last-child(2n) => 2nd last of many' => [
':nth-last-child(2n) { %1$s }',
'<p class="p-6" style="%1$s">',
],
':nth-last-child(2n) => 4th last of many' => [
':nth-last-child(2n) { %1$s }',
'<p class="p-4" id="p4" style="%1$s">',
],
':nth-last-child(3) => 3rd last of many' => [
':nth-last-child(3) { %1$s }',
'<p class="p-5 additional-class" style="%1$s">',
],
':nth-last-child(2n+3) => 3rd last of many' => [
':nth-last-child(2n+3) { %1$s }',
'<p class="p-5 additional-class" style="%1$s">',
],
':nth-last-child(2n+3) => 5th last of many' => [
':nth-last-child(2n+3) { %1$s }',
'<div class="div-3" style="%1$s">',
],
':nth-last-child(-n+3) => 2nd last of many' => [
':nth-last-child(-n+3) { %1$s }',
'<p class="p-6" style="%1$s">',
],
':nth-last-child(-n+3) => 3rd last of many' => [
':nth-last-child(-n+3) { %1$s }',
'<p class="p-5 additional-class" style="%1$s">',
],
'type & :nth-last-child(even) => 2nd last of many' => [
'p:nth-last-child(even) { %1$s }',
'<p class="p-6" style="%1$s">',
],
// broken: nth-of-type without preceding type
'type & :nth-of-type(even) => 2nd of many of type' => [
'p:nth-of-type(even) { %1$s }',
Expand Down Expand Up @@ -734,6 +774,33 @@ public function nonMatchedCssDataProvider()
':nth-child(2n+3) => not 4th of many' => [':nth-child(2n+3) { %1$s }', '<p class="p-4" id="p4">'],
':nth-child(-n+3) => not 4th of many' => [':nth-child(-n+3) { %1$s }', '<p class="p-4" id="p4">'],
':nth-child(-n+3) => not 5th of many' => [':nth-child(-n+3) { %1$s }', '<p class="p-5 additional-class">'],
':nth-last-child(even) => not last of many' => [':nth-last-child(even) { %1$s }', '<p class="p-7">'],
':nth-last-child(even) => not 3rd last of many' => [
':nth-last-child(even) { %1$s }',
'<p class="p-5 additional-class">',
],
':nth-last-child(2n) => not last of many' => [':nth-last-child(2n) { %1$s }', '<p class="p-7">'],
':nth-last-child(2n) => not 3rd last of many' => [
':nth-last-child(2n) { %1$s }',
'<p class="p-5 additional-class">',
],
':nth-last-child(3) => not last of many' => [':nth-last-child(3) { %1$s }', '<p class="p-7">'],
':nth-last-child(3) => not 2nd last of many' => [':nth-last-child(3) { %1$s }', '<p class="p-6">'],
':nth-last-child(3) => not 4th last of many' => [':nth-last-child(3) { %1$s }', '<p class="p-4" id="p4">'],
':nth-last-child(3) => not 6th last of many' => [':nth-last-child(3) { %1$s }', '<p class="p-2">'],
':nth-last-child(2n+3) => not last of many' => [':nth-last-child(2n+3) { %1$s }', '<p class="p-7">'],
':nth-last-child(2n+3) => not 4th last of many' => [
':nth-last-child(2n+3) { %1$s }',
'<p class="p-4" id="p4">',
],
':nth-last-child(-n+3) => not 4th last of many' => [
':nth-last-child(-n+3) { %1$s }',
'<p class="p-4" id="p4">',
],
':nth-last-child(-n+3) => not 5th last of many' => [
':nth-last-child(-n+3) { %1$s }',
'<div class="div-3">',
],
'type & :nth-of-type(even) => not 1st of many of type' => [
'p:nth-of-type(even) { %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 @@ -739,6 +739,7 @@ public function matchedCssDataProvider()
':nth-child(3) => 3rd of many' => ['*:nth-child(3) { %1$s }', '<div class="div-3" style="%1$s">'],
// broken: nth-child(Xn+Y)
'type & :nth-child(even) => 2nd of many' => ['p:nth-child(even) { %1$s }', '<p class="p-2" style="%1$s">'],
// broken: nth-last-child
// broken: nth-of-type without preceding type
'type & :nth-of-type(even) => 2nd of many of type' => [
'p:nth-of-type(even) { %1$s }',
Expand Down