@amazeelabs/silverback-gatsby 3.7.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/drupal/silverback_gatsby/.prettierignore +1 -0
  3. package/drupal/silverback_gatsby/CHANGELOG.md +1216 -0
  4. package/drupal/silverback_gatsby/README.md +297 -0
  5. package/drupal/silverback_gatsby/composer.json +15 -0
  6. package/drupal/silverback_gatsby/directives.gql +63 -0
  7. package/drupal/silverback_gatsby/directives.graphql +62 -0
  8. package/drupal/silverback_gatsby/drush.services.yml +9 -0
  9. package/drupal/silverback_gatsby/graphql/entity.directive.graphqls +2 -0
  10. package/drupal/silverback_gatsby/graphql/menu.directive.graphqls +17 -0
  11. package/drupal/silverback_gatsby/graphql/silverback_gatsby.base.graphqls +25 -0
  12. package/drupal/silverback_gatsby/graphql/silverback_gatsby.extension.graphqls +10 -0
  13. package/drupal/silverback_gatsby/graphql/stringTranslation.directive.graphqls +4 -0
  14. package/drupal/silverback_gatsby/graphql/translatableString.directive.graphqls +2 -0
  15. package/drupal/silverback_gatsby/modules/silverback_gatsby_example/directives.gql +6 -0
  16. package/drupal/silverback_gatsby/modules/silverback_gatsby_example/graphql/.graphqlrc.json +4 -0
  17. package/drupal/silverback_gatsby/modules/silverback_gatsby_example/graphql/silverback_gatsby_example.graphqls +39 -0
  18. package/drupal/silverback_gatsby/modules/silverback_gatsby_example/silverback_gatsby_example.info.yml +7 -0
  19. package/drupal/silverback_gatsby/modules/silverback_gatsby_example/silverback_gatsby_example.module +16 -0
  20. package/drupal/silverback_gatsby/modules/silverback_gatsby_example/src/Directives.php +24 -0
  21. package/drupal/silverback_gatsby/silverback_gatsby.info.yml +8 -0
  22. package/drupal/silverback_gatsby/silverback_gatsby.install +180 -0
  23. package/drupal/silverback_gatsby/silverback_gatsby.links.task.yml +6 -0
  24. package/drupal/silverback_gatsby/silverback_gatsby.module +119 -0
  25. package/drupal/silverback_gatsby/silverback_gatsby.permissions.yml +8 -0
  26. package/drupal/silverback_gatsby/silverback_gatsby.post_update.php +15 -0
  27. package/drupal/silverback_gatsby/silverback_gatsby.routing.yml +28 -0
  28. package/drupal/silverback_gatsby/silverback_gatsby.services.yml +50 -0
  29. package/drupal/silverback_gatsby/src/Annotation/GatsbyFeed.php +41 -0
  30. package/drupal/silverback_gatsby/src/Commands/SilverbackGatsbyCommands.php +102 -0
  31. package/drupal/silverback_gatsby/src/Controller/BuildController.php +45 -0
  32. package/drupal/silverback_gatsby/src/Controller/PublisherController.php +34 -0
  33. package/drupal/silverback_gatsby/src/Directives.php +51 -0
  34. package/drupal/silverback_gatsby/src/GatsbyBuildTrigger.php +230 -0
  35. package/drupal/silverback_gatsby/src/GatsbyBuildTriggerInterface.php +52 -0
  36. package/drupal/silverback_gatsby/src/GatsbyUpdate.php +38 -0
  37. package/drupal/silverback_gatsby/src/GatsbyUpdateHandler.php +181 -0
  38. package/drupal/silverback_gatsby/src/GatsbyUpdateTracker.php +98 -0
  39. package/drupal/silverback_gatsby/src/GatsbyUpdateTrackerInterface.php +59 -0
  40. package/drupal/silverback_gatsby/src/GatsbyUpdateTrigger.php +69 -0
  41. package/drupal/silverback_gatsby/src/GatsbyUpdateTriggerInterface.php +22 -0
  42. package/drupal/silverback_gatsby/src/GraphQL/Build.php +235 -0
  43. package/drupal/silverback_gatsby/src/GraphQL/ComposableSchema.php +73 -0
  44. package/drupal/silverback_gatsby/src/LocaleStorageDecorator.php +181 -0
  45. package/drupal/silverback_gatsby/src/MenuTreeStorageDecorator.php +139 -0
  46. package/drupal/silverback_gatsby/src/Plugin/FeedBase.php +121 -0
  47. package/drupal/silverback_gatsby/src/Plugin/FeedInterface.php +132 -0
  48. package/drupal/silverback_gatsby/src/Plugin/FeedPluginManager.php +39 -0
  49. package/drupal/silverback_gatsby/src/Plugin/Gatsby/Feed/EntityFeed.php +252 -0
  50. package/drupal/silverback_gatsby/src/Plugin/Gatsby/Feed/MenuFeed.php +292 -0
  51. package/drupal/silverback_gatsby/src/Plugin/Gatsby/Feed/StringTranslationFeed.php +171 -0
  52. package/drupal/silverback_gatsby/src/Plugin/Gatsby/Feed/TranslatableStringFeed.php +128 -0
  53. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/CurrentUserEntity.php +43 -0
  54. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/EntityQueryBase.php +40 -0
  55. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/FetchEntity.php +371 -0
  56. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/FetchString.php +64 -0
  57. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/FetchTranslatableString.php +74 -0
  58. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/FocalPoint.php +47 -0
  59. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/GatsbyBuildId.php +36 -0
  60. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/GatsbyExtractId.php +28 -0
  61. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/GatsbyExtractLangcode.php +28 -0
  62. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/ImageProps.php +149 -0
  63. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/ListEntities.php +88 -0
  64. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/ListStrings.php +87 -0
  65. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/StringId.php +37 -0
  66. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/StringTranslations.php +94 -0
  67. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/EntityFetch.php +51 -0
  68. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/EntityTranslationsWithDefault.php +30 -0
  69. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/FocalPoint.php +27 -0
  70. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/ImageProps.php +27 -0
  71. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/MenuLangcode.php +27 -0
  72. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/MenuTranslations.php +36 -0
  73. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/SilverbackGatsbyEntityId.php +39 -0
  74. package/drupal/silverback_gatsby/src/Plugin/GraphQL/SchemaExtension/SilverbackGatsbySchemaExtension.php +384 -0
  75. package/drupal/silverback_gatsby/src/SilverbackGatsbyServiceProvider.php +43 -0
  76. package/drupal/silverback_gatsby/src/SilverbackGatsbySessionConfiguration.php +30 -0
  77. package/drupal/silverback_gatsby/src/SilverbackReverseProxyMiddleware.php +49 -0
  78. package/drupal/silverback_gatsby/tests/queries/create-page-fields.gql +12 -0
  79. package/drupal/silverback_gatsby/tests/queries/current-user.gql +6 -0
  80. package/drupal/silverback_gatsby/tests/queries/feed_info.gql +12 -0
  81. package/drupal/silverback_gatsby/tests/queries/load-entity.gql +5 -0
  82. package/drupal/silverback_gatsby/tests/queries/menus.gql +31 -0
  83. package/drupal/silverback_gatsby/tests/queries/multilingual-menus.gql +11 -0
  84. package/drupal/silverback_gatsby/tests/queries/revisionable-translatable.gql +15 -0
  85. package/drupal/silverback_gatsby/tests/queries/revisionable.gql +8 -0
  86. package/drupal/silverback_gatsby/tests/queries/translatable.gql +14 -0
  87. package/drupal/silverback_gatsby/tests/queries/untranslatable.gql +10 -0
  88. package/drupal/silverback_gatsby/tests/schema/.graphqlrc.json +4 -0
  89. package/drupal/silverback_gatsby/tests/schema/translatable-strings.graphql +7 -0
  90. package/drupal/silverback_gatsby/tests/src/Kernel/CurrentUserTest.php +37 -0
  91. package/drupal/silverback_gatsby/tests/src/Kernel/EntityFeedTest.php +490 -0
  92. package/drupal/silverback_gatsby/tests/src/Kernel/EntityFeedTestBase.php +178 -0
  93. package/drupal/silverback_gatsby/tests/src/Kernel/GatsbyBuildTriggerTest.php +155 -0
  94. package/drupal/silverback_gatsby/tests/src/Kernel/GatsbyFeedInfoTest.php +319 -0
  95. package/drupal/silverback_gatsby/tests/src/Kernel/GatsbyUpdateHandlerTest.php +131 -0
  96. package/drupal/silverback_gatsby/tests/src/Kernel/GatsbyUpdateTrackerTest.php +196 -0
  97. package/drupal/silverback_gatsby/tests/src/Kernel/GatsbyUpdateTriggerTest.php +177 -0
  98. package/drupal/silverback_gatsby/tests/src/Kernel/MenuFeedTest.php +192 -0
  99. package/drupal/silverback_gatsby/tests/src/Kernel/TranslatableStringFeedTest.php +210 -0
  100. package/drupal/silverback_gatsby/tests/src/Traits/NotificationCheckTrait.php +43 -0
  101. package/package.json +15 -0
