Exemplo n.º 1
0
 /**
  * @test
  */
 public function shouldUnshortenAGivenShortenedUrl()
 {
     $adapter = new Zend_Http_Client_Adapter_Test();
     $client = new Zend_Http_Client('http://adapter.org', array('adapter' => $adapter));
     $adapter->setResponse("HTTP/1.1 302 Found" . "\r\n" . "Location: http://zendframework.com" . "\r\n");
     $this->_service = new Recordshelf_Service_Isgd($client);
     $this->assertEquals('http://zendframework.com', $this->_service->unshorten('http://is.gd/1T35Q'));
 }
Exemplo n.º 2
0
 public function testGetAdapterWithConfig()
 {
     $httptest = new Zend_Http_Client_Adapter_Test();
     // Nirvanix adapter
     $nirvanixConfig = new Zend_Config_Ini(realpath(dirname(__FILE__) . '/_files/config/nirvanix.ini'));
     $nirvanixConfig = $nirvanixConfig->toArray();
     $nirvanixConfig[Zend_Cloud_StorageService_Adapter_Nirvanix::HTTP_ADAPTER] = $httptest;
     $doc = new DOMDocument('1.0', 'utf-8');
     $root = $doc->createElement('Response');
     $responseCode = $doc->createElement('ResponseCode', 0);
     $sessionTok = $doc->createElement('SessionToken', '54592180-7060-4D4B-BC74-2566F4B2F943');
     $root->appendChild($responseCode);
     $root->appendChild($sessionTok);
     $doc->appendChild($root);
     $body = $doc->saveXML();
     $resp = new Zend_Http_Response(200, array('Date' => 0), $body);
     $httptest->setResponse($resp);
     $nirvanixAdapter = Zend_Cloud_StorageService_Factory::getAdapter($nirvanixConfig);
     $this->assertEquals('Zend_Cloud_StorageService_Adapter_Nirvanix', get_class($nirvanixAdapter));
     // S3 adapter
     $s3Config = new Zend_Config_Ini(realpath(dirname(__FILE__) . '/_files/config/s3.ini'));
     $s3Adapter = Zend_Cloud_StorageService_Factory::getAdapter($s3Config);
     $this->assertEquals('Zend_Cloud_StorageService_Adapter_S3', get_class($s3Adapter));
     // file system adapter
     $fileSystemConfig = new Zend_Config_Ini(realpath(dirname(__FILE__) . '/_files/config/filesystem.ini'));
     $fileSystemAdapter = Zend_Cloud_StorageService_Factory::getAdapter($fileSystemConfig);
     $this->assertEquals('Zend_Cloud_StorageService_Adapter_FileSystem', get_class($fileSystemAdapter));
     // Azure adapter
     $azureConfig = new Zend_Config_Ini(realpath(dirname(__FILE__) . '/_files/config/windowsazure.ini'));
     $azureConfig = $azureConfig->toArray();
     $azureContainer = $azureConfig[Zend_Cloud_StorageService_Adapter_WindowsAzure::CONTAINER];
     $azureConfig[Zend_Cloud_StorageService_Adapter_WindowsAzure::HTTP_ADAPTER] = $httptest;
     $q = "?";
     $doc = new DOMDocument('1.0', 'utf-8');
     $root = $doc->createElement('EnumerationResults');
     $acctName = $doc->createAttribute('AccountName');
     $acctName->value = 'http://myaccount.blob.core.windows.net';
     $root->appendChild($acctName);
     $maxResults = $doc->createElement('MaxResults', 1);
     $containers = $doc->createElement('Containers');
     $container = $doc->createElement('Container');
     $containerName = $doc->createElement('Name', $azureContainer);
     $container->appendChild($containerName);
     $containers->appendChild($container);
     $root->appendChild($maxResults);
     $root->appendChild($containers);
     $doc->appendChild($root);
     $body = $doc->saveXML();
     $resp = new Zend_Http_Response(200, array('x-ms-request-id' => 0), $body);
     $httptest->setResponse($resp);
     $azureAdapter = Zend_Cloud_StorageService_Factory::getAdapter($azureConfig);
     $this->assertEquals('Zend_Cloud_StorageService_Adapter_WindowsAzure', get_class($azureAdapter));
 }
