SystemPreferenceTest.php (1860B)
1 <?php 2 3 namespace PartKeepr\SystemPreferenceBundle\Tests; 4 5 use PartKeepr\CoreBundle\Tests\WebTestCase; 6 use PartKeepr\SystemPreferenceBundle\Exceptions\SystemPreferenceNotFoundException; 7 8 class SystemPreferenceTest extends WebTestCase 9 { 10 public function setUp() 11 { 12 $this->loadFixtures([]); 13 } 14 15 public function testSystemPreferenceService() 16 { 17 $this->getContainer()->get("partkeepr.system_preference_service")->setSystemPreference("foo", "bar"); 18 19 $this->assertEquals("bar", $this->getContainer()->get("partkeepr.system_preference_service")->getSystemPreferenceValue("foo")); 20 21 $this->getContainer()->get("partkeepr.system_preference_service")->setSystemPreference("foo", "bar2"); 22 23 $this->assertEquals("bar2", $this->getContainer()->get("partkeepr.system_preference_service")->getSystemPreferenceValue("foo")); 24 25 $preference = $this->getContainer()->get("partkeepr.system_preference_service")->getPreference("foo"); 26 $this->assertEquals("foo", $preference->getPreferenceKey()); 27 28 $this->expectException(SystemPreferenceNotFoundException::class); 29 $this->assertEquals("bar2", $this->getContainer()->get("partkeepr.system_preference_service")->getSystemPreferenceValue("foo2")); 30 } 31 32 public function testSystemPreferenceCreate() 33 { 34 $client = static::makeClient(true); 35 36 $parameters = [ 37 "preferenceKey" => "foobar", 38 "@type" => "SystemPreference", 39 "preferenceValue" => "test", 40 ]; 41 42 // First test: Ensure invalid auth key is returned 43 $client->request( 44 'POST', 45 '/api/system_preferences', 46 [], 47 [], 48 [], 49 json_encode($parameters) 50 ); 51 52 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 53 } 54 }