/**
  * @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 testQueryTablesWithFilterOption()
 {
     $this->skipIfEmulated();
     // Setup
     $name1 = 'wquerytableswithfilteroption1';
     $name2 = 'querytableswithfilteroption2';
     $name3 = 'querytableswithfilteroption3';
     $prefix = 'q';
     $prefixFilter = Filter::applyAnd(Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant($prefix, EdmType::STRING)), Filter::applyLe(Filter::applyPropertyName('TableName'), Filter::applyConstant($prefix . '{', EdmType::STRING)));
     $this->createTable($name1);
     $this->createTable($name2);
     $this->createTable($name3);
     // Test
     $result = $this->restProxy->queryTables($prefixFilter);
     // Assert
     $tables = $result->getTables();
     $this->assertCount(2, $tables);
     $this->assertEquals($name2, $tables[0]);
     $this->assertEquals($name3, $tables[1]);
 }
Esempio n. 2
0
 /**
  * @covers WindowsAzure\Table\Models\Filters\Filter::applyGe
  * @covers WindowsAzure\Table\Models\Filters\Filter::applyPropertyName
  * @covers WindowsAzure\Table\Models\Filters\Filter::applyQueryString
  */
 public function testApplyGe()
 {
     // Setup
     $left = Filter::applyPropertyName('test');
     $right = Filter::applyQueryString('raw string');
     // Test
     $actual = Filter::applyGe($left, $right);
     // Assert
     $this->assertEquals($left, $actual->getLeft());
     $this->assertEquals($right, $actual->getRight());
 }
 public function testCheckBinaryFilter()
 {
     $filter = new BinaryFilter(null, null, null);
     $this->assertNotNull($filter, 'Default $filter');
     $this->assertNull($filter->getLeft(), 'Default BinaryFilter->getFilter');
     $this->assertNull($filter->getOperator(), 'Default BinaryFilter->getOperator');
     $this->assertNull($filter->getRight(), 'Default BinaryFilter->getRight');
     $left = new UnaryFilter(null, null);
     $operator = 'foo';
     $right = new ConstantFilter(null, EdmType::STRING);
     $filter = new BinaryFilter($left, $operator, $right);
     $this->assertEquals($left, $filter->getLeft(), 'Set BinaryFilter->getLeft');
     $this->assertEquals($operator, $filter->getOperator(), 'Set BinaryFilter->getOperator');
     $this->assertEquals($right, $filter->getRight(), 'Set BinaryFilter->getRight');
     // Now check the factory.
     $filter = Filter::applyAnd($left, $right);
     $this->assertEquals($left, $filter->getLeft(), 'and factory BinaryFilter->getLeft');
     $this->assertEquals('and', $filter->getOperator(), 'and factory BinaryFilter->getOperator');
     $this->assertEquals($right, $filter->getRight(), 'and factory BinaryFilter->getRight');
     $filter = Filter::applyEq($left, $right);
     $this->assertEquals($left, $filter->getLeft(), 'eq factory BinaryFilter->getLeft');
     $this->assertEquals('eq', $filter->getOperator(), 'eq factory BinaryFilter->getOperator');
     $this->assertEquals($right, $filter->getRight(), 'eq factory BinaryFilter->getRight');
     $filter = Filter::applyGe($left, $right);
     $this->assertEquals($left, $filter->getLeft(), 'ge factory BinaryFilter->getLeft');
     $this->assertEquals('ge', $filter->getOperator(), 'ge factory BinaryFilter->getOperator');
     $this->assertEquals($right, $filter->getRight(), 'ge factory BinaryFilter->getRight');
     $filter = Filter::applyGt($left, $right);
     $this->assertEquals($left, $filter->getLeft(), 'gt factory BinaryFilter->getLeft');
     $this->assertEquals('gt', $filter->getOperator(), 'gt factory BinaryFilter->getOperator');
     $this->assertEquals($right, $filter->getRight(), 'gt factory BinaryFilter->getRight');
     $filter = Filter::applyLe($left, $right);
     $this->assertEquals($left, $filter->getLeft(), 'le factory BinaryFilter->getLeft');
     $this->assertEquals('le', $filter->getOperator(), 'le factory BinaryFilter->getOperator');
     $this->assertEquals($right, $filter->getRight(), 'le factory BinaryFilter->getRight');
     $filter = Filter::applyLt($left, $right);
     $this->assertEquals($left, $filter->getLeft(), 'lt factory BinaryFilter->getLeft');
     $this->assertEquals('lt', $filter->getOperator(), 'lt factory BinaryFilter->getOperator');
     $this->assertEquals($right, $filter->getRight(), 'lt factory BinaryFilter->getRight');
     $filter = Filter::applyNe($left, $right);
     $this->assertEquals($left, $filter->getLeft(), 'ne factory BinaryFilter->getLeft');
     $this->assertEquals('ne', $filter->getOperator(), 'ne factory BinaryFilter->getOperator');
     $this->assertEquals($right, $filter->getRight(), 'ne factory BinaryFilter->getRight');
     $filter = Filter::applyOr($left, $right);
     $this->assertEquals($left, $filter->getLeft(), 'or factory BinaryFilter->getLeft');
     $this->assertEquals('or', $filter->getOperator(), 'or factory BinaryFilter->getOperator');
     $this->assertEquals($right, $filter->getRight(), 'or factory BinaryFilter->getRight');
 }
 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;
 }
 private static function getBinaryFilterFromIndex($index, $f1, $f2)
 {
     switch ($index) {
         case 0:
             return Filter::applyEq($f1, $f2);
         case 1:
             return Filter::applyGe($f1, $f2);
         case 2:
             return Filter::applyGt($f1, $f2);
         case 3:
             return Filter::applyLe($f1, $f2);
         case 4:
             return Filter::applyLt($f1, $f2);
         case 5:
             return Filter::applyNe($f1, $f2);
         default:
             return null;
     }
 }
 /**
  * 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);
 }