Exemplo n.º 3
0
 /**
  * Set up the test case
  *
  * @return void
  */
 public function setUp()
 {
     $this->rackspace = new Zend_Service_Rackspace_Files('foo', 'bar');
     $this->httpClientAdapterTest = new Zend_Http_Client_Adapter_Test();
     $this->rackspace->getHttpClient()->setAdapter($this->httpClientAdapterTest);
     // authentication (from a file)
     $this->httpClientAdapterTest->setResponse(self::loadResponse('../../_files/testAuthenticate'));
     $this->assertTrue($this->rackspace->authenticate(), 'Authentication failed');
     $this->metadata = array('foo' => 'bar', 'foo2' => 'bar2');
     $this->metadata2 = array('hello' => 'world');
     // load the HTTP response (from a file)
     $this->httpClientAdapterTest->setResponse($this->loadResponse($this->getName()));
 }
Exemplo n.º 4
0
 /**
  * Setup for each test
  */
 public function setUp()
 {
     $this->infrastructure = Zend_Cloud_Infrastructure_Factory::getAdapter(array(Zend_Cloud_Infrastructure_Factory::INFRASTRUCTURE_ADAPTER_KEY => 'Zend_Cloud_Infrastructure_Adapter_Ec2', Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_ACCESS_KEY => 'foo', Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_SECRET_KEY => 'bar', Zend_Cloud_Infrastructure_Adapter_Ec2::AWS_REGION => 'us-east-1'));
     $this->httpClientAdapterTest = new Zend_Http_Client_Adapter_Test();
     // load the HTTP response (from a file)
     $shortClassName = substr(__CLASS__, strlen('Zend_Cloud_Infrastructure_Adapter_'));
     $filename = dirname(__FILE__) . '/_files/' . $shortClassName . '_' . $this->getName() . '.response';
     if (file_exists($filename)) {
         $this->httpClientAdapterTest->setResponse($this->loadResponse($filename));
     }
     $adapter = $this->infrastructure->getAdapter();
     $client = new Zend_Http_Client(null, array('adapter' => $this->httpClientAdapterTest));
     call_user_func(array($adapter, 'setHttpClient'), $client);
 }
