@@ -685,14 +685,119 @@ public function provideFilterAndSortOnlyRead(): array
685
685
}
686
686
}
687
687
GRAPHQL ,
688
+ 'expected ' => [
689
+ ["myField " => "test2 " , "author " => ["firstName " => "tester2 " ]],
690
+ ["myField " => "test3 " , "author " => ["firstName " => "tester2 " ]],
691
+ ["myField " => "test1 " , "author " => ["firstName " => "tester1 " ]],
692
+ ],
693
+ ],
694
+ 'read with sorter files title DESC ' => [
695
+ 'fixture ' => '_SortPlugin ' ,
696
+ 'query ' => <<<GRAPHQL
697
+ query {
698
+ readDataObjectFakes(sort: { myField: ASC }) {
699
+ nodes {
700
+ myField
701
+ files(sort: { title: DESC }) {
702
+ title
703
+ }
704
+ }
705
+ }
706
+ }
707
+ GRAPHQL ,
708
+ 'expected ' => [
709
+ ["myField " => "test1 " , "files " => [["title " => "file4 " ], ["title " => "file3 " ], ["title " => "file2 " ], ["title " => "file1 " ]]],
710
+ ["myField " => "test2 " , "files " => []],
711
+ ["myField " => "test3 " , "files " => []],
712
+ ],
713
+ ],
714
+ 'read with sorter files ParentID ACS, name DESC ' => [
715
+ 'fixture ' => '_SortPlugin ' ,
716
+ 'query ' => <<<GRAPHQL
717
+ query {
718
+ readDataObjectFakes(sort: { myField: ASC }) {
719
+ nodes {
720
+ myField
721
+ files(sort: { ParentID: ASC, name: DESC }) {
722
+ title
723
+ }
724
+ }
725
+ }
726
+ }
727
+ GRAPHQL ,
728
+ 'expected ' => [
729
+ ["myField " => "test1 " , "files " => [["title " => "file2 " ],["title " => "file1 " ], ["title " => "file4 " ],["title " => "file3 " ]]],
730
+ ["myField " => "test2 " , "files " => []],
731
+ ["myField " => "test3 " , "files " => []],
732
+ ],
733
+ ],
734
+ 'read with sorter files ParentID DESC, name ASC ' => [
735
+ 'fixture ' => '_SortPlugin ' ,
736
+ 'query ' => <<<GRAPHQL
737
+ query {
738
+ readDataObjectFakes(sort: { myField: ASC }) {
739
+ nodes {
740
+ myField
741
+ files(sort: { ParentID: DESC, name: ASC }) {
742
+ title
743
+ }
744
+ }
745
+ }
746
+ }
747
+ GRAPHQL ,
748
+ 'expected ' => [
749
+ ["myField " => "test1 " , "files " => [["title " => "file3 " ],["title " => "file4 " ], ["title " => "file1 " ],["title " => "file2 " ]]],
750
+ ["myField " => "test2 " , "files " => []],
751
+ ["myField " => "test3 " , "files " => []],
752
+ ],
753
+ ],
754
+ 'read with sorter files name ASC, ParentID DESC ' => [
755
+ 'fixture ' => '_SortPlugin ' ,
756
+ 'query ' => <<<GRAPHQL
757
+ query {
758
+ readDataObjectFakes(sort: { myField: ASC }) {
759
+ nodes {
760
+ myField
761
+ files(sort: { name: ASC, ParentID: DESC }) {
762
+ title
763
+ }
764
+ }
765
+ }
766
+ }
767
+ GRAPHQL ,
768
+ 'expected ' => [
769
+ ["myField " => "test1 " , "files " => [["title " => "file3 " ],["title " => "file1 " ], ["title " => "file4 " ],["title " => "file2 " ]]],
770
+ ["myField " => "test2 " , "files " => []],
771
+ ["myField " => "test3 " , "files " => []],
772
+ ],
773
+ ],
774
+ 'read with sorter files name DESC, ParentID ASC ' => [
775
+ 'fixture ' => '_SortPlugin ' ,
776
+ 'query ' => <<<GRAPHQL
777
+ query {
778
+ readDataObjectFakes(sort: { myField: ASC }) {
779
+ nodes {
780
+ myField
781
+ files(sort: { name: DESC, ParentID: ASC }) {
782
+ title
783
+ }
784
+ }
785
+ }
786
+ }
787
+ GRAPHQL ,
788
+ 'expected ' => [
789
+ ["myField " => "test1 " , "files " => [["title " => "file2 " ],[ "title " => "file4 " ],["title " => "file1 " ],["title " => "file3 " ]]],
790
+ ["myField " => "test2 " , "files " => []],
791
+ ["myField " => "test3 " , "files " => []],
792
+ ],
688
793
],
689
794
];
690
795
}
691
796
692
797
/**
693
798
* @dataProvider provideFilterAndSortOnlyRead
694
799
*/
695
- public function testFilterAndSortOnlyRead ($ fixture , $ query )
800
+ public function testFilterAndSortOnlyRead (string $ fixture , string $ query, array $ expected )
696
801
{
697
802
$ author = Member::create (['FirstName ' => 'tester1 ' ]);
698
803
$ author ->write ();
@@ -709,18 +814,34 @@ public function testFilterAndSortOnlyRead($fixture, $query)
709
814
$ dataObject3 = DataObjectFake::create (['MyField ' => 'test3 ' , 'AuthorID ' => $ author2 ->ID ]);
710
815
$ dataObject3 ->write ();
711
816
817
+ $ file1 = File::create (['Title ' => 'file1 ' , 'Name ' => 'asc_name ' ]);
818
+ $ file1 ->ParentID = 1 ;
819
+ $ file1 ->write ();
820
+
821
+ $ file2 = File::create (['Title ' => 'file2 ' , 'Name ' => 'desc_name ' ]);
822
+ $ file2 ->ParentID = 1 ;
823
+ $ file2 ->write ();
824
+
825
+ $ file3 = File::create (['Title ' => 'file3 ' , 'Name ' => 'asc_name ' ]);
826
+ $ file3 ->ParentID = 2 ;
827
+ $ file3 ->write ();
828
+
829
+ $ file4 = File::create (['Title ' => 'file4 ' , 'Name ' => 'desc_name ' ]);
830
+ $ file4 ->ParentID = 2 ;
831
+ $ file4 ->write ();
832
+
833
+ $ dataObject1 ->Files ()->add ($ file1 );
834
+ $ dataObject1 ->Files ()->add ($ file2 );
835
+ $ dataObject1 ->Files ()->add ($ file3 );
836
+ $ dataObject1 ->Files ()->add ($ file4 );
712
837
713
838
$ factory = new TestSchemaBuilder (['_ ' . __FUNCTION__ . $ fixture ]);
714
839
$ schema = $ this ->createSchema ($ factory );
715
840
716
841
$ result = $ this ->querySchema ($ schema , $ query );
717
842
$ this ->assertSuccess ($ result );
718
843
$ records = $ result ['data ' ]['readDataObjectFakes ' ]['nodes ' ] ?? [];
719
- $ this ->assertResults ([
720
- ["myField " => "test2 " , "author " => ["firstName " => "tester2 " ]],
721
- ["myField " => "test3 " , "author " => ["firstName " => "tester2 " ]],
722
- ["myField " => "test1 " , "author " => ["firstName " => "tester1 " ]],
723
- ], $ records );
844
+ $ this ->assertResults ($ expected , $ records );
724
845
}
725
846
726
847
public function testAggregateProperties ()
0 commit comments