66use Illuminate \Pagination \LengthAwarePaginator ;
77use Illuminate \Pagination \Paginator ;
88use Napp \Core \Api \Tests \Models \Category ;
9+ use Napp \Core \Api \Tests \Transformers \CategoryStrictTransformer ;
910use Napp \Core \Api \Transformers \ApiTransformer ;
1011use Napp \Core \Api \Tests \TestCase ;
1112
@@ -146,4 +147,43 @@ public function test_transform_length_aware_paginated_with_relationships()
146147 $ this ->assertEquals ('Windows ' , $ transformedOutput ['data ' ][1 ]['products ' ][1 ]['title ' ]);
147148 }
148149
150+ public function test_transform_length_aware_paginated_with_relationships_with_strict_mode_on ()
151+ {
152+ $ category = Category::create (['title ' => 'Electronics ' ]);
153+ $ category ->products ()->create (['name ' => 'iPhone ' , 'price ' => 100.0 ]);
154+ $ category ->products ()->create (['name ' => 'Google Pixel ' , 'price ' => 80.0 ]);
155+ $ category ->products ()->create (['name ' => 'Samsung Galaxy 9 ' , 'price ' => 110.0 ]);
156+
157+ $ category2 = Category::create (['title ' => 'Computers ' ]);
158+ $ category2 ->products ()->create (['name ' => 'Mac ' , 'price ' => 28860.0 ]);
159+ $ category2 ->products ()->create (['name ' => 'Windows ' , 'price ' => 11000.0 ]);
160+
161+ $ input = Category::with ('products ' )->get ();
162+
163+ $ paginatedInput = new LengthAwarePaginator ($ input , count ($ input ) * 4 , count ($ input ));
164+
165+ $ transformedOutput = (new CategoryStrictTransformer ())->transformOutput ($ paginatedInput );
166+
167+ $ this ->assertArrayHasKey ('current_page ' , $ transformedOutput );
168+ $ this ->assertArrayHasKey ('data ' , $ transformedOutput );
169+ $ this ->assertArrayHasKey ('first_page_url ' , $ transformedOutput );
170+ $ this ->assertArrayHasKey ('from ' , $ transformedOutput );
171+ $ this ->assertArrayHasKey ('last_page ' , $ transformedOutput );
172+ $ this ->assertArrayHasKey ('last_page_url ' , $ transformedOutput );
173+ $ this ->assertArrayHasKey ('next_page_url ' , $ transformedOutput );
174+ $ this ->assertArrayHasKey ('path ' , $ transformedOutput );
175+ $ this ->assertArrayHasKey ('per_page ' , $ transformedOutput );
176+ $ this ->assertArrayHasKey ('prev_page_url ' , $ transformedOutput );
177+ $ this ->assertArrayHasKey ('to ' , $ transformedOutput );
178+ $ this ->assertArrayHasKey ('total ' , $ transformedOutput );
179+
180+ $ this ->assertArrayNotHasKey ('products ' , $ transformedOutput ['data ' ][0 ]);
181+ $ this ->assertArrayNotHasKey ('products ' , $ transformedOutput ['data ' ][1 ]);
182+ $ this ->assertArrayNotHasKey ('title ' , $ transformedOutput ['data ' ][0 ]);
183+ $ this ->assertArrayNotHasKey ('title ' , $ transformedOutput ['data ' ][1 ]);
184+
185+ $ this ->assertEquals (1 , $ transformedOutput ['data ' ][0 ]['id ' ]);
186+ $ this ->assertEquals (2 , $ transformedOutput ['data ' ][1 ]['id ' ]);
187+ }
188+
149189}
0 commit comments