/**
  * @covers WindowsAzure\Table\TableRestProxy::queryTables
  * @covers WindowsAzure\Table\TableRestProxy::_buildFilterExpression
  * @covers WindowsAzure\Table\TableRestProxy::_buildFilterExpressionRec
  * @covers WindowsAzure\Table\TableRestProxy::_addOptionalQuery
  * @covers WindowsAzure\Table\TableRestProxy::_encodeODataUriValues
  * @covers WindowsAzure\Table\TableRestProxy::_encodeODataUriValue
  * @covers WindowsAzure\Table\Models\EdmType::serializeQueryValue
  * @covers WindowsAzure\Table\Models\QueryTablesResult::create
  * @covers WindowsAzure\Table\Internal\AtomReaderWriter::_parseBody
  * @covers WindowsAzure\Table\Internal\AtomReaderWriter::parseTableEntries
  * @covers WindowsAzure\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 WindowsAzure\Table\TableRestProxy::createTable
  * @covers WindowsAzure\Table\TableRestProxy::deleteTable
  * @covers WindowsAzure\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 (!Configuration::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)');
 }
 /**
  * @covers WindowsAzure\Table\Models\QueryTablesOptions::setFilter
  * @covers WindowsAzure\Table\Models\QueryTablesOptions::getFilter
  */
 public function testSetFilter()
 {
     // Setup
     $options = new QueryTablesOptions();
     $expected = Filter::applyConstant('constValue', EdmType::STRING);
     // Test
     $options->setFilter($expected);
     // Assert
     $this->assertEquals($expected, $options->getFilter());
 }
 public function testCheckQueryTablesOptions()
 {
     $options = new QueryTablesOptions();
     $nextTableName = 'foo';
     $filter = new Filter();
     $this->assertNull($options->getNextTableName(), 'Default QueryTablesOptions->getNextTableName');
     $this->assertNotNull($options->getQuery(), 'Default QueryTablesOptions->getQuery');
     $options->setNextTableName($nextTableName);
     $options->setFilter($filter);
     $options->setTop(10);
     $this->assertEquals($nextTableName, $options->getNextTableName(), 'Set QueryTablesOptions->getNextTableName');
     $this->assertEquals($filter, $options->getFilter(), 'Set QueryTablesOptions->getFilter');
     $this->assertEquals($filter, $options->getQuery()->getFilter(), 'Set QueryTablesOptions->getQuery->getFilter');
     $this->assertEquals(10, $options->getTop(), 'Set QueryTablesOptions->getTop');
     $this->assertEquals(10, $options->getQuery()->getTop(), 'Set QueryTablesOptions->getQuery->getTop');
 }
 static function getInterestingQueryTablesOptions()
 {
     $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::$TEST_TABLE_NAMES[1]), Filter::applyPropertyName('TableName'));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyEq(Filter::applyConstant(self::$TEST_TABLE_NAMES[2]), Filter::applyPropertyName('TableName'));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyAnd(Filter::applyEq(Filter::applyConstant(self::$TEST_TABLE_NAMES[1]), Filter::applyPropertyName('TableName')), Filter::applyEq(Filter::applyConstant(self::$TEST_TABLE_NAMES[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::$TEST_TABLE_NAMES[1])), Filter::applyLe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[2])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyOr(Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[1])), Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[2])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyAnd(Filter::applyEq(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[1])), Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[0])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyOr(Filter::applyEq(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[1])), Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[2])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyOr(Filter::applyEq(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[1])), Filter::applyEq(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[2])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyOr(Filter::applyEq(Filter::applyConstant(self::$TEST_TABLE_NAMES[1]), Filter::applyPropertyName('TableName')), Filter::applyEq(Filter::applyConstant(self::$TEST_TABLE_NAMES[2]), Filter::applyPropertyName('TableName')));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $options->setPrefix(self::$nonExistTablePrefix);
     array_push($ret, $options);
     if (!Configuration::isEmulated()) {
         $options = new QueryTablesOptions();
         $options->setPrefix(self::$testUniqueId);
         array_push($ret, $options);
     }
     $options = new QueryTablesOptions();
     $nextTableName = self::$TEST_TABLE_NAMES[1];
     $options->setNextTableName($nextTableName);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $nextTableName = self::$nonExistTablePrefix;
     $options->setNextTableName($nextTableName);
     array_push($ret, $options);
     return $ret;
 }
 /**
  * Lists all tables in this storage service.
  * 
  * @return array
  */
 public function listTables()
 {
     $nextTableName = null;
     $tables = array();
     do {
         $options = new QueryTablesOptions();
         $options->setNextTableName($nextTableName);
         $result = $this->_tableProxy->queryTables();
         $nextTableName = $result->getNextTableName();
         $tables = array_merge($tables, $result->getTables());
     } while (!is_null($nextTableName));
     return $tables;
 }
 /**
  * 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($response->getHeader(), $tables);
 }
 /**
  * @covers WindowsAzure\Table\TableRestProxy::queryTables
  */
 public function testQueryTablesWithPrefixWorks()
 {
     // Act
     $qto = new QueryTablesOptions();
     $qto->setPrefix(self::$testTablesPrefix);
     $result = $this->restProxy->queryTables($qto);
     // Assert
     $this->assertNotNull($result, '$result');
 }