/**
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::deleteEntity
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertEntity
  */
 public function testDeleteEntityTroublesomeRowKey()
 {
     // The service does not allow the following common characters in keys:
     // 35 '#'
     // 47 '/'
     // 63 '?'
     // 92 '\'
     // In addition, the following values are not allowed, as they make the URL bad:
     // 0-31, 127-159
     // That still leaves several options for making troublesome keys
     // spaces
     // single quotes
     // Unicode
     // These need to be properly encoded when passed on the URL, else there will be trouble
     $table = TableServiceFunctionalTestData::$testTableNames[0];
     $e = new Entity();
     $e->setRowKey('row\'Key\'');
     $e->setPartitionKey('niceKey');
     $this->restProxy->insertEntity($table, $e);
     $this->restProxy->deleteEntity($table, $e->getPartitionKey(), $e->getRowKey());
     $qopts = new QueryEntitiesOptions();
     $qopts->setFilter(Filter::applyEq(Filter::applyPropertyName('RowKey'), Filter::applyConstant($e->getRowKey(), EdmType::STRING)));
     $queryres = $this->restProxy->queryEntities($table, $qopts);
     $this->assertEquals(0, count($queryres->getEntities()), 'entities returned');
     $e = new Entity();
     $e->setRowKey('row Key');
     $e->setPartitionKey('niceKey');
     $this->restProxy->insertEntity($table, $e);
     $this->restProxy->deleteEntity($table, $e->getPartitionKey(), $e->getRowKey());
     $qopts = new QueryEntitiesOptions();
     $qopts->setFilter(Filter::applyEq(Filter::applyPropertyName('RowKey'), Filter::applyConstant($e->getRowKey(), EdmType::STRING)));
     $queryres = $this->restProxy->queryEntities($table, $qopts);
     $this->assertEquals(0, count($queryres->getEntities()), 'entities returned');
     $e = new Entity();
     $e->setRowKey('row ' . TableServiceFunctionalTestData::getUnicodeString());
     $e->setPartitionKey('niceKey');
     $this->restProxy->insertEntity($table, $e);
     $this->restProxy->deleteEntity($table, $e->getPartitionKey(), $e->getRowKey());
     $qopts = new QueryEntitiesOptions();
     $qopts->setFilter(Filter::applyEq(Filter::applyPropertyName('RowKey'), Filter::applyConstant($e->getRowKey(), EdmType::STRING)));
     $queryres = $this->restProxy->queryEntities($table, $qopts);
     $this->assertEquals(0, count($queryres->getEntities()), 'entities returned');
     $this->clearTable($table);
 }
 /**
  * @covers MicrosoftAzure\Storage\Table\Models\QueryEntitiesOptions::setFilter
  * @covers MicrosoftAzure\Storage\Table\Models\QueryEntitiesOptions::getFilter
  */
 public function testSetFilter()
 {
     // Setup
     $options = new QueryEntitiesOptions();
     $expected = Filter::applyConstant('constValue', EdmType::STRING);
     // Test
     $options->setFilter($expected);
     // Assert
     $this->assertEquals($expected, $options->getFilter());
 }
 public function testCheckQueryEntitiesOptions()
 {
     $options = new QueryEntitiesOptions();
     $query = new Query();
     $nextPartitionKey = 'aaa';
     $nextRowKey = 'bbb';
     $this->assertNull($options->getNextPartitionKey(), 'Default QueryEntitiesOptions->getNextPartitionKey');
     $this->assertNull($options->getNextRowKey(), 'Default QueryEntitiesOptions->getNextRowKey');
     $this->assertNotNull($options->getQuery(), 'Default QueryEntitiesOptions->getQuery');
     $options->setNextPartitionKey($nextPartitionKey);
     $options->setNextRowKey($nextRowKey);
     $options->setQuery($query);
     $this->assertEquals($nextPartitionKey, $options->getNextPartitionKey(), 'Set QueryEntitiesOptions->getNextPartitionKey');
     $this->assertEquals($nextRowKey, $options->getNextRowKey(), 'Set QueryEntitiesOptions->getNextRowKey');
     $this->assertEquals($query, $options->getQuery(), 'Set QueryEntitiesOptions->getQuery');
     $options->addSelectField('bar');
     $options->addSelectField('baz');
     $this->assertNotNull($options->getSelectFields(), 'Add $options->getSelectFields');
     $this->assertNotNull($options->getQuery()->getSelectFields(), 'Add $options->getQuery->getSelectFields');
     $this->assertEquals(2, count($options->getSelectFields()), 'Add $options->getSelectFields->size');
     $this->assertEquals(2, count($options->getQuery()->getSelectFields()), 'Add $options->getQuery->getSelectFields->size');
     $filter = Filter::applyConstant('foo', EdmType::STRING);
     $options->setFilter($filter);
     $options->setSelectFields(null);
     $options->setTop(TableServiceFunctionalTestData::INT_MAX_VALUE);
     $this->assertEquals($filter, $options->getFilter(), 'Set $options->getFilter');
     $this->assertEquals($filter, $options->getQuery()->getFilter(), 'Set $options->getQuery->getFilter');
     $this->assertNull($options->getSelectFields(), 'Set $options->getSelectFields');
     $this->assertNull($options->getQuery()->getSelectFields(), 'Set $options->getQuery->getSelectFields');
     $this->assertEquals(TableServiceFunctionalTestData::INT_MAX_VALUE, $options->getTop(), 'Set $options->getTop');
     $this->assertEquals(TableServiceFunctionalTestData::INT_MAX_VALUE, $options->getQuery()->getTop(), 'Set $options->getQuery->getTop');
 }
 /**
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::deleteEntity
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::getEntity
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertEntity
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::queryEntities
  */
 public function testDeleteEntityTroublesomeKeyWorks()
 {
     // The service does not allow the following common characters in keys:
     // * chr(35) = '#'
     // * chr(47) = '/'
     // * chr(63) = '?'
     // * chr(92) = '\'
     //
     // In addition, the following values are not allowed, as they make the URL bad:
     // * 0-31, 127-159
     // That still leaves several options for making troublesome keys
     // * spaces
     // * single quotes
     // * Unicode
     // These need to be properly encoded when passed on the URL, else there will be trouble
     // Arrange
     $entity1 = new Entity();
     $entity1->setPartitionKey('001');
     $entity1->setRowKey('key with spaces');
     $entity2 = new Entity();
     $entity2->setPartitionKey('001');
     $entity2->setRowKey('key\'with\'quotes');
     $entity3 = new Entity();
     $entity3->setPartitionKey('001');
     $entity3->setRowKey('keyWithUnicode' . chr(0xeb) . chr(0x8b) . chr(0xa4));
     // \uB2E4 in UTF8
     $entity4 = new Entity();
     $entity4->setPartitionKey('001');
     $entity4->setRowKey('key \'with\'\'' . chr(0xeb) . chr(0x8b) . chr(0xa4));
     // \uB2E4 in UTF8
     $entity5 = new Entity();
     $entity5->setPartitionKey('001');
     $entity5->setRowKey('Qbert_Says=.!@%^&');
     // Act
     $result1 = $this->restProxy->insertEntity(self::$testTable8, $entity1);
     $result2 = $this->restProxy->insertEntity(self::$testTable8, $entity2);
     $result3 = $this->restProxy->insertEntity(self::$testTable8, $entity3);
     $result4 = $this->restProxy->insertEntity(self::$testTable8, $entity4);
     $result5 = $this->restProxy->insertEntity(self::$testTable8, $entity5);
     $this->restProxy->deleteEntity(self::$testTable8, $result1->getEntity()->getPartitionKey(), $result1->getEntity()->getRowKey());
     $this->restProxy->deleteEntity(self::$testTable8, $result2->getEntity()->getPartitionKey(), $result2->getEntity()->getRowKey());
     $this->restProxy->deleteEntity(self::$testTable8, $result3->getEntity()->getPartitionKey(), $result3->getEntity()->getRowKey());
     $this->restProxy->deleteEntity(self::$testTable8, $result4->getEntity()->getPartitionKey(), $result4->getEntity()->getRowKey());
     $this->restProxy->deleteEntity(self::$testTable8, $result5->getEntity()->getPartitionKey(), $result5->getEntity()->getRowKey());
     // Assert
     try {
         $this->restProxy->getEntity(self::$testTable8, $result1->getEntity()->getPartitionKey(), $result1->getEntity()->getRowKey());
         $this->fail('Expect an exception when getting an entity that does not exist');
     } catch (ServiceException $e) {
         $this->assertEquals(TestResources::STATUS_NOT_FOUND, $e->getCode(), 'getCode');
     }
     $qopts = new QueryEntitiesOptions();
     $qopts->setFilter(Filter::applyEq(Filter::applyPropertyName('RowKey'), Filter::applyConstant('key\'with\'quotes', EdmType::STRING)));
     $assertResult2 = $this->restProxy->queryEntities(self::$testTable8, $qopts);
     $this->assertEquals(0, count($assertResult2->getEntities()), 'entities returned');
     $assertResult3 = $this->restProxy->queryEntities(self::$testTable8);
     foreach ($assertResult3->getEntities() as $entity) {
         $this->assertFalse($entity3->getRowKey() == $entity->getRowKey(), 'Entity3 should be removed from the table');
         $this->assertFalse($entity4->getRowKey() == $entity->getRowKey(), 'Entity4 should be removed from the table');
         $this->assertFalse($entity5->getRowKey() == $entity->getRowKey(), 'Entity5 should be removed from the table');
     }
 }
