/** * Parses the given array into signed identifiers. * * @param string $publicAccess The container public access. * @param array $parsed The parsed response into array representation. * * @return none */ public static function create($publicAccess, $parsed) { $result = new ContainerAcl(); $result->_publicAccess = $publicAccess; $result->_signedIdentifiers = array(); if (!empty($parsed) && is_array($parsed['SignedIdentifier'])) { $entries = $parsed['SignedIdentifier']; $temp = Utilities::getArray($entries); foreach ($temp as $value) { $startString = urldecode($value['AccessPolicy']['Start']); $expiryString = urldecode($value['AccessPolicy']['Expiry']); $start = Utilities::convertToDateTime($startString); $expiry = Utilities::convertToDateTime($expiryString); $permission = $value['AccessPolicy']['Permission']; $id = $value['Id']; $result->addSignedIdentifier($id, $start, $expiry, $permission); } } return $result; }
public function testParseEntities() { // Setup $atomSerializer = new AtomReaderWriter(); $pk1 = '123'; $pk2 = '124'; $pk3 = '125'; $e1 = TestResources::getTestEntity($pk1, '1'); $e2 = TestResources::getTestEntity($pk2, '2'); $e3 = TestResources::getTestEntity($pk3, '3'); $e1->setETag('W/"datetime\'2012-05-17T00%3A59%3A32.1131734Z\'"'); $e2->setETag('W/"datetime\'2012-05-17T00%3A59%3A32.4252358Z\'"'); $e3->setETag('W/"datetime\'2012-05-17T00%3A59%3A32.7533014Z\'"'); $e1->setTimestamp(Utilities::convertToDateTime('2012-05-17T00:59:32.0000473Z')); $e2->setTimestamp(Utilities::convertToDateTime('2012-05-17T00:59:32.0000473Z')); $e3->setTimestamp(Utilities::convertToDateTime('2012-05-17T00:59:32.0000473Z')); $expected = array($e1, $e2, $e3); $entitiesAtom = '<?xml version="1.0" encoding="utf-8" standalone="yes"?> <feed xml:base="http://aogail2.table.core.windows.net/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"> <title type="text">queryentitieswithmultipleentities</title> <id>http://aogail2.table.core.windows.net/queryentitieswithmultipleentities</id> <updated>2012-05-17T00:59:32Z</updated> <link rel="self" title="queryentitieswithmultipleentities" href="queryentitieswithmultipleentities" /> <entry m:etag="W/"datetime\'2012-05-17T00%3A59%3A32.1131734Z\'""> <id>http://aogail2.table.core.windows.net/queryentitieswithmultipleentities(PartitionKey=\'123\',RowKey=\'1\')</id> <title type="text"></title> <updated>2012-05-17T00:59:32Z</updated> <author> <name /> </author> <link rel="edit" title="queryentitieswithmultipleentities" href="queryentitieswithmultipleentities(PartitionKey=\'123\',RowKey=\'1\')" /> <category term="aogail2.queryentitieswithmultipleentities" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> <content type="application/xml"> <m:properties> <d:PartitionKey>123</d:PartitionKey> <d:RowKey>1</d:RowKey> <d:Timestamp m:type="Edm.DateTime">2012-05-17T00:59:32.1131734Z</d:Timestamp> <d:CustomerId m:type="Edm.Int32">890</d:CustomerId> <d:CustomerName>John</d:CustomerName> <d:IsNew m:type="Edm.Boolean">true</d:IsNew> <d:JoinDate m:type="Edm.DateTime">2012-01-26T18:26:19Z</d:JoinDate> </m:properties> </content> </entry> <entry m:etag="W/"datetime\'2012-05-17T00%3A59%3A32.4252358Z\'""> <id>http://aogail2.table.core.windows.net/queryentitieswithmultipleentities(PartitionKey=\'124\',RowKey=\'2\')</id> <title type="text"></title> <updated>2012-05-17T00:59:32Z</updated> <author> <name /> </author> <link rel="edit" title="queryentitieswithmultipleentities" href="queryentitieswithmultipleentities(PartitionKey=\'124\',RowKey=\'2\')" /> <category term="aogail2.queryentitieswithmultipleentities" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> <content type="application/xml"> <m:properties> <d:PartitionKey>124</d:PartitionKey> <d:RowKey>2</d:RowKey> <d:Timestamp m:type="Edm.DateTime">2012-05-17T00:59:32.4252358Z</d:Timestamp> <d:CustomerId m:type="Edm.Int32">890</d:CustomerId> <d:CustomerName>John</d:CustomerName> <d:IsNew m:type="Edm.Boolean">true</d:IsNew> <d:JoinDate m:type="Edm.DateTime">2012-01-26T18:26:19Z</d:JoinDate> </m:properties> </content> </entry> <entry m:etag="W/"datetime\'2012-05-17T00%3A59%3A32.7533014Z\'""> <id>http://aogail2.table.core.windows.net/queryentitieswithmultipleentities(PartitionKey=\'125\',RowKey=\'3\')</id> <title type="text"></title> <updated>2012-05-17T00:59:32Z</updated> <author> <name /> </author> <link rel="edit" title="queryentitieswithmultipleentities" href="queryentitieswithmultipleentities(PartitionKey=\'125\',RowKey=\'3\')" /> <category term="aogail2.queryentitieswithmultipleentities" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> <content type="application/xml"> <m:properties> <d:PartitionKey>125</d:PartitionKey> <d:RowKey>3</d:RowKey> <d:Timestamp m:type="Edm.DateTime">2012-05-17T00:59:32.7533014Z</d:Timestamp> <d:CustomerId m:type="Edm.Int32">890</d:CustomerId> <d:CustomerName>John</d:CustomerName> <d:IsNew m:type="Edm.Boolean">true</d:IsNew> <d:JoinDate m:type="Edm.DateTime">2012-01-26T18:26:19Z</d:JoinDate> </m:properties> </content> </entry> </feed> '; // Test $actual = $atomSerializer->parseEntities($entitiesAtom); // Assert $this->assertEquals($expected, $actual); }
/** * Converts the value into its proper type. * * @param string $type The edm type. * @param string $value The edm value. * * @return mix * * @throws \InvalidArgumentException */ public static function unserializeQueryValue($type, $value) { // Having null value means that the user wants to remove the property name // associated with this value. Leave the value as null so this hold. if (is_null($value)) { return null; } else { switch ($type) { case self::GUID: case self::STRING: case self::INT64: case null: // NULL also is treated as EdmType::STRING return strval($value); case self::BINARY: return base64_decode($value); case self::DATETIME: return Utilities::convertToDateTime($value); case self::BOOLEAN: return Utilities::toBoolean($value); case self::DOUBLE: return doubleval($value); case self::INT32: return intval($value); default: throw new \InvalidArgumentException(); } } }
public static function getTestEntity($partitionKey, $rowKey) { $entity = new Entity(); $entity->setPartitionKey($partitionKey); $entity->setRowKey($rowKey); $entity->addProperty('CustomerId', EdmType::INT32, 890); $entity->addProperty('CustomerName', null, 'John'); $entity->addProperty('IsNew', EdmType::BOOLEAN, true); $entity->addProperty('JoinDate', EdmType::DATETIME, Utilities::convertToDateTime('2012-01-26T18:26:19.0000473Z')); return $entity; }
/** * @covers WindowsAzure\Common\Internal\Utilities::convertToDateTime */ public function testConvertToDateTimeWithDate() { // Setup $date = new \DateTime(); // Test $actual = Utilities::convertToDateTime($date); // Assert $this->assertEquals($date, $actual); }
/** * Gets the access control list (ACL) and any container-level access policies * for the container. * * @param string $container The container name. * @param Models\BlobServiceOptions $options The optional parameters. * * @return Models\GetContainerAclResult * * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179469.aspx */ public function getContainerAcl($container, $options = null) { Validate::isString($container, 'container'); $method = Resources::HTTP_GET; $headers = array(); $postParams = array(); $queryParams = array(); $path = $container; $statusCode = Resources::STATUS_OK; if (is_null($options)) { $options = new BlobServiceOptions(); } $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $this->addOptionalQueryParam($queryParams, Resources::QP_REST_TYPE, 'container'); $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'acl'); $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode); $access = $response->getHeader(Resources::X_MS_BLOB_PUBLIC_ACCESS); $etag = $response->getHeader(Resources::ETAG); $modified = $response->getHeader(Resources::LAST_MODIFIED); $modifiedDate = Utilities::convertToDateTime($modified); $parsed = $this->dataSerializer->unserialize($response->getBody()); return GetContainerAclResult::create($access, $etag, $modifiedDate, $parsed); }
static function mutateEntity($ent, $pivot) { if ($pivot == MutatePivot::CHANGE_VALUES) { self::mutateEntityChangeValues($ent); } else { if ($pivot == MutatePivot::ADD_PROPERTY) { $ent->addProperty('BOOLEAN' . TableServiceFunctionalTestData::getNewKey(), EdmType::BOOLEAN, true); $ent->addProperty('DATETIME' . TableServiceFunctionalTestData::getNewKey(), EdmType::DATETIME, Utilities::convertToDateTime('2012-01-26T18:26:19.0000473Z')); $ent->addProperty('DOUBLE' . TableServiceFunctionalTestData::getNewKey(), EdmType::DOUBLE, 12345678901); $ent->addProperty('GUID' . TableServiceFunctionalTestData::getNewKey(), EdmType::GUID, '90ab64d6-d3f8-49ec-b837-b8b5b6367b74'); $ent->addProperty('INT32' . TableServiceFunctionalTestData::getNewKey(), EdmType::INT32, 23); $ent->addProperty('INT64' . TableServiceFunctionalTestData::getNewKey(), EdmType::INT64, '-1'); $ent->addProperty('STRING' . TableServiceFunctionalTestData::getNewKey(), EdmType::STRING, 'this is a test!'); } else { if ($pivot == MutatePivot::REMOVE_PROPERTY) { $propToRemove = null; foreach ($ent->getProperties() as $propName => $propValue) { // Don't mess with the keys. if ($propName == 'PartitionKey' || $propName == 'RowKey' || $propName == 'Timestamp') { continue; } $propToRemove = $propName; break; } $props = $ent->getProperties(); unset($props[$propToRemove]); } else { if ($pivot == MutatePivot::NULL_PROPERTY) { foreach ($ent->getProperties() as $propName => $propValue) { // Don't mess with the keys. if ($propName == 'PartitionKey' || $propName == 'RowKey' || $propName == 'Timestamp') { continue; } $propValue->setValue(null); } } } } } }
static function getInterestingEntities() { $ret = array(); array_push($ret, self::getSimpleEntity()); $e = new Entity(); $e->addProperty('RowKey', EdmType::STRING, self::getNewKey()); $e->addProperty('PartitionKey', null, self::getNewKey()); array_push($ret, $e); $e = new Entity(); $e->setPartitionKey(self::getNewKey()); $e->setRowKey(self::getNewKey()); $e->addProperty('BINARY', EdmType::BINARY, chr(0) . chr(1) . chr(2) . chr(3) . chr(4)); $e->addProperty('BOOLEAN', EdmType::BOOLEAN, true); $e->addProperty('DATETIME', EdmType::DATETIME, Utilities::convertToDateTime('2012-01-26T18:26:19.0000473Z')); $e->addProperty('DOUBLE', EdmType::DOUBLE, 12345678901); $e->addProperty('GUID', EdmType::GUID, '90ab64d6-d3f8-49ec-b837-b8b5b6367b74'); $e->addProperty('INT32', EdmType::INT32, 23); $e->addProperty('INT64', EdmType::INT64, '-1'); $now = new \DateTime(); $e->addProperty('STRING', EdmType::STRING, $now->format(\DateTime::COOKIE)); array_push($ret, $e); $e = new Entity(); $e->setPartitionKey(self::getNewKey()); $e->setRowKey(self::getNewKey()); $e->addProperty('test', EdmType::BOOLEAN, true); $e->addProperty('test2', EdmType::STRING, 'value'); $e->addProperty('test3', EdmType::INT32, 3); $e->addProperty('test4', EdmType::INT64, '12345678901'); $e->addProperty('test5', EdmType::DATETIME, new \DateTime()); array_push($ret, $e); $e = new Entity(); $e->setPartitionKey(self::getNewKey()); +$e->setRowKey(self::getNewKey()); $e->addProperty('BINARY', EdmType::BINARY, null); $e->addProperty('BOOLEAN', EdmType::BOOLEAN, null); $e->addProperty('DATETIME', EdmType::DATETIME, null); $e->addProperty('DOUBLE', EdmType::DOUBLE, null); $e->addProperty('GUID', EdmType::GUID, null); $e->addProperty('INT32', EdmType::INT32, null); $e->addProperty('INT64', EdmType::INT64, null); $e->addProperty('STRING', EdmType::STRING, null); array_push($ret, $e); return $ret; }
/** * @covers WindowsAzure\Table\Models\Entity::setTimestamp * @covers WindowsAzure\Table\Models\Entity::getTimestamp */ public function testSetTimestamp() { // Setup $entity = new Entity(); $expected = Utilities::convertToDateTime(Utilities::isoDate()); // Test $entity->setTimestamp($expected); // Assert $this->assertEquals($expected, $entity->getTimestamp()); }
/** * @covers WindowsAzure\Blob\BlobRestProxy::createContainer * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer * @covers WindowsAzure\Blob\BlobRestProxy::getContainerACL * @covers WindowsAzure\Blob\BlobRestProxy::setContainerACL */ public function testSetContainerACLWorks() { // Arrange $container = self::$_creatable_container_4; $expiryStartDate = new \DateTime(); $expiryStartDate->setDate(2010, 1, 1); $expiryEndDate = new \DateTime(); $expiryEndDate->setDate(2020, 1, 1); // Act $this->restProxy->createContainer($container); $acl = new ContainerACL(); $acl->setPublicAccess(PublicAccessType::BLOBS_ONLY); $acl->addSignedIdentifier('test', $expiryStartDate, $expiryEndDate, 'rwd'); $this->restProxy->setContainerACL($container, $acl); $res = $this->restProxy->getContainerACL($container); $acl2 = $res->getContainerACL(); $this->restProxy->deleteContainer($container); // Assert $this->assertNotNull($acl2, '$acl2'); $this->assertNotNull($res->getETag(), '$res->getETag()'); $this->assertNotNull($res->getLastModified(), '$res->getLastModified()'); $this->assertNotNull($acl2->getPublicAccess(), '$acl2->getPublicAccess()'); $this->assertEquals(PublicAccessType::BLOBS_ONLY, $acl2->getPublicAccess(), '$acl2->getPublicAccess()'); $this->assertEquals(1, count($acl2->getSignedIdentifiers()), 'count($acl2->getSignedIdentifiers())'); $signedids = $acl2->getSignedIdentifiers(); $this->assertEquals('test', $signedids[0]->getId(), '$signedids[0]->getId()'); $expiryStartDate = $expiryStartDate->setTimezone(new \DateTimeZone('UTC')); $expiryEndDate = $expiryEndDate->setTimezone(new \DateTimeZone('UTC')); $this->assertEquals(Utilities::convertToDateTime($expiryStartDate), Utilities::convertToDateTime($signedids[0]->getAccessPolicy()->getStart()), '$signedids[0]->getAccessPolicy()->getStart()'); $this->assertEquals(Utilities::convertToDateTime($expiryEndDate), Utilities::convertToDateTime($signedids[0]->getAccessPolicy()->getExpiry()), '$signedids[0]->getAccessPolicy()->getExpiry()'); $this->assertEquals('rwd', $signedids[0]->getAccessPolicy()->getPermission(), '$signedids[0]->getAccessPolicy()->getPermission()'); }