/**
  * @covers WindowsAzure\Blob\Models\SetContainerMetadataOptions::setAccessCondition
  */
 public function testSetAccessCondition()
 {
     // Setup
     $expected = AccessCondition::none();
     $result = new SetContainerMetadataOptions();
     // Test
     $result->setAccessCondition($expected);
     // Assert
     $this->assertEquals($expected, $result->getAccessCondition());
 }
 public static function getSetContainerMetadataOptions()
 {
     $ret = array();
     $options = new SetContainerMetadataOptions();
     array_push($ret, $options);
     $options = new SetContainerMetadataOptions();
     $options->setTimeout(10);
     array_push($ret, $options);
     $options = new SetContainerMetadataOptions();
     $options->setTimeout(-10);
     array_push($ret, $options);
     // Set Container Metadata only supports the If-Modified-Since access condition.
     // But easier to special-case If-Unmodified-Since in the test.
     foreach (self::getTemporalAccessConditions() as $ac) {
         $options = new SetContainerMetadataOptions();
         $options->setAccessCondition($ac);
         array_push($ret, $options);
     }
     return $ret;
 }
Ejemplo n.º 3
0
 /**
  * Sets metadata headers on the container.
  * 
  * @param string                             $container name
  * @param array                              $metadata  metadata key/value pair.
  * @param Models\SetContainerMetadataOptions $options   optional parameters
  * 
  * @return none
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179362.aspx
  */
 public function setContainerMetadata($container, $metadata, $options = null)
 {
     Validate::isString($container, 'container');
     $this->validateMetadata($metadata);
     $method = Resources::HTTP_PUT;
     $headers = $this->generateMetadataHeaders($metadata);
     $postParams = array();
     $queryParams = array();
     $path = $container;
     $statusCode = Resources::STATUS_OK;
     if (is_null($options)) {
         $options = new SetContainerMetadataOptions();
     }
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->addOptionalQueryParam($queryParams, Resources::QP_REST_TYPE, 'container');
     $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'metadata');
     $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition());
     $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
 }
 /**
  * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  * @covers WindowsAzure\Blob\BlobRestProxy::getContainerMetadata
  * @covers WindowsAzure\Blob\BlobRestProxy::setContainerMetadata
  */
 private function setContainerMetadataWorker($options, $metadata)
 {
     $container = BlobServiceFunctionalTestData::getInterestingContainerName();
     // Make sure there is something to test
     $this->restProxy->createContainer($container);
     $firstkey = '';
     if (!is_null($metadata) && count($metadata) > 0) {
         $firstkey = array_keys($metadata);
         $firstkey = $firstkey[0];
     }
     try {
         try {
             // And put in some metadata
             if (is_null($options)) {
                 $this->restProxy->setContainerMetadata($container, $metadata);
             } else {
                 $this->restProxy->setContainerMetadata($container, $metadata, $options);
             }
             if (is_null($options)) {
                 $options = new SetContainerMetadataOptions();
             }
             $this->assertFalse(Utilities::startsWith($firstkey, '<'), 'Should get HTTP request error if the metadata is invalid');
             if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
                 $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
             }
             // setMetadata only honors If-Modified-Since
             if (!Configuration::isEmulated() && !BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition()) && (!is_null($options->getAccessCondition()) && $options->getAccessCondition()->getHeader() != Resources::IF_UNMODIFIED_SINCE)) {
                 $this->assertTrue(false, 'Expect failing access condition to throw');
             }
             $res = $this->restProxy->getContainerMetadata($container);
             $this->verifyGetContainerMetadataWorker($res, $metadata);
         } catch (\HTTP_Request2_LogicException $e) {
             $this->assertTrue(Utilities::startsWith($firstkey, '<'), 'Should get HTTP request error only if the metadata is invalid');
         }
     } catch (ServiceException $e) {
         if (!Configuration::isEmulated() && !BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition()) && (!is_null($options->getAccessCondition()) && $options->getAccessCondition()->getHeader() != Resources::IF_UNMODIFIED_SINCE)) {
             // setMetadata only honors If-Modified-Since
             $this->assertEquals(412, $e->getCode(), 'getCode');
         } else {
             if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
                 $this->assertEquals(500, $e->getCode(), 'getCode');
             } else {
                 throw $e;
             }
         }
     }
     // Clean up.
     $this->restProxy->deleteContainer($container);
 }