Skip to content

Commit 0b6b4c4

Browse files
committed
test(references): add tests for $page->references api support.
1 parent 2146054 commit 0b6b4c4

File tree

3 files changed

+170
-0
lines changed

3 files changed

+170
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/**
4+
* When both requested page template and it's referenses' templates
5+
* are legal templates then admin user gets all the pages.
6+
*/
7+
8+
namespace ProcessWire\GraphQL\Test\FieldtypePageReferences;
9+
10+
use ProcessWire\GraphQL\Utils;
11+
use ProcessWire\GraphQL\Test\GraphQLTestCase;
12+
13+
class CaseOneTest extends GraphQLTestCase
14+
{
15+
const settings = [
16+
"login" => "admin",
17+
"legalTemplates" => ["skyscraper", "architect"],
18+
"legalPageFields" => ["references", "name"],
19+
"legalFields" => ["architects"]
20+
];
21+
22+
public function testValue()
23+
{
24+
$architect = Utils::pages()->get("template=architect");
25+
$query = "{
26+
architect (s: \"id=$architect->id\") {
27+
list {
28+
name
29+
references {
30+
getTotal
31+
list {
32+
name
33+
}
34+
}
35+
}
36+
}
37+
}";
38+
$res = self::execute($query);
39+
self::assertEquals(
40+
$architect->references()[0]->name,
41+
$res->data->architect->list[0]->references->list[0]->name,
42+
"Retrieves correct reference page at 0."
43+
);
44+
self::assertEquals(
45+
$architect->references()[1]->name,
46+
$res->data->architect->list[0]->references->list[1]->name,
47+
"Retrieves correct reference page at 1."
48+
);
49+
self::assertEquals(
50+
$architect->references()[2]->name,
51+
$res->data->architect->list[0]->references->list[2]->name,
52+
"Retrieves correct reference page at 2."
53+
);
54+
self::assertEquals(
55+
$architect->references->count,
56+
$res->data->architect->list[0]->references->getTotal,
57+
"Retrieves correct amount of reference pages."
58+
);
59+
self::assertObjectNotHasAttribute("errors", $res, "There are errors.");
60+
}
61+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 CaseThreeTest 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+
]
33+
];
34+
}
35+
36+
public function testValue()
37+
{
38+
$architect = Utils::pages()->get("template=architect");
39+
$query = "{
40+
architect (s: \"id=$architect->id\") {
41+
list {
42+
references {
43+
getTotal
44+
list {
45+
name
46+
}
47+
}
48+
}
49+
}
50+
}";
51+
$res = self::execute($query);
52+
self::assertNotEquals(
53+
count($architect->references()),
54+
count($res->data->architect->list[0]->references->list),
55+
"Returns empty list when user has no access to referenced pages template."
56+
);
57+
self::assertEquals(
58+
0,
59+
count($res->data->architect->list[0]->references->list),
60+
"Returns empty list when user has no access to referenced pages template."
61+
);
62+
self::assertObjectNotHasAttribute("errors", $res, "There are errors.");
63+
}
64+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/**
4+
* When the requested page template is legal but not
5+
* 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 CaseTwoTest extends GraphQLTestCase
15+
{
16+
const settings = [
17+
"login" => "admin",
18+
"legalTemplates" => ["architect"],
19+
"legalPageFields" => ["references"],
20+
];
21+
22+
public function testValue()
23+
{
24+
$architect = Utils::pages()->get("template=architect");
25+
$query = "{
26+
architect (s: \"id=$architect->id\") {
27+
list {
28+
references {
29+
getTotal
30+
list {
31+
name
32+
}
33+
}
34+
}
35+
}
36+
}";
37+
$res = self::execute($query);
38+
self::assertEquals(
39+
0,
40+
count($res->data->architect->list[0]->references->list),
41+
"Returns empty list when no access to parent pages template."
42+
);
43+
self::assertObjectNotHasAttribute("errors", $res, "There are errors.");
44+
}
45+
}

0 commit comments

Comments
 (0)