Exemplo n.º 5
0
 /**
  * Basic testing to ensure that tagSearch() works as expected
  *
  * @return void
  */
 public function testTagSearchBasic()
 {
     $this->_flickr->getRestClient()->getHttpClient()->setAdapter($this->_httpClientAdapterTest);
     $this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));
     $options = array('per_page' => 10, 'page' => 1, 'tag_mode' => 'or', 'extras' => 'license, date_upload, date_taken, owner_name, icon_server');
     $resultSet = $this->_flickr->tagSearch('php', $options);
     $this->assertEquals(4285, $resultSet->totalResultsAvailable);
     $this->assertEquals(10, $resultSet->totalResults());
     $this->assertEquals(10, $resultSet->totalResultsReturned);
     $this->assertEquals(1, $resultSet->firstResultPosition);
     $this->assertEquals(0, $resultSet->key());
     try {
         $resultSet->seek(-1);
     } catch (OutOfBoundsException $e) {
         $this->assertContains('Illegal index', $e->getMessage());
     }
     $resultSet->seek(9);
     try {
         $resultSet->seek(10);
     } catch (OutOfBoundsException $e) {
         $this->assertContains('Illegal index', $e->getMessage());
     }
     $resultSet->rewind();
     $resultSetIds = array('428222530', '427883929', '427884403', '427887192', '427883923', '427884394', '427883930', '427884398', '427883924', '427884401');
     $this->assertTrue($resultSet->valid());
     foreach ($resultSetIds as $resultSetId) {
         $this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__ . "-result_{$resultSetId}"));
         $result = $resultSet->current();
         $this->assertTrue($result instanceof Zend_Service_Flickr_Result);
         $resultSet->next();
     }
     $this->assertFalse($resultSet->valid());
 }
 /**
  * Setup for each test
  */
 public function setUp()
 {
     $this->infrastructure = Zend_Cloud_Infrastructure_Factory::getAdapter(array(Zend_Cloud_Infrastructure_Factory::INFRASTRUCTURE_ADAPTER_KEY => 'Zend_Cloud_Infrastructure_Adapter_Rackspace', Zend_Cloud_Infrastructure_Adapter_Rackspace::RACKSPACE_USER => 'foo', Zend_Cloud_Infrastructure_Adapter_Rackspace::RACKSPACE_KEY => 'bar', Zend_Cloud_Infrastructure_Adapter_Rackspace::RACKSPACE_REGION => 'USA'));
     $this->httpClientAdapterTest = new Zend_Http_Client_Adapter_Test();
     $this->infrastructure->getAdapter()->getHttpClient()->setAdapter($this->httpClientAdapterTest);
     // load the HTTP response (from a file)
     $shortClassName = 'RackspaceTest';
     $filename = dirname(__FILE__) . '/_files/' . $shortClassName . '_' . $this->getName() . '.response';
     if (file_exists($filename)) {
         // authentication (from file)
         $content = dirname(__FILE__) . '/_files/' . $shortClassName . '_testAuthenticate.response';
         $this->httpClientAdapterTest->setResponse($this->loadResponse($content));
         $this->assertTrue($this->infrastructure->getAdapter()->authenticate(), 'Authentication failed');
         $this->httpClientAdapterTest->setResponse($this->loadResponse($filename));
     }
 }
Exemplo n.º 7
0
 /**
  * @covers Robo47_Service_Gravatar::gravatarExists
  * @covers Robo47_Service_Gravatar::_getCacheId
  * @dataProvider gravatarExistsProvider
  */
 public function testGravatarExistsWithCache()
 {
     $cache = Zend_Cache::factory('Core', new Robo47_Cache_Backend_Array(), array('automatic_cleaning_factor' => 0), array('automatic_cleaning_factor' => 0));
     $options = array('cachePrefix' => 'foo_', 'cache' => $cache);
     $service = new Robo47_Service_Gravatar($options);
     // do first request
     $this->_adapter->setResponse(new Zend_Http_Response(404, array()));
     $this->assertSame(false, $service->gravatarExists('*****@*****.**'));
     $cacheEntry = $cache->load($service->getCacheId('*****@*****.**'));
     $this->assertEquals('false', $cacheEntry, 'wrong value in cache');
     // assert cache is used and no request is made
     $this->_adapter->setResponse(new Zend_Http_Response(200, array()));
     $this->assertSame(false, $service->gravatarExists('*****@*****.**'));
     $cacheEntry = $cache->load($service->getCacheId('*****@*****.**'));
     $this->assertEquals('false', $cacheEntry, 'wrong value in cache');
     // ignore cache for checking
     $this->_adapter->setResponse(new Zend_Http_Response(200, array()));
     $this->assertSame(true, $service->gravatarExists('*****@*****.**', false));
     $cacheEntry = $cache->load($service->getCacheId('*****@*****.**'));
     $this->assertEquals('true', $cacheEntry, 'wrong value in cache');
     // use cache for checking
     $this->_adapter->setResponse(new Zend_Http_Response(404, array()));
     $this->assertSame(true, $service->gravatarExists('*****@*****.**'));
     $cacheEntry = $cache->load($service->getCacheId('*****@*****.**'));
     $this->assertEquals('true', $cacheEntry, 'wrong value in cache');
     // ignore cache again for checking
     $this->_adapter->setResponse(new Zend_Http_Response(404, array()));
     $this->assertSame(false, $service->gravatarExists('*****@*****.**', false));
     $cacheEntry = $cache->load($service->getCacheId('*****@*****.**'));
     $this->assertEquals('false', $cacheEntry, 'wrong value in cache');
 }
