Exemplo n.º 1
0
 /**
  * Test method for the <tt>toJSON()</tt> function.
  */
 public function testToJSON()
 {
     $getTagsRequest = new GetTagsRequest();
     // Test without the 'application' parameter set
     try {
         $getTagsRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'auth' parameter set
     $getTagsRequest->setApplication('APPLICATION');
     try {
         $getTagsRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test without the 'hwid' parameter set
     $getTagsRequest->setAuth('XXXXXXXX');
     try {
         $getTagsRequest->toJSON();
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     $getTagsRequest->setHwid('HWID');
     // Test with valid values
     $array = $getTagsRequest->toJSON();
     $this->assertEquals('APPLICATION', $array['application']);
     $this->assertEquals('XXXXXXXX', $array['auth']);
     $this->assertEquals('HWID', $array['hwid']);
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function getTags(GetTagsRequest $getTagsRequest)
 {
     // If the 'application' attribute is not set in the request we try to get a default one from the Pushwoosh
     // client
     if ($getTagsRequest->getApplication() === null) {
         // The 'application' must be set
         if (!isset($this->application)) {
             throw new PushwooshException('The  \'application\' property is not set !');
         }
         $getTagsRequest->setApplication($this->application);
     }
     // If the 'auth' parameter is not set in the request we try to get it from the Pushwoosh client
     if ($getTagsRequest->getAuth() === null) {
         // The 'auth' parameter is expected here
         if (!isset($this->auth)) {
             throw new PushwooshException('The \'auth\' parameter is not set !');
             // Use the 'auth' parameter defined in the Pushwoosh client
         } else {
             $getTagsRequest->setAuth($this->auth);
         }
     }
     $response = $this->cURLClient->pushwooshCall('getTags', $getTagsRequest->jsonSerialize());
     return GetTagsResponse::create($response);
 }
Exemplo n.º 3
0
 /**
  * Test method for the <tt>getTags($getTagsRequest)</tt> function.
  */
 public function testGetTags()
 {
     // 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', 'response' => array('result' => array('tag0' => 'tag0Value', 'tag1' => 'tag1Value', 'tag2' => 'tag2Value')))));
     $pushwoosh = new Pushwoosh();
     $pushwoosh->setCURLClient($cURLClient);
     $getTagsRequest = GetTagsRequest::create()->setHwid('HWID');
     // Test with the 'application' parameter not defined
     try {
         $pushwoosh->getTags($getTagsRequest);
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test with the 'auth' parameter not defined
     $pushwoosh->setApplication('APPLICATION');
     try {
         $pushwoosh->getTags($getTagsRequest);
         $this->fail('Must have thrown a PushwooshException !');
     } catch (PushwooshException $pe) {
         // Expected
     }
     // Test with the 'application' and 'auth' parameters definied in the Pushwoosh client
     $pushwoosh->setApplication('APPLICATION');
     $pushwoosh->setAuth('AUTH');
     $getTagsRequest->setApplication(null);
     $getTagsRequest->setAuth(null);
     $pushwoosh->getTags($getTagsRequest);
     // Test with the 'application' and 'auth' parameters definied in the request
     $pushwoosh->setApplication(null);
     $pushwoosh->setAuth(null);
     $getTagsRequest->setApplication('APPLICATION');
     $getTagsRequest->setAuth('AUTH');
     $pushwoosh->getTags($getTagsRequest);
     // Test with the 'application' defined in the Pushwoosh client and the 'auth' parameter defined in the request
     $pushwoosh->setApplication('APPLICATION');
     $pushwoosh->setAuth(null);
     $getTagsRequest->setApplication(null);
     $getTagsRequest->setAuth('AUTH');
     $pushwoosh->getTags($getTagsRequest);
     // Test with the 'application' defined in the request and the 'auth' parameter defined in the Pushwoosh client
     $pushwoosh->setApplication(null);
     $pushwoosh->setAuth('AUTH');
     $getTagsRequest->setApplication('APPLICATION');
     $getTagsRequest->setAuth(null);
     $getTagsResponse = $pushwoosh->getTags($getTagsRequest);
     $getTagsResponseResponse = $getTagsResponse->getResponse();
     $this->assertNotNull($getTagsResponseResponse);
     $result = $getTagsResponseResponse->getResult();
     $this->assertCount(3, $result);
     $this->assertEquals('tag0Value', $result['tag0']);
     $this->assertEquals('tag1Value', $result['tag1']);
     $this->assertEquals('tag2Value', $result['tag2']);
     $tags = $getTagsResponseResponse->getTags();
     $this->assertCount(3, $tags);
     $this->assertEquals('tag0Value', $tags['tag0']);
     $this->assertEquals('tag1Value', $tags['tag1']);
     $this->assertEquals('tag2Value', $tags['tag2']);
     $this->assertTrue($getTagsResponseResponse->hasTag('tag0'));
     $this->assertTrue($getTagsResponseResponse->hasTag('tag1'));
     $this->assertTrue($getTagsResponseResponse->hasTag('tag2'));
     $this->assertTrue($getTagsResponse->isOk());
     $this->assertEquals(200, $getTagsResponse->getStatusCode());
     $this->assertEquals('OK', $getTagsResponse->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);
     $getTagsResponse = $pushwoosh->getTags($getTagsRequest);
     $this->assertFalse($getTagsResponse->isOk());
     $this->assertEquals(400, $getTagsResponse->getStatusCode());
     $this->assertEquals('KO', $getTagsResponse->getStatusMessage());
 }