markTestSkipped('Testing Zend_Service_ShortUrl_BitLyTest only works when TESTS_ZEND_SERVICE_SHORTURL_BITLY_ENABLED is set.'); } Zend_Service_Abstract::setHttpClient(new Zend_Http_Client()); } public function testShortenEmptyUrlException() { $this->setExpectedException('Zend_Service_ShortUrl_Exception'); $s = new Zend_Service_ShortUrl_BitLy('test'); $s->shorten(''); } public function testShortenIncorrectUrlException() { $this->setExpectedException('Zend_Service_ShortUrl_Exception'); $s = new Zend_Service_ShortUrl_BitLy('test'); $s->shorten('wrongAdress.cccc'); } public function testExceptionOnBadApiResponse() { $this->setExpectedException('Zend_Service_ShortUrl_Exception'); $clientResponse = $this->getMock('Zend_Http_Response', array(), array(), '', false); $clientResponse->expects($this->once())->method('getStatus')->will($this->returnValue(500)); $client = $this->getMock('Zend_Http_Client', array(), array(), '', false); $client->expects($this->once())->method('request')->will($this->returnValue($clientResponse)); $s = new Zend_Service_ShortUrl_BitLy('test'); $s->setHttpClient($client); $s->shorten('http://framework.zend.com'); } public function testAuthenticationWithAccessToken() { $accessToken = 'test'; $clientResponse = $this->getMock('Zend_Http_Response', array(), array(), '', false); $clientResponse->expects($this->once())->method('getStatus')->will($this->returnValue(200)); $clientResponse->expects($this->once())->method('getBody')->will($this->returnValue('http://bit.ly/ZFramework')); $client = $this->getMock('Zend_Http_Client', array(), array(), '', false); $client->expects($this->any())->method('setParameterGet')->with($this->anything(),$this->anything()); $client->expects($this->at(0))->method('setParameterGet')->with('access_token',$accessToken); $client->expects($this->once())->method('request')->will($this->returnValue($clientResponse)); $s = new Zend_Service_ShortUrl_BitLy($accessToken); $s->setHttpClient($client); $s->shorten('http://framework.zend.com'); } public function testAuthenticationWithUserCredentials() { $login = 'test'; $apiKey = 'api'; $clientResponse = $this->getMock('Zend_Http_Response', array(), array(), '', false); $clientResponse->expects($this->once())->method('getStatus')->will($this->returnValue(200)); $clientResponse->expects($this->once())->method('getBody')->will($this->returnValue('http://bit.ly/ZFramework')); $client = $this->getMock('Zend_Http_Client', array(), array(), '', false); $client->expects($this->any())->method('setParameterGet')->with($this->anything(),$this->anything()); $client->expects($this->at(0))->method('setParameterGet')->with('login',$login); $client->expects($this->at(1))->method('setParameterGet')->with('apiKey',$apiKey); $client->expects($this->once())->method('request')->will($this->returnValue($clientResponse)); $s = new Zend_Service_ShortUrl_BitLy($login, $apiKey); $s->setHttpClient($client); $s->shorten('http://framework.zend.com'); } }