-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
267 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace markhuot\craftpest\behaviors; | ||
|
||
use craft\elements\db\ElementQuery; | ||
use craft\elements\db\EntryQuery; | ||
use craft\elements\db\MatrixBlockQuery; | ||
use craft\elements\ElementCollection; | ||
use craft\elements\Entry; | ||
use craft\fields\Entries; | ||
use craft\fields\Matrix; | ||
use yii\base\Behavior; | ||
|
||
class SnapshotableBehavior extends Behavior | ||
{ | ||
public function toSnapshot() | ||
{ | ||
return collect($this->owner->toArray()) | ||
->except([ | ||
'id', 'postDate', 'sectionId', 'uid', 'siteSettingsId', | ||
'fieldLayoutId', 'contentId', 'dateCreated', 'dateUpdated', | ||
'canonicalId', 'typeId', | ||
]) | ||
|
||
// filter out any non-eager loaded queries because we can't snapshot on them, their | ||
// values change too often between runs | ||
->filter(fn ($value, $handle) => ! ($this->owner->{$handle} instanceof ElementQuery)) | ||
|
||
// Remap any element collections (eager loaded relations) to their nested snapshots | ||
->map(function ($value, $handle) { | ||
if ($this->owner->{$handle} instanceof ElementCollection) { | ||
return $this->owner->{$handle}->map->toSnapshot(); | ||
} | ||
|
||
return $value; | ||
}) | ||
->all(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/.pest/snapshots/SnapshotTest/it_asserts_dom_snapshots.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[ | ||
"<ul>\n <li>one<\/li>\n <li>two<\/li>\n <li>three<\/li>\n <\/ul>", | ||
"<ul>\n <li>one<\/li>\n <li>two<\/li>\n <li>three<\/li>\n <\/ul>" | ||
] |
16 changes: 16 additions & 0 deletions
16
tests/.pest/snapshots/SnapshotTest/it_asserts_html_snapshots.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<h1>heading text</h1> | ||
<p class="paragraph-element">inner html</p> | ||
<div id="first"> | ||
<ul> | ||
<li>one</li> | ||
<li>two</li> | ||
<li>three</li> | ||
</ul> | ||
</div> | ||
<div id="second"> | ||
<ul> | ||
<li>one</li> | ||
<li>two</li> | ||
<li>three</li> | ||
</ul> | ||
</div> |
3 changes: 3 additions & 0 deletions
3
tests/.pest/snapshots/SnapshotTest/it_asserts_view_dom_snapshots.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
"<h1>heading text<\/h1>" | ||
] |
16 changes: 16 additions & 0 deletions
16
tests/.pest/snapshots/SnapshotTest/it_asserts_view_snapshots.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<h1>heading text</h1> | ||
<p class="paragraph-element">inner html</p> | ||
<div id="first"> | ||
<ul> | ||
<li>one</li> | ||
<li>two</li> | ||
<li>three</li> | ||
</ul> | ||
</div> | ||
<div id="second"> | ||
<ul> | ||
<li>one</li> | ||
<li>two</li> | ||
<li>three</li> | ||
</ul> | ||
</div> |
4 changes: 4 additions & 0 deletions
4
tests/.pest/snapshots/SnapshotTest/it_expects_dom_snapshots.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[ | ||
"<ul>\n <li>one<\/li>\n <li>two<\/li>\n <li>three<\/li>\n <\/ul>", | ||
"<ul>\n <li>one<\/li>\n <li>two<\/li>\n <li>three<\/li>\n <\/ul>" | ||
] |
16 changes: 16 additions & 0 deletions
16
tests/.pest/snapshots/SnapshotTest/it_expects_html_snapshots.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<h1>heading text</h1> | ||
<p class="paragraph-element">inner html</p> | ||
<div id="first"> | ||
<ul> | ||
<li>one</li> | ||
<li>two</li> | ||
<li>three</li> | ||
</ul> | ||
</div> | ||
<div id="second"> | ||
<ul> | ||
<li>one</li> | ||
<li>two</li> | ||
<li>three</li> | ||
</ul> | ||
</div> |
27 changes: 27 additions & 0 deletions
27
tests/.pest/snapshots/SnapshotTest/it_matches_entry_snapshots.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"expiryDate": null, | ||
"deletedWithEntryType": false, | ||
"_authorId": null, | ||
"tempId": null, | ||
"draftId": null, | ||
"revisionId": null, | ||
"isProvisionalDraft": false, | ||
"enabled": true, | ||
"archived": false, | ||
"siteId": 2, | ||
"title": "foo bar", | ||
"slug": "foo-bar", | ||
"uri": "posts\/foo-bar", | ||
"dateLastMerged": null, | ||
"dateDeleted": null, | ||
"trashed": false, | ||
"isNewForSite": true, | ||
"isDraft": false, | ||
"isRevision": false, | ||
"isUnpublishedDraft": false, | ||
"ref": "posts\/foo-bar", | ||
"status": "live", | ||
"structureId": null, | ||
"url": "http:\/\/localhost:8080\/posts\/foo-bar", | ||
"authorId": null | ||
} |
56 changes: 56 additions & 0 deletions
56
tests/.pest/snapshots/SnapshotTest/it_matches_nested_entry_snapshots.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"expiryDate": null, | ||
"deletedWithEntryType": false, | ||
"_authorId": null, | ||
"tempId": null, | ||
"draftId": null, | ||
"revisionId": null, | ||
"isProvisionalDraft": false, | ||
"enabled": true, | ||
"archived": false, | ||
"siteId": 2, | ||
"title": "foo bar", | ||
"slug": "foo-bar", | ||
"uri": "posts\/foo-bar", | ||
"dateLastMerged": null, | ||
"dateDeleted": null, | ||
"trashed": false, | ||
"isNewForSite": false, | ||
"isDraft": false, | ||
"isRevision": false, | ||
"isUnpublishedDraft": false, | ||
"ref": "posts\/foo-bar", | ||
"status": "live", | ||
"structureId": null, | ||
"url": "http:\/\/localhost:8080\/posts\/foo-bar", | ||
"authorId": null, | ||
"entriesField": [ | ||
{ | ||
"expiryDate": null, | ||
"deletedWithEntryType": false, | ||
"_authorId": null, | ||
"tempId": null, | ||
"draftId": null, | ||
"revisionId": null, | ||
"isProvisionalDraft": false, | ||
"enabled": true, | ||
"archived": false, | ||
"siteId": 2, | ||
"title": "child", | ||
"slug": "child", | ||
"uri": "posts\/child", | ||
"dateLastMerged": null, | ||
"dateDeleted": null, | ||
"trashed": false, | ||
"isNewForSite": false, | ||
"isDraft": false, | ||
"isRevision": false, | ||
"isUnpublishedDraft": false, | ||
"ref": "posts\/child", | ||
"status": "live", | ||
"structureId": null, | ||
"url": "http:\/\/localhost:8080\/posts\/child", | ||
"authorId": null | ||
} | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
tests/.pest/snapshots/SnapshotTest/it_renders_views_with_variables.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ foo }} |