/**
  * @covers MicrosoftAzure\Storage\Table\Models\QueryTablesOptions::setPrefix
  * @covers MicrosoftAzure\Storage\Table\Models\QueryTablesOptions::getPrefix
  */
 public function testSetPrefix()
 {
     // Setup
     $options = new QueryTablesOptions();
     $expected = 'prefix';
     // Test
     $options->setPrefix($expected);
     // Assert
     $this->assertEquals($expected, $options->getPrefix());
 }
 /**
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::queryTables
  */
 public function testQueryTablesWithPrefixWorks()
 {
     // Act
     $qto = new QueryTablesOptions();
     $qto->setPrefix(self::$testTablesPrefix);
     $result = $this->restProxy->queryTables($qto);
     // Assert
     $this->assertNotNull($result, '$result');
 }
Esempio n. 3
0
 /**
  * Quries tables in the given storage account.
  *
  * @param Models\QueryTablesOptions|string|Models\Filter $options Could be
  * optional parameters, table prefix or filter to apply.
  *
  * @return Models\QueryTablesResult
  *
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179405.aspx
  */
 public function queryTables($options = null)
 {
     $method = Resources::HTTP_GET;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $statusCode = Resources::STATUS_OK;
     $path = 'Tables';
     if (is_null($options)) {
         $options = new QueryTablesOptions();
     } else {
         if (is_string($options)) {
             $prefix = $options;
             $options = new QueryTablesOptions();
             $options->setPrefix($prefix);
         } else {
             if ($options instanceof Filter) {
                 $filter = $options;
                 $options = new QueryTablesOptions();
                 $options->setFilter($filter);
             }
         }
     }
     $query = $options->getQuery();
     $next = $options->getNextTableName();
     $prefix = $options->getPrefix();
     $timeout = $options->getTimeout();
     if (!empty($prefix)) {
         // Append Max char to end '{' is 1 + 'z' in AsciiTable ==> upperBound
         // is prefix + '{'
         $prefixFilter = Filter::applyAnd(Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant($prefix, EdmType::STRING)), Filter::applyLe(Filter::applyPropertyName('TableName'), Filter::applyConstant($prefix . '{', EdmType::STRING)));
         if (is_null($query)) {
             $query = new Models\Query();
         }
         if (is_null($query->getFilter())) {
             // use the prefix filter if the query filter is null
             $query->setFilter($prefixFilter);
         } else {
             // combine and use the prefix filter if the query filter exists
             $combinedFilter = Filter::applyAnd($query->getFilter(), $prefixFilter);
             $query->setFilter($combinedFilter);
         }
     }
     $queryParams = $this->_addOptionalQuery($queryParams, $query);
     $this->addOptionalQueryParam($queryParams, Resources::QP_NEXT_TABLE_NAME, $next);
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $timeout);
     // One can specify the NextTableName option to get table entities starting
     // from the specified name. However, there appears to be an issue in the
     // Azure Table service where this does not engage on the server unless
     // $filter appears in the URL. The current behavior is to just ignore the
     // NextTableName options, which is not expected or easily detectable.
     if (array_key_exists(Resources::QP_NEXT_TABLE_NAME, $queryParams) && !array_key_exists(Resources::QP_FILTER, $queryParams)) {
         $queryParams[Resources::QP_FILTER] = Resources::EMPTY_STRING;
     }
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
     $tables = $this->_atomSerializer->parseTableEntries($response->getBody());
     return QueryTablesResult::create(HttpFormatter::formatHeaders($response->getHeaders()), $tables);
 }
 /**
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::queryTables
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::_buildFilterExpression
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::_buildFilterExpressionRec
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::_addOptionalQuery
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::_encodeODataUriValues
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::_encodeODataUriValue
  * @covers MicrosoftAzure\Storage\Table\Models\EdmType::serializeQueryValue
  * @covers MicrosoftAzure\Storage\Table\Models\QueryTablesResult::create
  * @covers MicrosoftAzure\Storage\Table\Internal\AtomReaderWriter::_parseBody
  * @covers MicrosoftAzure\Storage\Table\Internal\AtomReaderWriter::parseTableEntries
  * @covers MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::sendContext
  */
 public function testQueryTablesWithPrefix()
 {
     $this->skipIfEmulated();
     // Setup
     $name1 = 'wquerytableswithprefix1';
     $name2 = 'querytableswithprefix2';
     $name3 = 'querytableswithprefix3';
     $options = new QueryTablesOptions();
     $options->setPrefix('q');
     $this->createTable($name1);
     $this->createTable($name2);
     $this->createTable($name3);
     // Test
     $result = $this->restProxy->queryTables($options);
     // Assert
     $tables = $result->getTables();
     $this->assertCount(2, $tables);
     $this->assertEquals($name2, $tables[0]);
     $this->assertEquals($name3, $tables[1]);
 }
 /**
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::createTable
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::deleteTable
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::queryTables
  */
 private function deleteTableWorker($options)
 {
     $Table = TableServiceFunctionalTestData::getInterestingTableName();
     // Make sure that the list of all applicable Tables is correctly updated.
     $qto = new QueryTablesOptions();
     if (!$this->isEmulated()) {
         // The emulator has problems with some queries,
         // but full Azure allow this to be more efficient:
         $qto->setPrefix(TableServiceFunctionalTestData::$testUniqueId);
     }
     $qsStart = $this->restProxy->queryTables($qto);
     // Make sure there is something to delete.
     $this->restProxy->createTable($Table);
     // Make sure that the list of all applicable Tables is correctly updated.
     $qs = $this->restProxy->queryTables($qto);
     $this->assertEquals(count($qsStart->getTables()) + 1, count($qs->getTables()), 'After adding one, with Prefix=(\'' . TableServiceFunctionalTestData::$testUniqueId . '\'), then count Tables');
     $deleted = false;
     if (is_null($options)) {
         $this->restProxy->deleteTable($Table);
     } else {
         $this->restProxy->deleteTable($Table, $options);
     }
     $deleted = true;
     if (is_null($options)) {
         $options = new TableServiceOptions();
     }
     // Make sure that the list of all applicable Tables is correctly updated.
     $qs = $this->restProxy->queryTables($qto);
     if (!$deleted) {
         $this->println('Test didn\'t delete the $Table, so try again more simply');
         // Try again. If it doesn't work, not much else to try.
         $this->restProxy->deleteTable($Table);
     }
     $this->assertEquals(count($qsStart->getTables()), count($qs->getTables()), 'After adding then deleting one, with Prefix=(\'' . TableServiceFunctionalTestData::$testUniqueId . '\'), then count(Tables)');
 }
 static function getInterestingQueryTablesOptions($isEmulated)
 {
     $ret = array();
     $options = new QueryTablesOptions();
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $options->setTop(2);
     $options->setPrefix(self::$nonExistTablePrefix);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $options->setTop(-2);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyEq(Filter::applyConstant(self::$testTableNames[1]), Filter::applyPropertyName('TableName'));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyEq(Filter::applyConstant(self::$testTableNames[2]), Filter::applyPropertyName('TableName'));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyAnd(Filter::applyEq(Filter::applyConstant(self::$testTableNames[1]), Filter::applyPropertyName('TableName')), Filter::applyEq(Filter::applyConstant(self::$testTableNames[2]), Filter::applyPropertyName('TableName')));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyAnd(Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$testTableNames[1])), Filter::applyLe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$testTableNames[2])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyOr(Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$testTableNames[1])), Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$testTableNames[2])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyAnd(Filter::applyEq(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$testTableNames[1])), Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$testTableNames[0])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyOr(Filter::applyEq(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$testTableNames[1])), Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$testTableNames[2])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyOr(Filter::applyEq(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$testTableNames[1])), Filter::applyEq(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$testTableNames[2])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyOr(Filter::applyEq(Filter::applyConstant(self::$testTableNames[1]), Filter::applyPropertyName('TableName')), Filter::applyEq(Filter::applyConstant(self::$testTableNames[2]), Filter::applyPropertyName('TableName')));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $options->setPrefix(self::$nonExistTablePrefix);
     array_push($ret, $options);
     if (!$isEmulated) {
         $options = new QueryTablesOptions();
         $options->setPrefix(self::$testUniqueId);
         array_push($ret, $options);
     }
     $options = new QueryTablesOptions();
     $nextTableName = self::$testTableNames[1];
     $options->setNextTableName($nextTableName);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $nextTableName = self::$nonExistTablePrefix;
     $options->setNextTableName($nextTableName);
     array_push($ret, $options);
     return $ret;
 }