/**
  * @covers WindowsAzure\Table\Models\QueryEntitiesOptions::setQuery
  * @covers WindowsAzure\Table\Models\QueryEntitiesOptions::getQuery
  * @covers WindowsAzure\Table\Models\QueryEntitiesOptions::__construct
  */
 public function testSetQuery()
 {
     // Setup
     $options = new QueryEntitiesOptions();
     $expected = new Query();
     // Test
     $options->setQuery($expected);
     // Assert
     $this->assertEquals($expected, $options->getQuery());
 }
 /**
  * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  */
 private function queryEntitiesWorker($options)
 {
     $table = TableServiceFunctionalTestData::$testTableNames[0];
     try {
         $ret = is_null($options) ? $this->restProxy->queryEntities($table) : $this->restProxy->queryEntities($table, $options);
         if (is_null($options)) {
             $options = new QueryEntitiesOptions();
         }
         if (!is_null($options->getQuery()) && !is_null($options->getQuery()->getTop()) && $options->getQuery()->getTop() <= 0) {
             $this->assertTrue(false, 'Expect non-positive Top in $options->query to throw');
         }
         $this->verifyqueryEntitiesWorker($ret, $options);
         // In principle, should check if there is a continuation, then use it.
         // However, the user cannot easily control when this happens, so I'm
         // not sure how useful it is.
         // To test that scenario, set NextTable in the $options.
     } catch (ServiceException $e) {
         if (!is_null($options->getQuery()) && !is_null($options->getQuery()->getTop()) && $options->getQuery()->getTop() <= 0) {
             $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
         } else {
             $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
         }
     }
 }
 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::IntegerMAX_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::IntegerMAX_VALUE, $options->getTop(), 'Set $options->getTop');
     $this->assertEquals(TableServiceFunctionalTestData::IntegerMAX_VALUE, $options->getQuery()->getTop(), 'Set $options->getQuery->getTop');
 }
Exemplo n.º 4
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($response->getHeader(), $entities);
 }