Skip to content

Commit 696b34c

Browse files
committed
test(page-class): cover page creation with custom page class
1 parent ea5c2b1 commit 696b34c

File tree

2 files changed

+54
-63
lines changed

2 files changed

+54
-63
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace ProcessWire\GraphQL\Test\PageClass;
4+
5+
use ProcessWire\BasicPagePage;
6+
use ProcessWire\GraphQL\Test\GraphqlTestCase;
7+
use ProcessWire\GraphQL\Utils;
8+
use ProcessWire\HookEvent;
9+
10+
class PageClassCreateTest extends GraphqlTestCase
11+
{
12+
const settings = [
13+
"login" => "admin",
14+
"legalTemplates" => ["basic-page", "home"],
15+
"legalFields" => ["title"],
16+
];
17+
18+
public function testCustomGet()
19+
{
20+
$originalValue = "original value";
21+
$expectedValue = "expected value";
22+
// Attach a hook pages save.
23+
Utils::pages()->addHookBefore("Pages::save", function (
24+
HookEvent $hookEvent
25+
) use (&$originalValue, $expectedValue) {
26+
$page = $hookEvent->arguments(0);
27+
if ($page instanceof BasicPagePage) {
28+
$originalValue = $expectedValue;
29+
}
30+
});
31+
32+
// create basic page via graphql
33+
$query = 'mutation CreateBasicPage ($page: BasicPageCreateInput!) {
34+
createBasicPage (page: $page) {
35+
title
36+
id
37+
}
38+
}';
39+
$variables = [
40+
"page" => [
41+
"parent" => "1",
42+
"name" => "basic-page-with-custom-class-created",
43+
"title" => "Incorrect title",
44+
],
45+
];
46+
47+
self::execute($query, $variables);
48+
self::assertEquals(
49+
$originalValue,
50+
$expectedValue,
51+
"Graphql created basic page does not use the custom page class."
52+
);
53+
}
54+
}

test/PageClass/PageClassTest.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)