Exemplo n.º 8
0
 /**
  * Test the authentication error (401 Unauthorized - Bad username or password)
  *
  * @return void
  */
 public function testAuthenticateError()
 {
     $this->_files->getHttpClient()->setAdapter($this->_httpClientAdapterTest);
     $this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));
     $this->assertFalse($this->_files->authenticate());
     $this->assertFalse($this->_files->isSuccessful());
     $this->assertEquals($this->_files->getErrorCode(), '401');
     $this->assertEquals($this->_files->getErrorMsg(), 'Bad username or password');
 }
Exemplo n.º 9
0
 /**
  * Import an invalid feed
  */
 protected function _importInvalid($filename)
 {
     $response = new Zend_Http_Response(200, array(), file_get_contents("{$this->_feedDir}/{$filename}"));
     $this->_adapter->setResponse($response);
     try {
         $feed = Zend_Feed::import('http://localhost');
     } catch (Exception $e) {
     }
     $this->assertTrue($e instanceof Zend_Feed_Exception, 'Expected Zend_Feed_Exception to be thrown');
 }
Exemplo n.º 10
0
 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
 {
     $request = new Test_Zend_Gdata_MockHttpClient_Request();
     $request->method = $method;
     $request->uri = $uri;
     $request->http_ver = $http_ver;
     $request->headers = $headers;
     $request->body = $body;
     array_push($this->_requests, $request);
     return parent::write($method, $uri, $http_ver, $headers, $body);
 }
Exemplo n.º 11
0
 /**
  * Ensures that userSearch() throws an exception when an invalid e-mail address is given
  *
  * @return void
  */
 public function testUserSearchExceptionEmailInvalid()
 {
     $this->_flickr->getRestClient()->getHttpClient()->setAdapter($this->_httpClientAdapterTest);
     $this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));
     try {
         $this->_flickr->userSearch('*****@*****.**');
         $this->fail('Expected Zend_Service_Exception not thrown');
     } catch (Zend_Service_Exception $e) {
         $this->assertContains('User not found', $e->getMessage());
     }
 }
Exemplo n.º 12
0
 /**
  * Imports an invalid feed
  */
 protected function _importInvalid($filename)
 {
     $response = new Zend_Http_Response(200, array(), file_get_contents("{$this->_feedDir}/{$filename}"));
     $this->_adapter->setResponse($response);
     try {
         $feed = Zend_Feed::import('http://localhost');
         $this->fail('Expected Zend_Feed_Exception not thrown');
     } catch (Zend_Feed_Exception $e) {
         $this->assertType('Zend_Feed_Exception', $e);
     }
 }
Exemplo n.º 13
0
 /**
  * Ensures that groupPoolGetPhotos() throws an exception when an invalid group_id is given
  *
  * @return void
  */
 public function testGroupPoolGetPhotosExceptionGroupIdInvalid()
 {
     $this->_flickr->getRestClient()->getHttpClient()->setAdapter($this->_httpClientAdapterTest);
     $this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));
     try {
         $this->_flickr->groupPoolGetPhotos('2e38a9d9425d7e2c9d0788455e9ccc61');
         $this->fail('Expected Zend_Service_Exception not thrown');
     } catch (Zend_Service_Exception $e) {
         $this->assertContains('Group not found', $e->getMessage());
     }
 }
Exemplo n.º 14
0
 public function testSettingNextResponseToAnInvalidIndex()
 {
     $indexes = array(-1, 1);
     foreach ($indexes as $i) {
         try {
             $this->adapter->setResponseIndex($i);
             $this->fail();
         } catch (\Exception $e) {
             $this->assertInstanceOf('Zend\\Http\\Client\\Adapter\\Exception', $e);
             $this->assertRegexp('/out of range/i', $e->getMessage());
         }
     }
 }
