|
| 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 | +} |
0 commit comments