Пример #5
0
 /**
  * Quries entities for the given table name
  *
  * @param string                                           $table   The name of
  * the table.
  * @param Models\QueryEntitiesOptions|string|Models\Filter $options Coule be
  * optional parameters, query string or filter to apply.
  *
  * @return Models\QueryEntitiesResult
  *
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179421.aspx
  */
 public function queryEntities($table, $options = null)
 {
     Validate::isString($table, 'table');
     Validate::notNullOrEmpty($table, 'table');
     $method = Resources::HTTP_GET;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $statusCode = Resources::STATUS_OK;
     $path = $table;
     if (is_null($options)) {
         $options = new QueryEntitiesOptions();
     } else {
         if (is_string($options)) {
             $queryString = $options;
             $options = new QueryEntitiesOptions();
             $options->setFilter(Filter::applyQueryString($queryString));
         } else {
             if ($options instanceof Filter) {
                 $filter = $options;
                 $options = new QueryEntitiesOptions();
                 $options->setFilter($filter);
             }
         }
     }
     $queryParams = $this->_addOptionalQuery($queryParams, $options->getQuery());
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->addOptionalQueryParam($queryParams, Resources::QP_NEXT_PK, $options->getNextPartitionKey());
     $this->addOptionalQueryParam($queryParams, Resources::QP_NEXT_RK, $options->getNextRowKey());
     $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, Resources::XML_ATOM_CONTENT_TYPE);
     if (!is_null($options->getQuery())) {
         $dsHeader = Resources::DATA_SERVICE_VERSION;
         $maxdsValue = Resources::MAX_DATA_SERVICE_VERSION_VALUE;
         $fields = $options->getQuery()->getSelectFields();
         $hasSelect = !empty($fields);
         if ($hasSelect) {
             $this->addOptionalHeader($headers, $dsHeader, $maxdsValue);
         }
     }
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
     $entities = $this->_atomSerializer->parseEntities($response->getBody());
     return QueryEntitiesResult::create(HttpFormatter::formatHeaders($response->getHeaders()), $entities);
 }