Exemplo n.º 15
0
 public function testWebSourceSearch()
 {
     $this->_bing->getHttpClient()->setAdapter($this->_httpClientAdapterTest);
     $this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));
     $searchResult = $this->_bing->search('tom graham', array('web' => array('count' => 10, 'offset' => 0)));
     $this->assertTrue($searchResult->hasSource('web'));
     // Check the source name isn't case sensitive
     $this->assertTrue($searchResult->hasSource('Web'));
     $resultSet = $searchResult->getSource('web');
     $this->assertType('Noginn_Service_Bing_WebResultSet', $resultSet);
     $this->assertEquals(10, count($resultSet));
     $this->assertEquals(25800000, $resultSet->getTotal());
     $this->assertEquals(0, $resultSet->getOffset());
     $this->assertEquals(0, $resultSet->key());
     // Attempt to seek below the lower bound
     try {
         $resultSet->seek(-1);
         $this->fail('Expected OutOfBoundsException not thrown');
     } catch (OutOfBoundsException $e) {
         $this->assertContains('Illegal index', $e->getMessage());
     }
     $resultSet->seek(9);
     // Attempt to seek above the upper bound
     try {
         $resultSet->seek(10);
         $this->fail('Expected OutOfBoundsException not thrown');
     } catch (OutOfBoundsException $e) {
         $this->assertContains('Illegal index', $e->getMessage());
     }
     $resultSet->rewind();
     $this->assertTrue($resultSet->valid());
     $result = $resultSet->current();
     $this->assertEquals('Thomas Graham and Sons', $result->getTitle());
     $this->assertEquals('Stockists of engineering fasteners and steel stock. The site gives information on the range of products and a history of the company.', $result->getDescription());
     $this->assertEquals('http://www.thomas-graham.co.uk/', $result->getUrl());
     $this->assertEquals('http://cc.bingj.com/cache.aspx?q=tom+graham&d=76275785218222&w=608c9417,5ee03831', $result->getCacheUrl());
     $this->assertEquals('www.thomas-graham.co.uk', $result->getDisplayUrl());
     $this->assertEquals('2009-06-21T09:09:36Z', $result->getDateTime());
 }
 public function testSettingNextResponseToAnInvalidIndex()
 {
     $indexes = array(-1, 1);
     foreach ($indexes as $i) {
         try {
             $this->adapter->setResponseIndex($i);
             $this->fail();
         } catch (Exception $e) {
             $class = 'Zend_Http_Client_Adapter_Exception';
             $this->assertType($class, $e);
             $this->assertRegexp('/out of range/i', $e->getMessage());
         }
     }
 }
Exemplo n.º 17
0
 /**
  * @covers Robo47_Service_Bitly::_callApi
  * @covers Robo47_Service_Bitly::_getData
  * @covers Robo47_Service_Bitly::shorten
  * @covers Robo47_Service_Bitly::expandByHash
  * @covers Robo47_Service_Bitly::expandByShortUrl
  * @covers Robo47_Service_Bitly::infoByHash
  * @covers Robo47_Service_Bitly::infoByHashWithKeys
  * @covers Robo47_Service_Bitly::infoByShortUrl
  * @covers Robo47_Service_Bitly::infoByShortUrlWithKeys
  * @covers Robo47_Service_Bitly::statsByHash
  * @covers Robo47_Service_Bitly::statsByShortUrl
  * @covers Robo47_Service_Bitly::errors
  * @dataProvider apiMethodsProvider
  */
 public function testApiMethods($method, $params, $format, $resultFormat)
 {
     $service = new Robo47_Service_Bitly('login', 'apiKey', $format, $resultFormat);
     $this->_adapter->setResponse($this->getResponse($format, $method));
     $result = call_user_func_array(array($service, $method), $params);
     $response = $service->getHttpClient()->request()->getBody();
     if ($format == Robo47_Service_Bitly::FORMAT_JSON) {
         if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_NATIVE) {
             $this->assertEquals($result, $response, 'Mismatch of result and response');
         } else {
             if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_ARRAY) {
                 $this->assertEquals($result, json_decode($response, true), 'Mismatch of result and response');
             } else {
                 if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_OBJECT) {
                     $this->assertEquals($result, json_decode($response, false), 'Mismatch of result and response');
                 } else {
                     $this->fail('invalid resultformat: ' . $resultFormat);
                 }
             }
         }
     } else {
         if ($format == Robo47_Service_Bitly::FORMAT_XML) {
             if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_NATIVE) {
                 $this->assertEquals($result, $response, 'Mismatch of result and response');
             } else {
                 if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_ARRAY) {
                     $this->assertEquals($result, $service->xmlToArray($response), 'Mismatch of result and response');
                 } else {
                     if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_OBJECT) {
                         $this->assertEquals($result, $service->xmlToObject($response), 'Mismatch of result and response');
                     } else {
                         $this->fail('invalid resultformat: ' . $resultFormat);
                     }
                 }
             }
         } else {
             $this->fail('invalid format: ' . $format);
         }
     }
 }
