コード例 #1
0
 /**
  * Test method for the <tt>toJSON()</tt> function.
  */
 public function testToJSON()
 {
     $registerDeviceRequest = new RegisterDeviceRequest();
     // Test without the 'application' parameter set
     try {
         $registerDeviceRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'deviceType' parameter set
     $registerDeviceRequest->setApplication('APPLICATION');
     try {
         $registerDeviceRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test with a bad 'deviceType' parameter set (special value 6)
     $registerDeviceRequest->setDeviceType(6);
     try {
         $registerDeviceRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test with a bad 'deviceType' parameter set
     $registerDeviceRequest->setDeviceType(100);
     try {
         $registerDeviceRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'hwid' parameter set
     $registerDeviceRequest->setDeviceType(1);
     try {
         $registerDeviceRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'pushToken' parameter set
     $registerDeviceRequest->setHwid('HWID');
     try {
         $registerDeviceRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'timezone' parameter set
     $registerDeviceRequest->setPushToken('PUSH_TOKEN');
     $registerDeviceRequest->setTimezone(3600);
     // Test without the 'language' parameter set
     $array = $registerDeviceRequest->toJSON();
     $this->assertEquals('APPLICATION', $array['application']);
     $this->assertEquals(1, $array['device_type']);
     $this->assertEquals('HWID', $array['hwid']);
     $this->assertNull($array['language']);
     $this->assertEquals('PUSH_TOKEN', $array['push_token']);
     $this->assertEquals(3600, $array['timezone']);
     // Test with the 'language' parameter set
     $registerDeviceRequest->setLanguage('fr');
     $array = $registerDeviceRequest->toJSON();
     $this->assertEquals('APPLICATION', $array['application']);
     $this->assertEquals(1, $array['device_type']);
     $this->assertEquals('HWID', $array['hwid']);
     $this->assertEquals('fr', $array['language']);
     $this->assertEquals('PUSH_TOKEN', $array['push_token']);
     $this->assertEquals(3600, $array['timezone']);
     // Test that all the supported device types does not fail
     $registerDeviceRequest->setDeviceType(1)->toJSON();
     $registerDeviceRequest->setDeviceType(2)->toJSON();
     $registerDeviceRequest->setDeviceType(3)->toJSON();
     $registerDeviceRequest->setDeviceType(4)->toJSON();
     $registerDeviceRequest->setDeviceType(5)->toJSON();
     $registerDeviceRequest->setDeviceType(7)->toJSON();
     $registerDeviceRequest->setDeviceType(8)->toJSON();
     $registerDeviceRequest->setDeviceType(9)->toJSON();
     $registerDeviceRequest->setDeviceType(10)->toJSON();
 }