server/src/tests/Controllers/ThemeControllerTest.php
changeset 537 d2e6ee099125
parent 474 245b4df137d3
equal deleted inserted replaced
536:b64c8c35c67d 537:d2e6ee099125
   105                             "value" => 999
   105                             "value" => 999
   106                         ]
   106                         ]
   107                     ]
   107                     ]
   108                 ]
   108                 ]
   109             ]);
   109             ]);
   110         $this->get('/api/v1/stats/themes/')->assertTrue($this->response->isOk(), $this->response->content());
   110         $response = $this->get('/api/v1/stats/themes/');
   111         $this->seeJsonEquals(["themes" => [
   111         $response
       
   112             ->assertStatus(200)
       
   113             ->assertJson(["themes" => [
   112             "http://ark.bnf.fr/ark:/12148/cb13318415c" => ['label' => 'professions', 'count' => 1412 ],
   114             "http://ark.bnf.fr/ark:/12148/cb13318415c" => ['label' => 'professions', 'count' => 1412 ],
   113             "http://ark.bnf.fr/ark:/12148/cb16604691s" => ['label' => 'travail non rémunéré', 'count' => 1092 ],
   115             "http://ark.bnf.fr/ark:/12148/cb16604691s" => ['label' => 'travail non rémunéré', 'count' => 1092 ],
   114             "http://ark.bnf.fr/ark:/12148/cb119339867" => ['label' => 'famille', 'count' => 1050 ],
   116             "http://ark.bnf.fr/ark:/12148/cb119339867" => ['label' => 'famille', 'count' => 1050 ],
   115             "http://ark.bnf.fr/ark:/12148/cb11932889r" => ['label' => 'oiseaux', 'count' => 1003 ],
   117             "http://ark.bnf.fr/ark:/12148/cb11932889r" => ['label' => 'oiseaux', 'count' => 1003 ],
   116             "http://ark.bnf.fr/ark:/12148/cb11932496x" => ['label' => 'météorologie', 'count' => 1001 ],
   118             "http://ark.bnf.fr/ark:/12148/cb11932496x" => ['label' => 'météorologie', 'count' => 1001 ],
   210                             "value" => 999
   212                             "value" => 999
   211                         ]
   213                         ]
   212                     ]
   214                     ]
   213                 ]
   215                 ]
   214             ]);
   216             ]);
   215         $this->get('/api/v1/stats/themes/?filter=all')->assertTrue($this->response->isOk(), $this->response->content());
   217         $response = $this->get('/api/v1/stats/themes/?filter=all');
   216         $this->seeJsonEquals(["themes" => [
   218         $response
       
   219             ->assertStatus(200)
       
   220             ->assertJson(["themes" => [
   217             "http://ark.bnf.fr/ark:/12148/cb13318415c" => ['label' => 'professions', 'count' => 1412 ],
   221             "http://ark.bnf.fr/ark:/12148/cb13318415c" => ['label' => 'professions', 'count' => 1412 ],
   218             "http://ark.bnf.fr/ark:/12148/cb16604691s" => ['label' => 'travail non rémunéré', 'count' => 1092 ],
   222             "http://ark.bnf.fr/ark:/12148/cb16604691s" => ['label' => 'travail non rémunéré', 'count' => 1092 ],
   219             "http://ark.bnf.fr/ark:/12148/cb119339867" => ['label' => 'famille', 'count' => 1050 ],
   223             "http://ark.bnf.fr/ark:/12148/cb119339867" => ['label' => 'famille', 'count' => 1050 ],
   220             "http://ark.bnf.fr/ark:/12148/cb11932889r" => ['label' => 'oiseaux', 'count' => 1003 ],
   224             "http://ark.bnf.fr/ark:/12148/cb11932889r" => ['label' => 'oiseaux', 'count' => 1003 ],
   221             "http://lexvo.org/id/iso639-3/fra" => ['label' => 'Français', 'count' => 1002 ],
   225             "http://lexvo.org/id/iso639-3/fra" => ['label' => 'Français', 'count' => 1002 ],
   294                             "value" => 999
   298                             "value" => 999
   295                         ]
   299                         ]
   296                     ]
   300                     ]
   297                 ]
   301                 ]
   298             ]);
   302             ]);
   299         $this->get('/api/v1/stats/themes/?filter=lexvo')->assertTrue($this->response->isOk(), $this->response->content());
   303         $response = $this->get('/api/v1/stats/themes/?filter=lexvo');
   300         $this->seeJsonEquals(["themes" => [
   304         $response
       
   305             ->assertStatus(200)
       
   306             ->assertJson(["themes" => [
   301             "http://lexvo.org/id/iso639-3/fra" => ['label' => 'Français', 'count' => 1002 ],
   307             "http://lexvo.org/id/iso639-3/fra" => ['label' => 'Français', 'count' => 1002 ],
   302             "http://lexvo.org/id/iso639-3/bzh" => ['label' => 'Breton', 'count' => 992 ]
   308             "http://lexvo.org/id/iso639-3/bzh" => ['label' => 'Breton', 'count' => 992 ]
   303         ], "meta" => ['total' => 999]]);
   309         ], "meta" => ['total' => 999]]);
   304 
   310 
   305     }
   311     }
   371 
   377 
   372         Es::shouldReceive('search')
   378         Es::shouldReceive('search')
   373             ->once()
   379             ->once()
   374             ->with($this->getOrderQuery(['_count' => 'desc']))
   380             ->with($this->getOrderQuery(['_count' => 'desc']))
   375             ->andReturn($this->getRespSort());
   381             ->andReturn($this->getRespSort());
   376         $this->get('/api/v1/stats/themes/')->assertTrue($this->response->isOk(), $this->response->content());
   382         $this->get('/api/v1/stats/themes/')->assertStatus(200);
   377 
   383 
   378     }
   384     }
   379 
   385 
   380     public function testIndexSortReverseCount() {
   386     public function testIndexSortReverseCount() {
   381         Es::shouldReceive('search')
   387         Es::shouldReceive('search')
   382             ->once()
   388             ->once()
   383             ->with($this->getOrderQuery(['_count' => 'asc']))
   389             ->with($this->getOrderQuery(['_count' => 'asc']))
   384             ->andReturn($this->getRespSort());
   390             ->andReturn($this->getRespSort());
   385         $this->get('/api/v1/stats/themes/?sort=-count')->assertTrue($this->response->isOk(), $this->response->content());
   391         $this->get('/api/v1/stats/themes/?sort=-count')->assertStatus(200);
   386     }
   392     }
   387 
   393 
   388     public function testIndexSortLabel() {
   394     public function testIndexSortLabel() {
   389         Es::shouldReceive('search')
   395         Es::shouldReceive('search')
   390             ->once()
   396             ->once()
   391             ->with($this->getOrderQuery(['_term' => 'asc']))
   397             ->with($this->getOrderQuery(['_term' => 'asc']))
   392             ->andReturn($this->getRespSort());
   398             ->andReturn($this->getRespSort());
   393         $this->get('/api/v1/stats/themes/?sort=label')->assertTrue($this->response->isOk(), $this->response->content());
   399         $this->get('/api/v1/stats/themes/?sort=label')->assertStatus(200);
   394     }
   400     }
   395 
   401 
   396     public function testIndexSortAlphabetical() {
   402     public function testIndexSortAlphabetical() {
   397         Es::shouldReceive('search')
   403         Es::shouldReceive('search')
   398             ->once()
   404             ->once()
   399             ->with($this->getOrderQuery(['_term' => 'asc']))
   405             ->with($this->getOrderQuery(['_term' => 'asc']))
   400             ->andReturn($this->getRespSort());
   406             ->andReturn($this->getRespSort());
   401         $this->get('/api/v1/stats/themes/?sort=alphabetical')->assertTrue($this->response->isOk(), $this->response->content());
   407         $this->get('/api/v1/stats/themes/?sort=alphabetical')->assertStatus(200);
   402     }
   408     }
   403 
   409 
   404     public function testIndexSortLabelReverse() {
   410     public function testIndexSortLabelReverse() {
   405         Es::shouldReceive('search')
   411         Es::shouldReceive('search')
   406             ->once()
   412             ->once()
   407             ->with($this->getOrderQuery(['_term' => 'desc']))
   413             ->with($this->getOrderQuery(['_term' => 'desc']))
   408             ->andReturn($this->getRespSort());
   414             ->andReturn($this->getRespSort());
   409         $this->get('/api/v1/stats/themes/?sort=-label')->assertTrue($this->response->isOk(), $this->response->content());
   415         $this->get('/api/v1/stats/themes/?sort=-label')->assertStatus(200);
   410     }
   416     }
   411 
   417 
   412 
   418 
   413     public function testIndexLimit() {
   419     public function testIndexLimit() {
   414 
   420 
   495                             "value" => 999
   501                             "value" => 999
   496                         ]
   502                         ]
   497                     ]
   503                     ]
   498                 ]
   504                 ]
   499             ]);
   505             ]);
   500         $this->get('/api/v1/stats/themes/?limit=3')->assertTrue($this->response->isOk(), $this->response->content());
   506         $response = $this->get('/api/v1/stats/themes/?limit=3')->assertStatus(200);
   501         $this->seeJsonEquals(["themes" => [
   507         $response->assertJson(["themes" => [
   502             "http://ark.bnf.fr/ark:/12148/cb13318415c" => ['label' => 'professions', 'count' => 1412 ],
   508             "http://ark.bnf.fr/ark:/12148/cb13318415c" => ['label' => 'professions', 'count' => 1412 ],
   503             "http://ark.bnf.fr/ark:/12148/cb16604691s" => ['label' => 'travail non rémunéré', 'count' => 1092 ],
   509             "http://ark.bnf.fr/ark:/12148/cb16604691s" => ['label' => 'travail non rémunéré', 'count' => 1092 ],
   504             "http://ark.bnf.fr/ark:/12148/cb119339867" => ['label' => 'famille', 'count' => 1050 ]
   510             "http://ark.bnf.fr/ark:/12148/cb119339867" => ['label' => 'famille', 'count' => 1050 ]
   505         ], "meta" => ['total' => 999]]);
   511         ], "meta" => ['total' => 999]]);
   506 
   512 
   591                             "value" => 999
   597                             "value" => 999
   592                         ]
   598                         ]
   593                     ]
   599                     ]
   594                 ]
   600                 ]
   595             ]);
   601             ]);
   596         $this->get('/api/v1/stats/themes/?limit=3&index=1')->assertTrue($this->response->isOk(), $this->response->content());
   602         $response = $this->get('/api/v1/stats/themes/?limit=3&index=1')->assertStatus(200);
   597         $this->seeJsonEquals(["themes" => [
   603         $response->assertJson(["themes" => [
   598             "http://ark.bnf.fr/ark:/12148/cb11932889r" => ['label' => 'oiseaux', 'count' => 1003 ],
   604             "http://ark.bnf.fr/ark:/12148/cb11932889r" => ['label' => 'oiseaux', 'count' => 1003 ],
   599             "http://ark.bnf.fr/ark:/12148/cb11932496x" => ['label' => 'météorologie', 'count' => 1001 ],
   605             "http://ark.bnf.fr/ark:/12148/cb11932496x" => ['label' => 'météorologie', 'count' => 1001 ],
   600             "http://ark.bnf.fr/ark:/12148/cb11933145f" => ['label' => 'plantes', 'count' => 995  ]
   606             "http://ark.bnf.fr/ark:/12148/cb11933145f" => ['label' => 'plantes', 'count' => 995  ]
   601         ], "meta" => ['total' => 999]]);
   607         ], "meta" => ['total' => 999]]);
   602 
   608 
   687                             "value" => 999
   693                             "value" => 999
   688                         ]
   694                         ]
   689                     ]
   695                     ]
   690                 ]
   696                 ]
   691             ]);
   697             ]);
   692         $this->get('/api/v1/stats/themes/?limit=3&index=2')->assertTrue($this->response->isOk(), $this->response->content());
   698         $response = $this->get('/api/v1/stats/themes/?limit=3&index=2')->assertStatus(200);
   693         $this->seeJsonEquals(["themes" => [
   699         $response->assertJson(["themes" => [
   694             "http://ark.bnf.fr/ark:/12148/cb11930908q" => ['label' => 'animaux sauvages', 'count' => 989 ],
   700             "http://ark.bnf.fr/ark:/12148/cb11930908q" => ['label' => 'animaux sauvages', 'count' => 989 ],
   695             "http://ark.bnf.fr/ark:/12148/cb11934786x" => ['label' => 'arbres', 'count' => 989 ]
   701             "http://ark.bnf.fr/ark:/12148/cb11934786x" => ['label' => 'arbres', 'count' => 989 ]
   696         ], "meta" => ['total' => 999]]);
   702         ], "meta" => ['total' => 999]]);
   697     }
   703     }
   698 
   704