adapter = new Zend_Http_Client_Adapter_Test(); $this->client = new Zend_Http_Client(); $this->client->setAdapter($this->adapter); $this->mpns = new Zend_Mobile_Push_Mpns(); $this->mpns->setHttpClient($this->client); } public function getMessage($type) { switch ($type) { case 'tile': $message = new Zend_Mobile_Push_Message_Mpns_Tile(); break; case 'toast': $message = new Zend_Mobile_Push_Message_Mpns_Toast(); break; default: $message = new Zend_Mobile_Push_Message_Mpns_Raw(); $message->setMessage(''); } $message->setToken('http://this.is.a.url.com'); return $message; } public function testGetHttpClientReturnsDefault() { $mpns = new Zend_Mobile_Push_Mpns(); $this->assertEquals('Zend_Http_Client', get_class($mpns->getHttpClient())); $this->assertTrue($mpns->getHttpClient() instanceof Zend_Http_Client); } public function testSetHttpClient() { $client = new Zend_Http_Client(); $this->mpns->setHttpClient($client); $this->assertEquals($client, $this->mpns->getHttpClient()); } /** * @expectedException Zend_Mobile_Push_Exception */ public function testSendThrowsExceptionWithNonValidMessage() { $msg = new Zend_Mobile_Push_Message_Mpns_Tile(); $this->mpns->send($msg); } /** * @expectedException Zend_Mobile_Push_Exception_DeviceQuotaExceeded */ public function testSendThrowsExceptionWhenDeviceQuotaExceeded() { $this->adapter->setResponse('HTTP/1.1 200 OK' . "\r\n" . 'NotificationStatus: QueueFull' . "\r\n\r\n"); $this->mpns->send($this->getMessage('raw')); } /** * @expectedException Zend_Mobile_Push_Exception_InvalidPayload */ public function testSendThrowsExceptionWhenInvalidPayload() { $this->adapter->setResponse('HTTP/1.1 400 Bad Request' . "\r\n\r\n"); $this->mpns->send($this->getMessage('raw')); } /** * @expectedException Zend_Mobile_Push_Exception_InvalidToken */ public function testSendThrowsExceptionWhenInvalidToken() { $this->adapter->setResponse('HTTP/1.1 401 Unauthorized' . "\r\n\r\n"); $this->mpns->send($this->getMessage('raw')); } /** * @expectedException Zend_Mobile_Push_Exception_InvalidToken */ public function testSendThrowsExceptionWhenDeviceNotRegistered() { $this->adapter->setResponse('HTTP/1.1 404 Not Found' . "\r\n\r\n"); $this->mpns->send($this->getMessage('raw')); } /** * @expectedException Zend_Mobile_Push_Exception */ public function testSendThrowsExceptionWhenMethodNotPost() { $this->adapter->setResponse('HTTP/1.1 405 Method Not Allowed' . "\r\n\r\n"); $this->mpns->send($this->getMessage('raw')); } /** * @expectedException Zend_Mobile_Push_Exception_QuotaExceeded */ public function testSendThrowsExceptionWhenServiceQuotaExceeded() { $this->adapter->setResponse('HTTP/1.1 406 Not Acceptable'); $this->mpns->send($this->getMessage('raw')); } /** * @expectedException Zend_Mobile_Push_Exception_InvalidToken */ public function testSendThrowsExceptionWhenInvalidToken2() { $this->adapter->setResponse('HTTP/1.1 412 Precondition Failed' . "\r\n\r\n"); $this->mpns->send($this->getMessage('raw')); } /** * @expectedException Zend_Mobile_Push_Exception_ServerUnavailable */ public function testSendThrowsExceptionWhenServerUnavailable() { $this->adapter->setResponse('HTTP/1.1 503 Service Unavailable' . "\r\n\r\n"); $this->mpns->send($this->getMessage('raw')); } public function testAllOk() { $this->adapter->setResponse('HTTP/1.1 200 OK' . "\r\n\r\n"); $this->mpns->send($this->getMessage('raw')); $toast = $this->getMessage('toast'); $toast->setTitle('Foo'); $toast->setMessage('Bar'); $this->mpns->send($toast); $tile = $this->getMessage('tile'); $tile->setBackgroundImage('red.jpg'); $tile->setCount(1); $tile->setTitle('Foo Bar'); // other optional attributes for wp7.1+ $tile->setTileId('/SomeAction.xaml'); $tile->setBackBackgroundImage('blue.jpg'); $tile->setBackTitle('Bar'); $tile->setBackContent('Foo'); } }