コード例 #1
0
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlobSnapshot
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createPageBlob
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::deleteBlob
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getBlob
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::listBlobs
  */
 private function deleteBlobWorker($options, $container)
 {
     $blob = BlobServiceFunctionalTestData::getInterestingBlobName($container);
     // Make sure there is something to test
     $dataSize = 512;
     $this->restProxy->createPageBlob($container, $blob, $dataSize);
     $snapshot = $this->restProxy->createBlobSnapshot($container, $blob);
     $this->restProxy->createBlobSnapshot($container, $blob);
     $blobinfo = $this->restProxy->getBlob($container, $blob);
     if (!is_null($options)) {
         BlobServiceFunctionalTestData::fixETagAccessCondition($options->getAccessCondition(), $blobinfo->getProperties()->getETag());
         $options->setSnapshot(is_null($options->getSnapshot()) ? null : $snapshot->getSnapshot());
     }
     $deleted = false;
     try {
         if (is_null($options)) {
             $this->restProxy->deleteBlob($container, $blob);
         } else {
             $this->restProxy->deleteBlob($container, $blob, $options);
         }
         $deleted = true;
         if (is_null($options)) {
             $options = new DeleteBlobOptions();
         }
         if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
             $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
         }
         if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
             $this->assertTrue(false, 'Expect failing temporal access condition should throw');
         }
         if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
             $this->assertTrue(false, 'Expect failing etag access condition to throw');
         }
         $listOptions = new ListBlobsOptions();
         $listOptions->setIncludeSnapshots(true);
         $listOptions->setPrefix($blob);
         $listBlobsResult = $this->restProxy->listBlobs($container == '' ? '$root' : $container, $listOptions);
         $blobs = $listBlobsResult->getBlobs();
         $this->verifyDeleteBlobWorker($options, $blobs);
     } catch (ServiceException $e) {
         if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
             $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'bad timeout: deleteHttpStatusCode');
         } else {
             if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
                 $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'bad temporal access condition IF_UNMODIFIED_SINCE: deleteHttpStatusCode');
             } else {
                 if (!BlobServiceFunctionalTestData::passETagAccessCondition($options->getAccessCondition())) {
                     $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'bad etag access condition: deleteHttpStatusCode');
                 } else {
                     throw $e;
                 }
             }
         }
     }
     // Clean up.
     if (!$deleted) {
         $this->restProxy->deleteBlob($container, $blob);
     }
 }
コード例 #2
0
 public static function getDeleteBlobOptions()
 {
     $ret = array();
     $options = new DeleteBlobOptions();
     array_push($ret, $options);
     $options = new DeleteBlobOptions();
     $options->setTimeout(10);
     array_push($ret, $options);
     $options = new DeleteBlobOptions();
     $options->setTimeout(-10);
     array_push($ret, $options);
     foreach (self::getAllAccessConditions() as $ac) {
         $options = new DeleteBlobOptions();
         $options->setAccessCondition($ac);
         array_push($ret, $options);
     }
     $options = new DeleteBlobOptions();
     $options->setDeleteSnaphotsOnly(true);
     array_push($ret, $options);
     $options = new DeleteBlobOptions();
     $options->setDeleteSnaphotsOnly(false);
     array_push($ret, $options);
     $options = new DeleteBlobOptions();
     $options->setSnapshot('placeholder');
     array_push($ret, $options);
     // TODO: Handle Lease ID
     //        $options = new DeleteBlobOptions();
     //        $options->setLeaseId('setLeaseId');
     //        array_push($ret, $options);
     return $ret;
 }
コード例 #3
0
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::deleteBlob
  */
 public function testDeleteBlobSnapshotsOnly()
 {
     // Setup
     $name = 'deleteblobsnapshotsonly' . $this->createSuffix();
     $blob = 'myblob';
     $contentType = 'text/plain; charset=UTF-8';
     $this->createContainer($name);
     $options = new CreateBlobOptions();
     $options->setContentType($contentType);
     $this->restProxy->createBlockBlob($name, $blob, 'Hello world', $options);
     $this->restProxy->createBlobSnapshot($name, $blob);
     $options = new DeleteBlobOptions();
     $options->setDeleteSnaphotsOnly(true);
     // Test
     $this->restProxy->deleteBlob($name, $blob, $options);
     // Assert
     $listOptions = new ListBlobsOptions();
     $listOptions->setIncludeSnapshots(true);
     $blobsResult = $this->restProxy->listBlobs($name, $listOptions);
     $blobs = $blobsResult->getBlobs();
     $actualBlob = $blobs[0];
     $this->assertNull($actualBlob->getSnapshot());
 }
コード例 #4
0
 /**
  * @covers MicrosoftAzure\Storage\Blob\Models\DeleteBlobOptions::setDeleteSnaphotsOnly
  * @covers MicrosoftAzure\Storage\Blob\Models\DeleteBlobOptions::getDeleteSnaphotsOnly
  */
 public function testSetDeleteSnaphotsOnly()
 {
     // Setup
     $expected = true;
     $options = new DeleteBlobOptions();
     $options->setDeleteSnaphotsOnly($expected);
     // Test
     $options->setDeleteSnaphotsOnly($expected);
     // Assert
     $this->assertEquals($expected, $options->getDeleteSnaphotsOnly());
 }
コード例 #5
0
 /**
  * Deletes a blob or blob snapshot.
  * 
  * Note that if the snapshot entry is specified in the $options then only this
  * blob snapshot is deleted. To delete all blob snapshots, do not set Snapshot 
  * and just set getDeleteSnaphotsOnly to true.
  * 
  * @param string                   $container name of the container
  * @param string                   $blob      name of the blob
  * @param Models\DeleteBlobOptions $options   optional parameters
  * 
  * @return none
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179413.aspx
  */
 public function deleteBlob($container, $blob, $options = null)
 {
     Validate::isString($container, 'container');
     Validate::isString($blob, 'blob');
     Validate::notNullOrEmpty($blob, 'blob');
     $method = Resources::HTTP_DELETE;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $this->_createPath($container, $blob);
     $statusCode = Resources::STATUS_ACCEPTED;
     if (is_null($options)) {
         $options = new DeleteBlobOptions();
     }
     if (is_null($options->getSnapshot())) {
         $delSnapshots = $options->getDeleteSnaphotsOnly() ? 'only' : 'include';
         $this->addOptionalHeader($headers, Resources::X_MS_DELETE_SNAPSHOTS, $delSnapshots);
     } else {
         $this->addOptionalQueryParam($queryParams, Resources::QP_SNAPSHOT, $options->getSnapshot());
     }
     $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition());
     $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId());
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
 }