File tree Expand file tree Collapse file tree 6 files changed +107
-12
lines changed
Field/Page/Fieldtype/FieldtypeInteger Expand file tree Collapse file tree 6 files changed +107
-12
lines changed Original file line number Diff line number Diff line change 11<?php namespace ProcessWire \GraphQL \Type \Fieldtype ;
22
33use GraphQL \Type \Definition \Type ;
4- use ProcessWire \GraphQL \Type \Fieldtype \Traits \FieldTrait ;
4+ use ProcessWire \Page ;
5+ use ProcessWire \GraphQL \Cache ;
56use ProcessWire \GraphQL \Type \Fieldtype \Traits \InputFieldTrait ;
67use ProcessWire \GraphQL \Type \Fieldtype \Traits \SetValueTrait ;
78
89class FieldtypeInteger
910{
10- use FieldTrait;
1111 use InputFieldTrait;
1212 use SetValueTrait;
1313 public static function type ()
1414 {
1515 return Type::int ();
1616 }
17+
18+ public static function field ($ field )
19+ {
20+ return Cache::field ($ field ->name , function () use ($ field ) {
21+ // description
22+ $ desc = $ field ->description ;
23+ if (!$ desc ) {
24+ $ desc = "Field with the type of {$ field ->type }" ;
25+ }
26+
27+ return [
28+ 'name ' => $ field ->name ,
29+ 'description ' => $ desc ,
30+ 'type ' => self ::type ($ field ),
31+ 'resolve ' => function (Page $ page ) use ($ field ) {
32+ $ fieldName = $ field ->name ;
33+ $ value = $ page ->$ fieldName ;
34+ if (empty ($ value ) && !is_int ($ value )) {
35+ return null ;
36+ }
37+ return $ value ;
38+ }
39+ ];
40+ });
41+ }
1742}
Original file line number Diff line number Diff line change 66use \ProcessWire \GraphQL \Test \Field \Page \Fieldtype \Traits \FieldtypeTestTrait ;
77use \ProcessWire \GraphQL \Utils ;
88
9- class FieldtypeIntegerTest extends GraphqlTestCase {
9+ class FieldtypeIntegerCaseOneTest extends GraphqlTestCase {
1010
1111 const settings = [
1212 'login ' => 'admin ' ,
@@ -20,7 +20,7 @@ class FieldtypeIntegerTest extends GraphqlTestCase {
2020
2121 public function testValue ()
2222 {
23- $ skyscraper = Utils::pages ()->find ("template=skyscraper, sort=random " )-> first ( );
23+ $ skyscraper = Utils::pages ()->get ("template=skyscraper, sort=random " );
2424 $ query = "{
2525 skyscraper(s: \"id= $ skyscraper ->id \") {
2626 list {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace ProcessWire \GraphQL \Test \Field \Page \Fieldtype ;
4+
5+ use \ProcessWire \GraphQL \Test \GraphqlTestCase ;
6+ use \ProcessWire \GraphQL \Utils ;
7+
8+ class FieldtypeIntegerCaseThreeTest extends GraphqlTestCase {
9+
10+ const settings = [
11+ 'login ' => 'admin ' ,
12+ 'legalTemplates ' => ['skyscraper ' ],
13+ 'legalFields ' => ['floors ' ],
14+ 'access ' => [
15+ 'fields ' => [
16+ [
17+ 'name ' => 'floors ' ,
18+ 'zeroNotEmpty ' => true
19+ ]
20+ ]
21+ ]
22+ ];
23+
24+ public function testValue ()
25+ {
26+ $ skyscraper = Utils::pages ()->get ("template=skyscraper, sort=random, floors='' " );
27+ $ query = "{
28+ skyscraper(s: \"id= $ skyscraper ->id \") {
29+ list {
30+ floors
31+ }
32+ }
33+ } " ;
34+ $ res = self ::execute ($ query );
35+ assertNull ($ res ->data ->skyscraper ->list [0 ]->floors , 'Retrieves incorrect value. ' );
36+ assertObjectNotHasAttribute ('errors ' , $ res , 'There are errors. ' );
37+ }
38+
39+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace ProcessWire \GraphQL \Test \Field \Page \Fieldtype ;
4+
5+ use \ProcessWire \GraphQL \Test \GraphqlTestCase ;
6+ use \ProcessWire \GraphQL \Utils ;
7+
8+ class FieldtypeIntegerCaseTwoTest extends GraphqlTestCase {
9+
10+ const settings = [
11+ 'login ' => 'admin ' ,
12+ 'legalTemplates ' => ['skyscraper ' ],
13+ 'legalFields ' => ['floors ' ],
14+ ];
15+
16+ public function testValue ()
17+ {
18+ $ skyscraper = Utils::pages ()->get ("template=skyscraper, sort=random, floors=0 " );
19+ $ query = "{
20+ skyscraper(s: \"id= $ skyscraper ->id \") {
21+ list {
22+ floors
23+ }
24+ }
25+ } " ;
26+ $ res = self ::execute ($ query );
27+ assertEquals (0 , $ res ->data ->skyscraper ->list [0 ]->floors , 'Retrieves incorrect value. ' );
28+ assertObjectNotHasAttribute ('errors ' , $ res , 'There are errors. ' );
29+ }
30+
31+ }
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ public function testDbQueryCount() {
118118 $ expected = $ skyscrapers ->get ("architects= $ architectsWithResumes, sort=random " );
119119 assertNotNull ($ expected , 'No expected skyscraper to check. ' );
120120 $ actual = self ::getListItemId ($ res ->data ->skyscraper ->list , $ expected ->id );
121- assertEquals (count ($ expected ->architects ), count ($ actual ->architects ), 'Incorrect architects amount. ' );
121+ assertEquals (count ($ expected ->architects ), count ($ actual ->architects -> list ), 'Incorrect architects amount. ' );
122122 assertEquals ($ expected ->architects [0 ]->id , $ actual ->architects ->list [0 ]->id , 'Incorrect architect id. ' );
123123 assertEquals ($ expected ->architects [0 ]->title , $ actual ->architects ->list [0 ]->title , 'Incorrect architect title. ' );
124124 assertEquals ($ expected ->architects [0 ]->created , $ actual ->architects ->list [0 ]->created , 'Incorrect architect created. ' );
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments