/**
  * @covers MicrosoftAzure\Storage\Blob\Models\SetBlobPropertiesOptions::setAccessCondition
  */
 public function testSetAccessCondition()
 {
     // Setup
     $expected = AccessCondition::none();
     $result = new SetBlobPropertiesOptions();
     // Test
     $result->setAccessCondition($expected);
     // Assert
     $this->assertEquals($expected, $result->getAccessCondition());
 }
 public static function getSetBlobPropertiesOptions()
 {
     $ret = array();
     $options = new SetBlobPropertiesOptions();
     array_push($ret, $options);
     $options = new SetBlobPropertiesOptions();
     $options->setTimeout(10);
     array_push($ret, $options);
     $options = new SetBlobPropertiesOptions();
     $options->setTimeout(-10);
     array_push($ret, $options);
     // Get Blob Properties only supports the temporal access conditions.
     foreach (self::getTemporalAccessConditions() as $ac) {
         $options = new SetBlobPropertiesOptions();
         $options->setAccessCondition($ac);
         array_push($ret, $options);
     }
     $options = new SetBlobPropertiesOptions();
     $options->setBlobCacheControl('setBlobCacheControl');
     array_push($ret, $options);
     $options = new SetBlobPropertiesOptions();
     $options->setBlobContentEncoding('setBlobContentEncoding');
     array_push($ret, $options);
     $options = new SetBlobPropertiesOptions();
     $options->setBlobContentLanguage('setBlobContentLanguage');
     array_push($ret, $options);
     // Note: This is not allowed on block blobs
     $options = new SetBlobPropertiesOptions();
     $options->setBlobContentLength(2048);
     array_push($ret, $options);
     $options = new SetBlobPropertiesOptions();
     $options->setBlobContentMD5('d41d8cd98f00b204e9800998ecf8427e');
     array_push($ret, $options);
     $options = new SetBlobPropertiesOptions();
     $options->setBlobContentType('setContentType');
     array_push($ret, $options);
     // TODO: Handle Lease ID
     //        $options = new SetBlobPropertiesOptions();
     //        $options->setLeaseId('setLeaseId');
     //        array_push($ret, $options);
     // Note: This is not allowed on block blobs
     $options = new SetBlobPropertiesOptions();
     $options->setSequenceNumber(0);
     $options->setSequenceNumberAction('update');
     array_push($ret, $options);
     return $ret;
 }
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getBlobProperties
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::setBlobProperties
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::_getBlobPropertiesResultFromResponse
  * @covers MicrosoftAzure\Storage\Blob\Models\SetBlobPropertiesResult::create
  */
 public function testSetBlobProperties()
 {
     // Setup
     $name = 'setblobproperties' . $this->createSuffix();
     $contentLength = 1024;
     $blob = 'myblob';
     $this->createContainer($name);
     $this->restProxy->createPageBlob($name, 'myblob', 512);
     $options = new SetBlobPropertiesOptions();
     $options->setBlobContentLength($contentLength);
     // Test
     $this->restProxy->setBlobProperties($name, $blob, $options);
     // Assert
     $result = $this->restProxy->getBlobProperties($name, $blob);
     $this->assertEquals($contentLength, $result->getProperties()->getContentLength());
 }
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createPageBlob
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getBlobProperties
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::setBlobProperties
  */
 public function testSetBlobPropertiesWorks()
 {
     // Act
     $container = self::$_test_container_for_blobs;
     $blob = 'test10';
     $this->restProxy->createPageBlob($container, $blob, 4096);
     $opts = new SetBlobPropertiesOptions();
     $opts->setBlobCacheControl('test');
     $opts->setBlobContentEncoding('UTF-8');
     $opts->setBlobContentLanguage('en-us');
     $opts->setBlobContentLength(512);
     $opts->setBlobContentMD5(null);
     $opts->setBlobContentType('text/plain');
     $opts->setSequenceNumberAction('increment');
     $result = $this->restProxy->setBlobProperties($container, $blob, $opts);
     $getResult = $this->restProxy->getBlobProperties($container, $blob);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertNotNull($result->getETag(), '$result->getETag()');
     $this->assertNotNull($result->getLastModified(), '$result->getLastModified()');
     $this->assertNotNull($result->getSequenceNumber(), '$result->getSequenceNumber()');
     $this->assertEquals(1, $result->getSequenceNumber(), '$result->getSequenceNumber()');
     $this->assertNotNull($getResult, '$getResult');
     $this->assertNotNull($getResult->getMetadata(), '$getResult->getMetadata()');
     $this->assertEquals(0, count($getResult->getMetadata()), 'count($getResult->getMetadata())');
     $props = $getResult->getProperties();
     $this->assertNotNull($props, '$props');
     $this->assertEquals('test', $props->getCacheControl(), '$props->getCacheControl()');
     $this->assertEquals('UTF-8', $props->getContentEncoding(), '$props->getContentEncoding()');
     $this->assertEquals('en-us', $props->getContentLanguage(), '$props->getContentLanguage()');
     $this->assertEquals('text/plain', $props->getContentType(), '$props->getContentType()');
     $this->assertEquals(512, $props->getContentLength(), '$props->getContentLength()');
     $this->assertNull($props->getContentMD5(), '$props->getContentMD5()');
     $this->assertNotNull($props->getLastModified(), '$props->getLastModified()');
     $this->assertEquals('PageBlob', $props->getBlobType(), '$props->getBlobType()');
     $this->assertEquals('unlocked', $props->getLeaseStatus(), '$props->getLeaseStatus()');
     $this->assertEquals(1, $props->getSequenceNumber(), '$props->getSequenceNumber()');
 }
Esempio n. 5
0
 /**
  * Sets system properties defined for a blob.
  * 
  * @param string                          $container name of the container
  * @param string                          $blob      name of the blob
  * @param Models\SetBlobPropertiesOptions $options   optional parameters
  * 
  * @return Models\SetBlobPropertiesResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691966.aspx
  */
 public function setBlobProperties($container, $blob, $options = null)
 {
     Validate::isString($container, 'container');
     Validate::isString($blob, 'blob');
     Validate::notNullOrEmpty($blob, 'blob');
     $method = Resources::HTTP_PUT;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $this->_createPath($container, $blob);
     $statusCode = Resources::STATUS_OK;
     if (is_null($options)) {
         $options = new SetBlobPropertiesOptions();
     }
     $blobContentType = $options->getBlobContentType();
     $blobContentEncoding = $options->getBlobContentEncoding();
     $blobContentLanguage = $options->getBlobContentLanguage();
     $blobContentLength = $options->getBlobContentLength();
     $blobContentMD5 = $options->getBlobContentMD5();
     $blobCacheControl = $options->getBlobCacheControl();
     $leaseId = $options->getLeaseId();
     $sNumberAction = $options->getSequenceNumberAction();
     $sNumber = $options->getSequenceNumber();
     $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition());
     $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $leaseId);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CACHE_CONTROL, $blobCacheControl);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_TYPE, $blobContentType);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_ENCODING, $blobContentEncoding);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_LANGUAGE, $blobContentLanguage);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_LENGTH, $blobContentLength);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_MD5, $blobContentMD5);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_SEQUENCE_NUMBER_ACTION, $sNumberAction);
     $this->addOptionalHeader($headers, Resources::X_MS_BLOB_SEQUENCE_NUMBER, $sNumber);
     $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'properties');
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
     return SetBlobPropertiesResult::create(HttpFormatter::formatHeaders($response->getHeaders()));
 }