@@ -0,0 +1,155 @@
1
+ <?php
2
+
3
+ namespace Drupal\Tests\silverback_gatsby\Kernel;
4
+
5
+ use Drupal\Core\Messenger\MessengerInterface;
6
+ use Drupal\graphql\Entity\Server;
7
+ use Drupal\KernelTests\KernelTestBase;
8
+ use Drupal\Tests\silverback_gatsby\Traits\NotificationCheckTrait;
9
+ use GuzzleHttp\Exception\RequestException;
10
+ use GuzzleHttp\Psr7\Request;
11
+ use Prophecy\Argument;
12
+
13
+ /**
14
+ *
15
+ */
16
+ class GatsbyBuildTriggerTest extends KernelTestBase {
17
+ use NotificationCheckTrait;
18
+
19
+ protected $strictConfigSchema = FALSE;
20
+
21
+ /**
22
+ * @var string[]
23
+ */
24
+ protected static $modules = [
25
+ 'language',
26
+ 'user',
27
+ 'node',
28
+ 'graphql',
29
+ 'file',
30
+ 'content_translation',
31
+ 'graphql_directives',
32
+ 'silverback_gatsby',
33
+ 'silverback_gatsby_example',
34
+ 'menu_link_content',
35
+ 'path_alias',
36
+ ];
37
+
38
+ /**
39
+ * @var \Prophecy\Prophecy\ObjectProphecy
40
+ */
41
+ protected $messengerProphecy;
42
+
43
+ /**
44
+ * @var \Drupal\silverback_gatsby\GatsbyBuildTrigger
45
+ */
46
+ protected $trigger;
47
+
48
+ /**
49
+ * {@inheritdoc}
50
+ */
51
+ protected function setUp() : void {
52
+ parent::setUp();
53
+ $this->setupClientProphecy();
54
+ $this->messengerProphecy = $this->prophesize(MessengerInterface::class);
55
+ $this->container->set('messenger', $this->messengerProphecy->reveal());
56
+
57
+ $this->installConfig('graphql');
58
+ $this->installConfig('graphql_directives');
59
+ $this->installSchema('silverback_gatsby', ['gatsby_update_log']);
60
+
61
+ $this->trigger = $this->container->get('silverback_gatsby.build_trigger');
62
+
63
+ $schemaDefinition = \Drupal::moduleHandler()->getModule('silverback_gatsby')->getPath()
64
+ . '/modules/silverback_gatsby_example/graphql/silverback_gatsby_example.graphqls';
65
+
66
+ Server::create([
67
+ 'schema' => 'directable',
68
+ 'name' => 'foo',
69
+ 'endpoint' => '/foo',
70
+ 'schema_configuration' => [
71
+ 'directable' => [
72
+ 'extensions' => [
73
+ 'silverback_gatsby' => 'silverback_gatsby',
74
+ ],
75
+ 'schema_definition' => $schemaDefinition,
76
+ 'autoload_contexts' => 'drupal',
77
+ 'build_webhook' => 'http://localhost:8000/__refresh',
78
+ ],
79
+ ],
80
+ ])->save();
81
+
82
+ Server::create([
83
+ 'schema' => 'directable',
84
+ 'name' => 'bar',
85
+ 'endpoint' => '/bar',
86
+ 'schema_configuration' => [
87
+ 'directable' => [
88
+ 'extensions' => [
89
+ 'silverback_gatsby' => 'silverback_gatsby',
90
+ ],
91
+ 'schema_definition' => $schemaDefinition,
92
+ 'autoload_contexts' => 'drupal',
93
+ 'build_webhook' => 'http://localhost:9000/__refresh',
94
+ ],
95
+ ],
96
+ ])->save();
97
+
98
+ }
99
+
100
+ /**
101
+ *
102
+ */
103
+ public function testBeforeShutdown() {
104
+ $this->trigger->trigger('foo', 1);
105
+ // If _drupal_shutdown_function() is not called, no notifications go out.
106
+ $this->checkTotalNotifications(0);
107
+ }
108
+
109
+ /**
110
+ *
111
+ */
112
+ public function testRequestException() {
113
+ $this->clientProphecy->post(Argument::any(), Argument::any())
114
+ ->willThrow(new RequestException('Invalid!', new Request('post', 'http://localhost:8000/__refresh')));
115
+ $this->trigger->trigger('foo', 1);
116
+ _drupal_shutdown_function();
117
+ $this->messengerProphecy->addError(Argument::any())->shouldHaveBeenCalledTimes(2);
118
+ $this->messengerProphecy->addError('Invalid!')->shouldHaveBeenCalledTimes(1);
119
+ $this->messengerProphecy->addError('Could not send build notification to server "http://localhost:8000/__refresh".')->shouldHaveBeenCalledTimes(1);
120
+ }
121
+
122
+ /**
123
+ *
124
+ */
125
+ public function testSingleTrigger() {
126
+ $this->trigger->trigger('foo', 1);
127
+ _drupal_shutdown_function();
128
+ $this->checkTotalNotifications(1);
129
+ $this->checkBuildNotification('http://localhost:8000/__refresh', 1);
130
+ }
131
+
132
+ /**
133
+ *
134
+ */
135
+ public function testMultipleTriggers() {
136
+ $this->trigger->trigger('foo', 1);
137
+ $this->trigger->trigger('foo', 2);
138
+ _drupal_shutdown_function();
139
+ $this->checkTotalNotifications(1);
140
+ $this->checkBuildNotification('http://localhost:8000/__refresh', 2);
141
+ }
142
+
143
+ /**
144
+ *
145
+ */
146
+ public function testMultipleServers() {
147
+ $this->trigger->trigger('foo', 1);
148
+ $this->trigger->trigger('bar', 2);
149
+ _drupal_shutdown_function();
150
+ $this->checkTotalNotifications(2);
151
+ $this->checkBuildNotification('http://localhost:8000/__refresh', 1);
152
+ $this->checkBuildNotification('http://localhost:9000/__refresh', 2);
153
+ }
154
+
155
+ }
@@ -0,0 +1,319 @@
1
+ <?php
2
+
3
+ namespace Drupal\Tests\silverback_gatsby\Kernel;
4
+
5
+ use Drupal\node\Entity\Node;
6
+
7
+ /**
8
+ *
9
+ */
10
+ class GatsbyFeedInfoTest extends EntityFeedTestBase {
11
+
12
+ /**
13
+ *
14
+ */
15
+ protected function expectedFeedInfo($changes = []) {
16
+ return [
17
+ [
18
+ 'typeName' => 'Page',
19
+ 'translatable' => TRUE,
20
+ 'singleFieldName' => '_loadPage',
21
+ 'listFieldName' => '_queryPages',
22
+ 'changes' => $changes['Page'] ?? [],
23
+ 'pathFieldName' => 'path',
24
+ 'templateFieldName' => NULL,
25
+
26
+ ],
27
+ [
28
+ 'typeName' => 'Post',
29
+ 'translatable' => FALSE,
30
+ 'singleFieldName' => '_loadPost',
31
+ 'listFieldName' => '_queryPosts',
32
+ 'changes' => $changes['Post'] ?? [],
33
+ 'pathFieldName' => 'path',
34
+ 'templateFieldName' => 'template',
35
+ ],
36
+ [
37
+ 'typeName' => 'MainMenu',
38
+ 'translatable' => FALSE,
39
+ 'singleFieldName' => '_loadMainMenu',
40
+ 'listFieldName' => '_queryMainMenus',
41
+ 'changes' => $changes['MainMenu'] ?? [],
42
+ 'pathFieldName' => NULL,
43
+ 'templateFieldName' => NULL,
44
+ ],
45
+ [
46
+ 'typeName' => 'VisibleMainMenu',
47
+ 'translatable' => FALSE,
48
+ 'singleFieldName' => '_loadVisibleMainMenu',
49
+ 'listFieldName' => '_queryVisibleMainMenus',
50
+ 'changes' => $changes['VisibleMainMenu'] ?? [],
51
+ 'pathFieldName' => NULL,
52
+ 'templateFieldName' => NULL,
53
+ ],
54
+ ];
55
+ }
56
+
57
+ /**
58
+ *
59
+ */
60
+ public function testInitialFeed() {
61
+ $query = $this->getQueryFromFile('feed_info.gql');
62
+ $this->assertResults($query, [], [
63
+ // When no build happened yet, the build ID is -1.
64
+ '_drupalBuildId' => -1,
65
+ '_drupalFeedInfo' => $this->expectedFeedInfo(),
66
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
67
+ }
68
+
69
+ /**
70
+ *
71
+ */
72
+ public function testInitialBuild() {
73
+ $node = Node::create([
74
+ 'type' => 'page',
75
+ 'title' => 'Test',
76
+ 'status' => 0,
77
+ ]);
78
+ $node->save();
79
+
80
+ $query = $this->getQueryFromFile('feed_info.gql');
81
+ $this->assertResults($query, [], [
82
+ // It should indicate that there has been a first build.
83
+ '_drupalBuildId' => 1,
84
+ '_drupalFeedInfo' => $this->expectedFeedInfo(),
85
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
86
+ }
87
+
88
+ /**
89
+ *
90
+ */
91
+ public function testInitialPublishedBuild() {
92
+ $node = Node::create([
93
+ 'type' => 'page',
94
+ 'title' => 'Test',
95
+ ]);
96
+ $node->save();
97
+
98
+ $this->useBuildServer();
99
+ $query = $this->getQueryFromFile('feed_info.gql');
100
+ $this->assertResults($query, [], [
101
+ // It should indicate that there has been a first build.
102
+ '_drupalBuildId' => 1,
103
+ '_drupalFeedInfo' => $this->expectedFeedInfo(),
104
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
105
+
106
+ $this->usePreviewServer();
107
+ $query = $this->getQueryFromFile('feed_info.gql');
108
+ $this->assertResults($query, [], [
109
+ // It should indicate that there has been a first build.
110
+ '_drupalBuildId' => 2,
111
+ '_drupalFeedInfo' => $this->expectedFeedInfo(),
112
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
113
+
114
+ $this->usePublicServer();
115
+ $query = $this->getQueryFromFile('feed_info.gql');
116
+ $this->assertResults($query, [], [
117
+ // It should indicate that there has been a first build.
118
+ '_drupalBuildId' => -1,
119
+ '_drupalFeedInfo' => $this->expectedFeedInfo(),
120
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
121
+ }
122
+
123
+ /**
124
+ *
125
+ */
126
+ public function testMultipleBuilds() {
127
+ $tracker = $this->container->get('silverback_gatsby.update_tracker');
128
+ $node = Node::create([
129
+ 'type' => 'page',
130
+ 'title' => 'Test',
131
+ 'status' => 0,
132
+ ]);
133
+ $node->save();
134
+ $tracker->clear();
135
+ $node->setTitle('Changed');
136
+ $node->save();
137
+ $tracker->clear();
138
+
139
+ $query = $this->getQueryFromFile('feed_info.gql');
140
+ $this->assertResults($query, [], [
141
+ '_drupalBuildId' => 2,
142
+ '_drupalFeedInfo' => $this->expectedFeedInfo(),
143
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
144
+ }
145
+
146
+ /**
147
+ *
148
+ */
149
+ public function testCurrentBuildArgument() {
150
+ $tracker = $this->container->get('silverback_gatsby.update_tracker');
151
+ $node = Node::create([
152
+ 'type' => 'page',
153
+ 'title' => 'Test',
154
+ 'status' => 0,
155
+ ]);
156
+ $node->save();
157
+ $tracker->clear();
158
+ $node->setTitle('Changed');
159
+ $node->save();
160
+ $tracker->clear();
161
+
162
+ $post = Node::create([
163
+ 'type' => 'blog',
164
+ 'title' => 'Test',
165
+ 'status' => 0,
166
+ ]);
167
+ $post->save();
168
+
169
+ $query = $this->getQueryFromFile('feed_info.gql');
170
+ // All changes since build 1. Edited page and created post.
171
+ $this->assertResults($query, [
172
+ 'lastBuild' => 1,
173
+ 'currentBuild' => 3,
174
+ ], [
175
+ '_drupalBuildId' => 3,
176
+ '_drupalFeedInfo' => $this->expectedFeedInfo([
177
+ 'Page' => [$node->uuid() . ':en'],
178
+ 'Post' => [$post->uuid()],
179
+ ]),
180
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
181
+
182
+ // Only the first change that edited the page.
183
+ $this->assertResults($query, [
184
+ 'lastBuild' => 1,
185
+ 'currentBuild' => 2,
186
+ ], [
187
+ '_drupalBuildId' => 3,
188
+ '_drupalFeedInfo' => $this->expectedFeedInfo([
189
+ 'Page' => [$node->uuid() . ':en'],
190
+ ]),
191
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
192
+
193
+ // Only the last change that created a blog post.
194
+ $this->assertResults($query, [
195
+ 'lastBuild' => 2,
196
+ 'currentBuild' => 3,
197
+ ], [
198
+ '_drupalBuildId' => 3,
199
+ '_drupalFeedInfo' => $this->expectedFeedInfo([
200
+ 'Post' => [$post->uuid()],
201
+ ]),
202
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
203
+ }
204
+
205
+ /**
206
+ *
207
+ */
208
+ public function testNodePublish() {
209
+ $tracker = $this->container->get('silverback_gatsby.update_tracker');
210
+ // Create one initial published node so both build and preview server have
211
+ // a build id we can diff against.
212
+ Node::create([
213
+ 'type' => 'page',
214
+ 'title' => 'Published',
215
+ ])->save();
216
+
217
+ // Create the second node that we are actually going to test.
218
+ $node = Node::create([
219
+ 'type' => 'page',
220
+ 'title' => 'Unpublished',
221
+ 'status' => 0,
222
+ ]);
223
+ $node->save();
224
+
225
+ $tracker->clear();
226
+
227
+ // Preview server should be on build 3 (2 for the initial node on preview
228
+ // & build and 1 for the unpublished node on preview).
229
+ $this->usePreviewServer();
230
+ $query = $this->getQueryFromFile('feed_info.gql');
231
+ $this->assertResults($query, [], [
232
+ // It should indicate that there has been a first build.
233
+ '_drupalBuildId' => 3,
234
+ '_drupalFeedInfo' => $this->expectedFeedInfo(),
235
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
236
+
237
+ // Preview should be on build 1 which is the initial node.
238
+ $this->useBuildServer();
239
+ $query = $this->getQueryFromFile('feed_info.gql');
240
+ $this->assertResults($query, [], [
241
+ // It should indicate that there has been a first build.
242
+ '_drupalBuildId' => 1,
243
+ '_drupalFeedInfo' => $this->expectedFeedInfo(),
244
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
245
+
246
+ // Publish the unpublished node.
247
+ // We have to create a new revision, or we get the last cached access result.
248
+ $node->setTitle('Published');
249
+ $node->setPublished();
250
+ $node->save();
251
+
252
+ // Build server should be on build 5 now. The 3 from before plus 2 builds
253
+ // for preview and build. "2:en" is marked as a change to be fetched.
254
+ $this->useBuildServer();
255
+ $query = $this->getQueryFromFile('feed_info.gql');
256
+ $this->assertResults($query, [
257
+ 'lastBuild' => 1,
258
+ 'currentBuild' => 5,
259
+ ], [
260
+ // It should indicate that there has been a first build.
261
+ '_drupalBuildId' => 5,
262
+ '_drupalFeedInfo' => $this->expectedFeedInfo(['Page' => [$node->uuid() . ':en']]),
263
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
264
+ }
265
+
266
+ /**
267
+ *
268
+ */
269
+ public function testNodeUnpublish() {
270
+ // Create an initial published node.
271
+ $tracker = $this->container->get('silverback_gatsby.update_tracker');
272
+ $node = Node::create([
273
+ 'type' => 'page',
274
+ 'title' => 'Published',
275
+ ]);
276
+ $node->save();
277
+
278
+ $tracker->clear();
279
+
280
+ // Preview server is on build 2. 1 is for the build server.
281
+ $this->usePreviewServer();
282
+ $query = $this->getQueryFromFile('feed_info.gql');
283
+ $this->assertResults($query, [], [
284
+ // It should indicate that there has been a first build.
285
+ '_drupalBuildId' => 2,
286
+ '_drupalFeedInfo' => $this->expectedFeedInfo(),
287
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
288
+
289
+ // The build server is on build 1.
290
+ $this->useBuildServer();
291
+ $query = $this->getQueryFromFile('feed_info.gql');
292
+ $this->assertResults($query, [], [
293
+ // It should indicate that there has been a first build.
294
+ '_drupalBuildId' => 1,
295
+ '_drupalFeedInfo' => $this->expectedFeedInfo(),
296
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
297
+
298
+ // Unpublish the node.
299
+ // We have to create a new revision, or we get the last cached access result.
300
+ $node->setTitle('Unpublished');
301
+ $node->setUnpublished();
302
+ $node->save();
303
+
304
+ // Build server is on build 3, and '1:en' is marked as changed which will
305
+ // effectively delete it from the gatsby store since the fetch will return
306
+ // null.
307
+ $this->useBuildServer();
308
+ $query = $this->getQueryFromFile('feed_info.gql');
309
+ $this->assertResults($query, [
310
+ 'lastBuild' => 1,
311
+ 'currentBuild' => 3,
312
+ ], [
313
+ // It should indicate that there has been a first build.
314
+ '_drupalBuildId' => 3,
315
+ '_drupalFeedInfo' => $this->expectedFeedInfo(['Page' => [$node->uuid() . ':en']]),
316
+ ], $this->defaultCacheMetaData()->mergeCacheMaxAge(0));
317
+ }
318
+
319
+ }
@@ -0,0 +1,131 @@
1
+ <?php
2
+
3
+ namespace Drupal\Tests\silverback_gatsby\Kernel;
4
+
5
+ use Drupal\Core\DependencyInjection\ContainerBuilder;
6
+ use Drupal\node\Entity\Node;
7
+ use Drupal\silverback_gatsby\GatsbyUpdate;
8
+ use Drupal\silverback_gatsby\GatsbyUpdateTrigger;
9
+ use Drupal\Tests\Traits\Core\PathAliasTestTrait;
10
+
11
+ /**
12
+ *
13
+ */
14
+ class GatsbyUpdateHandlerTest extends EntityFeedTestBase {
15
+
16
+ use PathAliasTestTrait;
17
+ protected static $modules = ['path_alias'];
18
+
19
+ /**
20
+ * @var \Drupal\silverback_gatsby\GatsbyUpdateTracker|object|null
21
+ */
22
+ protected $tracker;
23
+
24
+ /**
25
+ * @var \Prophecy\Prophecy\ObjectProphecy
26
+ */
27
+ protected $triggerProphecy;
28
+
29
+ /**
30
+ *
31
+ */
32
+ public function register(ContainerBuilder $container) {
33
+ parent::register($container);
34
+ $this->triggerProphecy = $this->prophesize(GatsbyUpdateTrigger::class);
35
+ $container->set('silverback_gatsby.update_trigger', $this->triggerProphecy->reveal());
36
+ }
37
+
38
+ /**
39
+ * {@inheritdoc}
40
+ */
41
+ protected function setUp() : void {
42
+ parent::setUp();
43
+ $this->installEntitySchema('path_alias');
44
+ $this->tracker = $this->container->get('silverback_gatsby.update_tracker');
45
+ }
46
+
47
+ /**
48
+ *
49
+ */
50
+ public function testLogRelevantChanges() {
51
+ $node = Node::create([
52
+ 'type' => 'page',
53
+ 'title' => 'Test',
54
+ 'status' => 0,
55
+ ]);
56
+ $node->save();
57
+ $this->tracker->clear();
58
+
59
+ $node->addTranslation('de', [
60
+ 'title' => 'Test DE',
61
+ 'status' => 0,
62
+ ])->save();
63
+
64
+ $node->setTitle('Test 2');
65
+ $node->save();
66
+
67
+ $diff = $this->tracker->diff(1, 3, $this->server->id());
68
+ $this->assertEquals([
69
+ new GatsbyUpdate('Page', $node->uuid() . ':en'),
70
+ new GatsbyUpdate('Page', $node->uuid() . ':de'),
71
+ ], $diff);
72
+ }
73
+
74
+ /**
75
+ *
76
+ */
77
+ public function testIgnoreIrrelevantChanges() {
78
+ $node = Node::create([
79
+ 'type' => 'article',
80
+ 'title' => 'Test',
81
+ 'status' => 0,
82
+ ]);
83
+ $node->save();
84
+ $node->setTitle('Test 2');
85
+ $node->save();
86
+
87
+ $diff = $this->tracker->diff(1, 2, $this->server->id());
88
+ $this->assertEmpty($diff);
89
+ }
90
+
91
+ /**
92
+ *
93
+ */
94
+ public function testTriggerUpdates() {
95
+ $page = Node::create([
96
+ 'type' => 'page',
97
+ 'title' => 'Test',
98
+ 'status' => 0,
99
+ ]);
100
+ $page->save();
101
+
102
+ $article = Node::create([
103
+ 'type' => 'article',
104
+ 'title' => 'Test',
105
+ 'status' => 0,
106
+ ]);
107
+ $article->save();
108
+
109
+ $this->triggerProphecy
110
+ ->trigger($this->server->id(), new GatsbyUpdate('Page', $page->uuid() . ':en'))->shouldHaveBeenCalledTimes(1);
111
+ }
112
+
113
+ /**
114
+ * Test case for testing the behavior when path alias triggers updates.
115
+ */
116
+ public function testPathAliasTriggerUpdates() {
117
+ $node = Node::create([
118
+ 'type' => 'page',
119
+ 'title' => 'Test',
120
+ ]);
121
+ $node->save();
122
+ $this->tracker->clear();
123
+ $this->createPathAlias('/node/1', '/test', 'en');
124
+ $this->tracker->clear();
125
+ // We expect two calls for the same page, as the path alias
126
+ // should also trigger a page build.
127
+ $this->triggerProphecy
128
+ ->trigger($this->server->id(), new GatsbyUpdate('Page', $node->uuid() . ':en'))->shouldHaveBeenCalledTimes(2);
129
+ }
130
+
131
+ }