+ public function test_event_webhook_call_before()
+ {
+ $args = [];
+ $callback = function (...$eventArgs) use (&$args) {
+ $args = $eventArgs;
+
+ return ['test' => 'hello!'];
+ };
+ Theme::listen(ThemeEvents::WEBHOOK_CALL_BEFORE, $callback);
+
+ Http::fake([
+ '*' => Http::response('', 200),
+ ]);
+
+ $webhook = new Webhook(['name' => 'Test webhook', 'endpoint' => 'https://example.com']);
+ $webhook->save();
+ $event = ActivityType::PAGE_UPDATE;
+ $detail = Page::query()->first();
+
+ dispatch((new DispatchWebhookJob($webhook, $event, $detail)));
+
+ $this->assertCount(5, $args);
+ $this->assertEquals($event, $args[0]);
+ $this->assertEquals($webhook->id, $args[1]->id);
+ $this->assertEquals($detail->id, $args[2]->id);
+
+ Http::assertSent(function (HttpClientRequest $request) {
+ return $request->isJson() && $request->data()['test'] === 'hello!';
+ });
+ }
+
+ public function test_event_activity_logged()
+ {
+ $book = $this->entities->book();
+ $args = [];
+ $callback = function (...$eventArgs) use (&$args) {
+ $args = $eventArgs;
+ };
+
+ Theme::listen(ThemeEvents::ACTIVITY_LOGGED, $callback);
+ $this->asEditor()->put($book->getUrl(), ['name' => 'My cool update book!']);
+
+ $this->assertCount(2, $args);
+ $this->assertEquals(ActivityType::BOOK_UPDATE, $args[0]);
+ $this->assertTrue($args[1] instanceof Book);
+ $this->assertEquals($book->id, $args[1]->id);
+ }
+
+ public function test_event_page_include_parse()
+ {
+ /** @var Page $page */
+ /** @var Page $otherPage */
+ $page = $this->entities->page();
+ $otherPage = Page::query()->where('id', '!=', $page->id)->first();
+ $otherPage->html = '<p id="bkmrk-cool">This is a really cool section</p>';
+ $page->html = "<p>{{@{$otherPage->id}#bkmrk-cool}}</p>";
+ $page->save();
+ $otherPage->save();
+
+ $args = [];
+ $callback = function (...$eventArgs) use (&$args) {
+ $args = $eventArgs;
+
+ return '<strong>Big & content replace surprise!</strong>';
+ };
+
+ Theme::listen(ThemeEvents::PAGE_INCLUDE_PARSE, $callback);
+ $resp = $this->asEditor()->get($page->getUrl());
+ $this->withHtml($resp)->assertElementContains('.page-content strong', 'Big & content replace surprise!');
+
+ $this->assertCount(4, $args);
+ $this->assertEquals($otherPage->id . '#bkmrk-cool', $args[0]);
+ $this->assertEquals('This is a really cool section', $args[1]);
+ $this->assertTrue($args[2] instanceof Page);
+ $this->assertTrue($args[3] instanceof Page);
+ $this->assertEquals($page->id, $args[2]->id);
+ $this->assertEquals($otherPage->id, $args[3]->id);
+ }
+