Exemplo n.º 18
0
 /**
  * Private method that queries REST service and returns SimpleXML response set
  *
  * @param  string $service name of Audioscrobbler service file we're accessing
  * @param  string $params  parameters that we send to the service if needded
  * @throws Zend_Http_Client_Exception
  * @throws Zend_Service_Exception
  * @return SimpleXMLElement result set
  */
 private function getInfo($service, $params = null)
 {
     $service = (string) $service;
     $params = (string) $params;
     if ($params === '') {
         $this->_client->setUri("http://ws.audioscrobbler.com{$service}");
     } else {
         $this->_client->setUri("http://ws.audioscrobbler.com{$service}?{$params}");
     }
     if ($this->_testing) {
         /**
          * @see Zend_Http_Client_Adapter_Test
          */
         require_once 'Zend/Http/Client/Adapter/Test.php';
         $adapter = new Zend_Http_Client_Adapter_Test();
         $this->_client->setConfig(array('adapter' => $adapter));
         $adapter->setResponse($this->_testingResponse);
     }
     $request = $this->_client->request();
     $response = $request->getBody();
     if ($response == 'No such path') {
         throw new Zend_Http_Client_Exception('Could not find: ' . $this->_client->getUri());
     } else {
         if ($response == 'No user exists with this name.') {
             throw new Zend_Http_Client_Exception('No user exists with this name');
         } else {
             if ($request->isError()) {
                 throw new Zend_Http_Client_Exception('The web service ' . $this->_client->getUri() . ' returned the following status code: ' . $response->getStatus());
             }
         }
     }
     set_error_handler(array($this, '_errorHandler'));
     if (!($simpleXmlElementResponse = simplexml_load_string($response))) {
         restore_error_handler();
         /**
          * @see Zend_Service_Exception
          */
         require_once 'Zend/Service/Exception.php';
         $exception = new Zend_Service_Exception('Response failed to load with SimpleXML');
         $exception->error = $this->_error;
         $exception->response = $response;
         throw $exception;
     }
     restore_error_handler();
     return $simpleXmlElementResponse;
 }
Exemplo n.º 19
0
 protected function setOkResponse($response)
 {
     $this->_adapter->setResponse("HTTP/1.1 200 OK" . "\r\n" . "Content-type: text/html" . "\r\n" . "\r\n" . $response);
 }
 /**
  * Check that recieving an unexpected response type throws an exception
  * 
  * @expectedException Zend_Service_Amazon_Ec2_Exception
  */
 public function testDisableZonesInvalidResponseType()
 {
     $this->_adapter->setResponse(self::_createResponseFromFile('response-enablezones-01.xml'));
     $this->_elb->disableAvailabilityZones('myLoadBalancer', 'us-east-1b');
 }
