partkeepr

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

UserPreferenceTest.php (1842B)


      1 <?php
      2 
      3 namespace PartKeepr\AuthBundle\Tests;
      4 
      5 use PartKeepr\CoreBundle\Tests\WebTestCase;
      6 
      7 class UserPreferenceTest extends WebTestCase
      8 {
      9     public function setUp()
     10     {
     11         $this->loadFixtures(
     12             [
     13                 'PartKeepr\AuthBundle\DataFixtures\LoadUserData',
     14             ]
     15         )->getReferenceRepository();
     16     }
     17 
     18     public function testPreferences()
     19     {
     20         $client = static::makeClient(true);
     21 
     22         $request = [
     23             'preferenceKey'   => 'foobar',
     24             'preferenceValue' => '1234',
     25         ];
     26 
     27         $client->request(
     28             'POST',
     29             '/api/user_preferences',
     30             [],
     31             [],
     32             ['CONTENT_TYPE' => 'application/json'],
     33             json_encode($request)
     34         );
     35 
     36         $response = json_decode($client->getResponse()->getContent());
     37 
     38         $this->assertInternalType('object', $response, var_export($client->getResponse()->getContent(), true));
     39 
     40         $this->assertObjectHasAttribute('preferenceKey', $response);
     41         $this->assertObjectHasAttribute('preferenceValue', $response);
     42         $this->assertEquals('foobar', $response->preferenceKey);
     43         $this->assertEquals('1234', $response->preferenceValue);
     44 
     45         $client->request(
     46             'GET',
     47             '/api/user_preferences',
     48             [],
     49             [],
     50             ['CONTENT_TYPE' => 'application/json']
     51         );
     52 
     53         $response = json_decode($client->getResponse()->getContent());
     54 
     55         $this->assertInternalType('array', $response);
     56 
     57         $preference = $response[0];
     58 
     59         $this->assertObjectHasAttribute('preferenceKey', $preference);
     60         $this->assertObjectHasAttribute('preferenceValue', $preference);
     61         $this->assertEquals('foobar', $preference->preferenceKey);
     62         $this->assertEquals('1234', $preference->preferenceValue);
     63     }
     64 }