Skip to content

Commit 26cccac

Browse files
committed
test(references): add tests for $page->references api support.
1 parent e4eb85b commit 26cccac

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
/**
4+
* When user got access to requested page template but not
5+
* to the references' templates. The `references` field returns
6+
* empty list.
7+
*/
8+
9+
namespace ProcessWire\GraphQL\Test\FieldtypePageReferences;
10+
11+
use ProcessWire\GraphQL\Utils;
12+
use ProcessWire\GraphQL\Test\GraphQLTestCase;
13+
14+
class CaseFourTest extends GraphQLTestCase
15+
{
16+
public static function getSettings()
17+
{
18+
19+
$editorRole = Utils::roles()->get("editor");
20+
21+
return [
22+
"login" => "editor",
23+
"legalTemplates" => ["architect", "skyscraper"],
24+
"legalPageFields" => ["references"],
25+
"access" => [
26+
"templates" => [
27+
[
28+
"name" => "architect",
29+
"roles" => [$editorRole->id],
30+
],
31+
[
32+
"name" => "skyscraper",
33+
"roles" => [$editorRole->id],
34+
],
35+
],
36+
]
37+
];
38+
}
39+
40+
public function testValue()
41+
{
42+
$architect = Utils::pages()->get("template=architect");
43+
$query = "{
44+
architect (s: \"id=$architect->id\") {
45+
list {
46+
references {
47+
getTotal
48+
list {
49+
name
50+
}
51+
}
52+
}
53+
}
54+
}";
55+
$res = self::execute($query);
56+
self::assertEquals(
57+
$architect->references()[0]->name,
58+
$res->data->architect->list[0]->references->list[0]->name,
59+
"Retrieves correct reference page at 0."
60+
);
61+
self::assertEquals(
62+
$architect->references()[1]->name,
63+
$res->data->architect->list[0]->references->list[1]->name,
64+
"Retrieves correct reference page at 1."
65+
);
66+
self::assertEquals(
67+
$architect->references->count,
68+
$res->data->architect->list[0]->references->getTotal,
69+
"Retrieves correct amount of reference pages."
70+
);
71+
self::assertObjectNotHasAttribute("errors", $res, "There are errors.");
72+
}
73+
}

test/Field/Page/PageReferences/CaseThreeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testValue()
5252
self::assertNotEquals(
5353
count($architect->references()),
5454
count($res->data->architect->list[0]->references->list),
55-
"Returns empty list when user has no access to referenced pages template."
55+
"Returned number of reference pages is not the same as the actual number of reference pages."
5656
);
5757
self::assertEquals(
5858
0,

test/Field/Page/PageReferences/CaseTwoTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testValue()
3838
self::assertEquals(
3939
0,
4040
count($res->data->architect->list[0]->references->list),
41-
"Returns empty list when no access to parent pages template."
41+
"Returns empty list when no access to references pages template."
4242
);
4343
self::assertObjectNotHasAttribute("errors", $res, "There are errors.");
4444
}

0 commit comments

Comments
 (0)