/** * @covers MicrosoftAzure\Storage\Blob\Models\SetContainerMetadataOptions::setAccessCondition */ public function testSetAccessCondition() { // Setup $expected = AccessCondition::none(); $result = new SetContainerMetadataOptions(); // Test $result->setAccessCondition($expected); // Assert $this->assertEquals($expected, $result->getAccessCondition()); }
/** * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createContainer * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::deleteContainer * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getContainerMetadata * @covers MicrosoftAzure\Storage\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 { // 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 (!$this->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 (ServiceException $e) { if (Utilities::startsWith($firstkey, '<')) { $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode'); } else { if (!$this->isEmulated() && !BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition()) && (!is_null($options->getAccessCondition()) && $options->getAccessCondition()->getHeader() != Resources::IF_UNMODIFIED_SINCE)) { // setMetadata only honors If-Modified-Since $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'getCode'); } else { if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) { $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode'); } else { throw $e; } } } } // Clean up. $this->restProxy->deleteContainer($container); }
/** * 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); }