示例#1
0
 /**
  * @covers mychaelstyle\storage\providers\AmazonS3::get
  * @covers mychaelstyle\storage\providers\AmazonS3::__mergePutOptions
  * @covers mychaelstyle\storage\providers\AmazonS3::__formatUri
  * @expectedException mychaelstyle\Exception
  */
 public function testGetFail()
 {
     if ($this->markIncompleteIfNoNetwork()) {
         return true;
     }
     // not exists
     $result = $this->object->get('notexist.txt');
     $this->assertNull($result);
 }
 /**
  * testGetBuggyXmlException
  *
  * @return void
  * @author Rob Mcvey
  * @expectedException AmazonS3Exception
  * @expectedExceptionMessage There was an error communicating with AWS
  **/
 public function testGetBuggyXmlException()
 {
     $localPath = APP . 'Plugin' . DS . 'AmazonS3' . DS . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'files';
     $file = 'lolcat.jpg';
     $fullpath = $localPath . DS . $file;
     $this->AmazonS3->setDate('Mon, 23 Sep 2013 08:46:05 GMT');
     // Mock the built request
     $expectedRequest = array('method' => 'GET', 'uri' => array('host' => 'bucket.s3.amazonaws.com', 'scheme' => 'https', 'path' => 'lolcat.jpg'), 'header' => array('Accept' => '*/*', 'User-Agent' => 'CakePHP', 'Date' => 'Mon, 23 Sep 2013 08:46:05 GMT', 'Authorization' => 'AWS foo:+UdJAQGhwJf06KRWWIXumX/5V4Y='));
     // Mock the HttpSocket response
     $HttpSocketResponse = new stdClass();
     $HttpSocketResponse->body = '<?xml version="1.0" encoding="UTF-8"?><Error><Code>Woops</Code><RequestId>2342134123</RequestId><HostId>DFHGDHGDHDFGH</HostId><AWSAccessKeyId>foo</AWSAccessKeyId></Error>';
     $HttpSocketResponse->code = 403;
     $HttpSocketResponse->headers = array('x-amz-id-2' => '4589328529385938', 'x-amz-request-id' => 'GSDFGt45egdfsC', 'Date' => 'Mon, 23 Sep 2013 08:46:05 GMT', 'Accept-Ranges' => 'bytes', 'Content-Type' => 'application/xml', 'Transfer-Encoding' => 'chunked', 'Connection' => 'close', 'Server' => 'AmazonS3');
     // Mock the HttpSocket class
     $this->AmazonS3->HttpSocket = $this->getMock('HttpSocket');
     $this->AmazonS3->HttpSocket->expects($this->once())->method('request')->with()->will($this->returnValue($HttpSocketResponse));
     $this->AmazonS3->get($file, $localPath);
     $this->assertFalse(file_exists($fullpath));
     unlink($fullpath);
     // Bye bye just in case
 }