/**
  * Test method for the <tt>toJSON()</tt> function.
  */
 public function testToJSON()
 {
     $setTagsRequest = new SetTagsRequest();
     // Test without the 'application' parameter set
     try {
         $setTagsRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'hwid' parameter set
     $setTagsRequest->setApplication('APPLICATION');
     try {
         $setTagsRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'tags' parameter set
     $setTagsRequest->setHwid('HWID');
     try {
         $setTagsRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     $setTagsRequest->setTags(array('tag0' => 'tag0_value', 'tag1' => 'tag1_value', 'tag2' => 'tag2_value'));
     // Test with valid values
     $array = $setTagsRequest->toJSON();
     $this->assertEquals('APPLICATION', $setTagsRequest->getApplication());
     $this->assertEquals('HWID', $setTagsRequest->getHwid());
     $tags = $array['tags'];
     $this->assertCount(3, $tags);
     $this->assertTrue(array_key_exists('tag0', $tags));
     $this->assertTrue(array_key_exists('tag1', $tags));
     $this->assertTrue(array_key_exists('tag2', $tags));
     $this->assertEquals('tag0_value', $tags['tag0']);
     $this->assertEquals('tag1_value', $tags['tag1']);
     $this->assertEquals('tag2_value', $tags['tag2']);
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function setTags(SetTagsRequest $setTagsRequest)
 {
     // If the 'application' attribute is not set in the request we try to get a default one from the Pushwoosh
     // client
     if ($setTagsRequest->getApplication() === null) {
         // The 'application' must be set
         if (!isset($this->application)) {
             throw new PushwooshException('The  \'application\' property is not set !');
         }
         $setTagsRequest->setApplication($this->application);
     }
     $response = $this->cURLClient->pushwooshCall('setTags', $setTagsRequest->jsonSerialize());
     return SetTagsResponse::create($response);
 }
Esempio n. 3
0
 /**
  * Test method for the <tt>setTags($setTagsRequest)</tt> function.
  *
  * @group PushwooshTest.setTags
  */
 public function testSetTags()
 {
     // Create a fake CURL client
     $cURLClient = $this->getMock('Gomoob\\Pushwoosh\\ICURLClient');
     $cURLClient->expects($this->any())->method('pushwooshCall')->will($this->returnValue(array('status_code' => 200, 'status_message' => 'OK')));
     $pushwoosh = new Pushwoosh();
     $pushwoosh->setCURLClient($cURLClient);
     $setTagsRequest = SetTagsRequest::create()->setHwid('hwid')->setTag('tag0', 'tag0Value')->setTag('tag1', 'tag1Value');
     // Test with the 'application' parameter not defined
     try {
         $pushwoosh->setTags($setTagsRequest);
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test with the 'application' parameter defined in the Pushwoosh client
     $pushwoosh->setApplication('APPLICATION');
     $setTagsRequest->setApplication(null);
     $pushwoosh->setTags($setTagsRequest);
     // Test with the 'application' parameter definied in the request
     $pushwoosh->setApplication(null);
     $setTagsRequest->setApplication('APPLICATION');
     $setTagsResponse = $pushwoosh->setTags($setTagsRequest);
     $this->assertTrue($setTagsResponse->isOk());
     $this->assertEquals(200, $setTagsResponse->getStatusCode());
     $this->assertEquals('OK', $setTagsResponse->getStatusMessage());
     // Test a call with an error response
     $cURLClient = $this->getMock('Gomoob\\Pushwoosh\\ICURLClient');
     $cURLClient->expects($this->any())->method('pushwooshCall')->will($this->returnValue(array('status_code' => 400, 'status_message' => 'KO')));
     $pushwoosh->setCURLClient($cURLClient);
     $setTagsResponse = $pushwoosh->setTags($setTagsRequest);
     $this->assertFalse($setTagsResponse->isOk());
     $this->assertEquals(400, $setTagsResponse->getStatusCode());
     $this->assertEquals('KO', $setTagsResponse->getStatusMessage());
 }