partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

TipOfTheDayTest.php (2515B)


      1 <?php
      2 
      3 namespace PartKeepr\TipOfTheDayBundle\Tests;
      4 
      5 use Doctrine\Common\DataFixtures\ProxyReferenceRepository;
      6 use Dunglas\ApiBundle\Api\IriConverter;
      7 use PartKeepr\CoreBundle\Tests\WebTestCase;
      8 
      9 class TipOfTheDayTest extends WebTestCase
     10 {
     11     /**
     12      * @var ProxyReferenceRepository
     13      */
     14     protected $fixtures;
     15 
     16     public function setUp()
     17     {
     18         $this->fixtures = $this->loadFixtures(
     19             [
     20                 'PartKeepr\TipOfTheDayBundle\DataFixtures\TipOfTheDayLoader',
     21                 'PartKeepr\AuthBundle\DataFixtures\LoadUserData',
     22             ]
     23         )->getReferenceRepository();
     24     }
     25 
     26     public function testTips()
     27     {
     28         $client = static::makeClient(true);
     29 
     30         $tip = $this->fixtures->getReference('tipoftheday');
     31 
     32         /**
     33          * @var IriConverter
     34          */
     35         $iriConverter = $this->getContainer()->get('api.iri_converter');
     36 
     37         $iri = $iriConverter->getIriFromItem($tip);
     38         $iri .= '/markTipRead';
     39 
     40         $client->request(
     41             'PUT',
     42             $iri
     43         );
     44 
     45         $response = json_decode($client->getResponse()->getContent());
     46 
     47         $this->assertObjectHasAttribute('name', $response);
     48         $this->assertObjectHasAttribute('@type', $response);
     49 
     50         $this->assertEquals('TipOfTheDay', $response->{'@type'});
     51         $this->assertEquals('FOO', $response->name);
     52 
     53         $client->request(
     54             'GET',
     55             '/api/tip_of_the_day_histories'
     56         );
     57 
     58         $response = json_decode($client->getResponse()->getContent());
     59 
     60         $this->assertObjectHasAttribute('@type', $response);
     61         $this->assertObjectHasAttribute('hydra:member', $response);
     62 
     63         $this->assertEquals('hydra:Collection', $response->{'@type'});
     64 
     65         $this->assertArrayHasKey(0, $response->{'hydra:member'});
     66         $this->assertEquals('FOO', $response->{'hydra:member'}[0]->name);
     67 
     68         $client->request(
     69             'POST',
     70             '/api/tip_of_the_days/markAllTipsAsUnread'
     71         );
     72 
     73         $this->assertEquals('OK', $client->getResponse()->getContent());
     74 
     75         $client->request(
     76             'GET',
     77             '/api/tip_of_the_day_histories'
     78         );
     79 
     80         $response = json_decode($client->getResponse()->getContent());
     81 
     82         $this->assertObjectHasAttribute('@type', $response);
     83         $this->assertObjectHasAttribute('hydra:member', $response);
     84 
     85         $this->assertEquals('hydra:Collection', $response->{'@type'});
     86 
     87         $this->assertEquals(0, count($response->{'hydra:member'}));
     88     }
     89 }