/** * Given array of MIME parts in raw string, this function converts them into MIME * representation. * * @param array $bodyPartContents The MIME body parts. * * @return array Returns array with two elements 'headers' and 'body' which * represents the MIME message. */ public function encodeMimeMultipart($bodyPartContents) { $count = count($bodyPartContents); $mimeType = Resources::MULTIPART_MIXED_TYPE; $batchGuid = Utilities::getGuid(); $batchId = sprintf('batch_%s', $batchGuid); $contentType1 = array('content_type' => "{$mimeType}"); $changeSetGuid = Utilities::getGuid(); $changeSetId = sprintf('changeset_%s', $changeSetGuid); $contentType2 = array('content_type' => "{$mimeType}; boundary={$changeSetId}"); $options = array('encoding' => 'binary', 'content_type' => Resources::HTTP_TYPE); $eof = "\r\n"; $result = array(); $result['body'] = Resources::EMPTY_STRING; $result['headers'] = array(); $batchBody =& $result['body']; $batchHeaders =& $result['headers']; $batchHeaders['Content-Type'] = $mimeType . "; {$eof} boundary=\"{$batchId}\""; $batchBody .= "--" . $batchId . $eof; $batchBody .= "Content-Type: {$mimeType}; boundary=\"{$changeSetId}\"" . $eof; $batchBody .= $eof; for ($i = 0; $i < count($bodyPartContents); $i++) { $batchBody .= "--" . $changeSetId . $eof; $batchBody .= "Content-Transfer-Encoding: binary" . $eof; $batchBody .= "Content-Type: " . Resources::HTTP_TYPE . $eof; $batchBody .= $eof . $bodyPartContents[$i] . $eof; } $batchBody .= "--" . $changeSetId . "--" . $eof; $batchBody .= $eof; $batchBody .= "--" . $batchId . "--" . $eof; return $result; }
private static function mutateEntityChangeValues($ent) { foreach ($ent->getProperties() as $propName => $initialProp) { // Don't mess with the keys. if ($propName == 'PartitionKey' || $propName == 'RowKey' || $propName == 'Timestamp') { continue; } $ptype = $initialProp->getEdmType(); if (is_null($ptype)) { $eff = $initialProp->getValue(); $initialProp->setValue($eff . 'AndMore'); } else { if ($ptype == EdmType::DATETIME) { $value = $initialProp->getValue(); if (is_null($value)) { $value = new \DateTime("1/26/1692"); } $value->modify('+1 day'); $initialProp->setValue($value); } else { if ($ptype == EdmType::BINARY) { $eff = $initialProp->getValue(); $initialProp->setValue($eff . 'x'); } else { if ($ptype == EdmType::BOOLEAN) { $eff = $initialProp->getValue(); $initialProp->setValue(!$eff); } else { if ($ptype == EdmType::DOUBLE) { $eff = $initialProp->getValue(); $initialProp->setValue($eff + 1); } else { if ($ptype == EdmType::GUID) { $initialProp->setValue(Utilities::getGuid()); } else { if ($ptype == EdmType::INT32) { $eff = $initialProp->getValue(); $eff = $eff > 10 ? 0 : $eff + 1; $initialProp->setValue($eff); } else { if ($ptype == EdmType::INT64) { $eff = $initialProp->getValue(); $eff = $eff > 10 ? 0 : $eff + 1; $initialProp->setValue(strval($eff)); } else { if ($ptype == EdmType::STRING) { $eff = $initialProp->getValue(); $initialProp->setValue($eff . 'AndMore'); } } } } } } } } } } }
/** * @covers MicrosoftAzure\Storage\Common\Internal\Utilities::getGuid */ public function testGetGuid() { // Test $actual1 = Utilities::getGuid(); $actual2 = Utilities::getGuid(); // Assert $this->assertNotNull($actual1); $this->assertNotNull($actual2); $this->assertInternalType('string', $actual1); $this->assertInternalType('string', $actual2); $this->assertNotEquals($actual1, $actual2); }
/** * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertEntity * @covers MicrosoftAzure\Storage\Table\TableRestProxy::queryEntities */ public function testQueryEntitiesWithFilterWorks() { // Arrange $table = self::$testTable5; $numberOfEntries = 5; $entities = array(); for ($i = 0; $i < $numberOfEntries; $i++) { $entity = new Entity(); $entity->setPartitionKey('001'); $entity->setRowKey('queryEntitiesWithFilterWorks-' . $i); $entity->addProperty('test', EdmType::BOOLEAN, $i % 2 == 0); $entity->addProperty('test2', EdmType::STRING, '\'value" ' . $i); $entity->addProperty('test3', EdmType::INT32, $i); $entity->addProperty('test4', EdmType::INT64, strval('12345678901' + $i)); $entity->addProperty('test5', EdmType::DATETIME, new \DateTime('2012-01-0' . $i)); $entity->addProperty('test6', EdmType::BINARY, chr($i)); $entity->addProperty('test7', EdmType::GUID, Utilities::getGuid()); $entities[$i] = $entity; $this->restProxy->insertEntity($table, $entity); } // Act $f = Filter::applyEq(Filter::applyPropertyName('RowKey'), Filter::applyConstant('queryEntitiesWithFilterWorks-3', EdmType::STRING)); $q = new Query(); $q->setFilter($f); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); // Act $q = new Query(); $q->setFilter(Filter::applyQueryString('RowKey eq \'queryEntitiesWithFilterWorks-3\'')); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); // Act $q = new Query(); $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test'), Filter::applyConstant(true, EdmType::BOOLEAN))); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(3, count($result->getEntities()), 'count($result->getEntities())'); // Act $q = new Query(); $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test2'), Filter::applyConstant('\'value" 3', EdmType::STRING))); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); // Act $q = new Query(); $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test4'), Filter::applyConstant(12345678903, EdmType::INT64))); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-2', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); // Act $q = new Query(); $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test5'), Filter::applyConstant(new \DateTime('2012-01-03'), EdmType::DATETIME))); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); // Act $q = new Query(); $ent3 = $entities[3]; $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test6'), Filter::applyConstant(chr(3), EdmType::BINARY))); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); // Act $q = new Query(); $ent3 = $entities[3]; $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test7'), Filter::applyConstant($ent3->getPropertyValue('test7'), EdmType::GUID))); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); }