Exemplo n.º 21
0
 /**
  * @param string $responseMessage
  */
 protected function setAudioscrobblerResponse($responseMessage)
 {
     $this->_httpTestAdapter->setResponse($responseMessage);
 }
Exemplo n.º 22
0
 public function testSpellingSuggestion()
 {
     $this->_boss->getHttpClient()->setAdapter($this->_httpClientAdapterTest);
     $this->_httpClientAdapterTest->setResponse($this->_loadResponse(__FUNCTION__));
     $this->assertEquals('spelling', $this->_boss->getSpellingSuggestion('spellign'));
 }
Exemplo n.º 23
0
 /**
  * @group ZF-11184
  */
 public function testImportingUriWithEmptyResponseBodyTriggersException()
 {
     $currClient = Zend_Feed_Reader::getHttpClient();
     $testAdapter = new Zend_Http_Client_Adapter_Test();
     $testAdapter->setResponse(new Zend_Http_Response(200, array(), ''));
     Zend_Feed_Reader::setHttpClient(new Zend_Http_Client(null, array('adapter' => $testAdapter)));
     $this->setExpectedException('Zend_Feed_Exception', 'Feed failed to load');
     $result = Zend_Feed_Reader::import('http://www.example.com');
 }
 /**
  * @group ZF-8330
  */
 public function testGetsFeedLinksAndNormalisesRelativeUrlsOnUriWithPath()
 {
     try {
         $currClient = Zend_Feed_Reader::getHttpClient();
         $testAdapter = new Zend_Http_Client_Adapter_Test();
         $testAdapter->setResponse(new Zend_Http_Response(200, array(), '<!DOCTYPE html><html><head><link rel="alternate" type="application/rss+xml" href="../test.rss"><link rel="alternate" type="application/atom+xml" href="/test.atom"></head><body></body></html>'));
         Zend_Feed_Reader::setHttpClient(new Zend_Http_Client(null, array('adapter' => $testAdapter)));
         $links = Zend_Feed_Reader::findFeedLinks('http://foo/bar');
         Zend_Feed_Reader::setHttpClient($currClient);
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
     $this->assertEquals('http://foo/test.rss', $links->rss);
     $this->assertEquals('http://foo/test.atom', $links->atom);
 }
 public function testDownloadAttachmentShouldNotCallInsertFileWhen404()
 {
     global $filegallib;
     require_once 'lib/filegals/filegallib.php';
     $filegallib = $this->getMock('FileGalLib', array('insert_file'));
     $filegallib->expects($this->exactly(0))->method('insert_file');
     $adapter = new Zend_Http_Client_Adapter_Test();
     $adapter->setResponse("HTTP/1.1 404 NOT FOUND" . "\r\n" . "Content-type: image/jpg" . "\r\n" . "Content-length: 1034" . "\r\n" . "\r\n" . 'empty content');
     $client = new Zend_Http_Client();
     $client->setAdapter($adapter);
     $obj = $this->getMock('TikiImporter_Blog_Wordpress', array('getHttpClient', 'createFileGallery'));
     $obj->expects($this->once())->method('createFileGallery')->will($this->returnValue(1));
     $obj->expects($this->once())->method('getHttpClient')->will($this->returnValue($client));
     $obj->dom = new DOMDocument();
     $obj->dom->load(dirname(__FILE__) . '/fixtures/wordpress_attachments.xml');
     $this->expectOutputString("\n\nImporting attachments:\nUnable to download attachment tadv2.jpg. Error message was: 404 NOT FOUND\nUnable to download attachment 1881232-hostelaria-las-torres-0.jpg. Error message was: 404 NOT FOUND\nUnable to download attachment 1881259-caminhando-no-gelo-no-vale-do-sil-ncio-0.jpg. Error message was: 404 NOT FOUND\n0 attachments imported and 3 errors.\n");
     $obj->downloadAttachments();
     $this->assertEquals(array(), $obj->newFiles);
 }
 public function testNewsshortActionFail()
 {
     $adapter = new Zend_Http_Client_Adapter_Test();
     $adapter->setNextRequestWillFail(true);
     Zend_Feed::setHttpClient(new Zend_Http_Client(null, array('adapter' => $adapter)));
     $this->dispatch('/index/newsshort');
     $this->assertController('index');
     $this->assertAction('newsshort');
     $this->assertQuery('p.messagebox.warning');
 }
Exemplo n.º 27
0
 /**
  * Test that when the encodecookies flag is set to FALSE, cookies captured
  * from a response by Zend_Http_CookieJar are not encoded
  *
  * @group ZF-1850
  */
 public function testCaptureCookiesNoEncodeZF1850()
 {
     $cookieName = "cookieWithSpecialChars";
     $cookieValue = "HID=XXXXXX&UN=XXXXXXX&UID=XXXXX";
     $adapter = new Zend_Http_Client_Adapter_Test();
     $adapter->setResponse("HTTP/1.0 200 OK\r\n" . "Content-type: text/plain\r\n" . "Content-length: 2\r\n" . "Connection: close\r\n" . "Set-Cookie: {$cookieName}={$cookieValue}; path=/\r\n" . "\r\n" . "OK");
     $this->_client->setUri('http://example.example/test');
     $this->_client->setConfig(array('adapter' => $adapter, 'encodecookies' => false));
     $this->_client->setCookieJar();
     // First request is expected to set the cookie
     $this->_client->request();
     // Next request should contain the cookie
     $this->_client->request();
     $request = $this->_client->getLastRequest();
     if (!preg_match("/^Cookie: {$cookieName}=([^;]+)/m", $request, $match)) {
         $this->fail("Could not find cookie in request");
     }
     $this->assertEquals($cookieValue, $match[1]);
 }
Exemplo n.º 28
0
 /**
  *
  * Private method that queries REST service and returns SimpleXML response set
  * @param string $service name of Audioscrobbler service file we're accessing
  * @param string $params parameters that we send to the service if needded
  * @return SimpleXML result set
  */
 private function getInfo($service, $params = NULL)
 {
     $service = (string) $service;
     $params = (string) $params;
     try {
         if ($params == "") {
             $this->_client->setUri("http://ws.audioscrobbler.com{$service}");
         } else {
             $this->_client->setUri("http://ws.audioscrobbler.com{$service}?{$params}");
         }
         if ($this->testing == TRUE) {
             $adapter = new Zend_Http_Client_Adapter_Test();
             $this->_client->setConfig(array('adapter' => $adapter));
             $adapter->setResponse($this->testing_response);
         }
         $request = $this->_client->request();
         $response = $request->getBody();
         if ($response == 'No such path') {
             throw new Zend_Http_Client_Exception('Could not find: ' . $this->_client->getUri());
         } else {
             if ($response == 'No user exists with this name.') {
                 throw new Zend_Http_Client_Exception('No user exists with this name');
             } else {
                 if ($request->isError()) {
                     throw new Zend_Http_Client_Exception('The web service ' . $this->_client->getUri() . ' returned the following status code: ' . $response->getStatus());
                 } else {
                     return simplexml_load_string($response);
                 }
             }
         }
     } catch (Zend_Http_Client_Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 29
0
 /**
  * @group ZF-11599
  */
 public function testGetConfig()
 {
     $this->assertNotNull($this->adapter->getConfig());
 }
Exemplo n.º 30
0
 /**
  * @expectedException Zend_Gdata_App_HttpException
  */
 public function testGetAuthSubTokenInfoCatchesHttpClientException()
 {
     $adapter = new Zend_Http_Client_Adapter_Test();
     $adapter->setNextRequestWillFail(true);
     $client = new Zend_Gdata_HttpClient();
     $client->setUri('http://example.com/AuthSub');
     $client->setAdapter($adapter);
     $revoked = Zend_Gdata_AuthSub::getAuthSubTokenInfo($this->token, $client);
 }