/**
  * @covers WindowsAzure\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());
 }
Ejemplo n.º 2
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);
 }
 /**
  * @covers WindowsAzure\Blob\BlobRestProxy::createBlobSnapshot
  * @covers WindowsAzure\Blob\BlobRestProxy::createPageBlob
  * @covers WindowsAzure\Blob\BlobRestProxy::deleteBlob
  * @covers WindowsAzure\Blob\BlobRestProxy::getBlob
  * @covers WindowsAzure\Blob\BlobRestProxy::listBlobs
  */
 private function deleteBlobWorker($options, $container)
 {
     $blob = BlobServiceFunctionalTestData::getInterestingBlobName();
     // 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(500, $e->getCode(), 'bad timeout: deleteHttpStatusCode');
         } else {
             if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
                 $this->assertEquals(412, $e->getCode(), 'bad temporal access condition IF_UNMODIFIED_SINCE: deleteHttpStatusCode');
             } else {
                 if (!BlobServiceFunctionalTestData::passEtagAccessCondition($options->getAccessCondition())) {
                     $this->assertEquals(412, $e->getCode(), 'bad etag access condition: deleteHttpStatusCode');
                 } else {
                     throw $e;
                 }
             }
         }
     }
     // Clean up.
     if (!$deleted) {
         $this->restProxy->deleteBlob($container, $blob);
     }
 }
 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;
 }
 /**
  * @covers WindowsAzure\Blob\Models\DeleteBlobOptions::setDeleteSnaphotsOnly
  * @covers WindowsAzure\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());
 }