Skip to content

Commit

Permalink
Tests for integer and cursor offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
twalder-docnet committed Jun 13, 2015
1 parent 8acd43c commit 6d86c0b
Showing 1 changed file with 80 additions and 28 deletions.
108 changes: 80 additions & 28 deletions tests/ProtoBufGqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,26 @@
class ProtoBufGqlTest extends GDSTest {

/**
* Fetch one test
* This request is re-used a lot in the tests
*
* @return \google\appengine\datastore\v4\RunQueryRequest
*/
public function testFetchOneNoParams()
private function getBasicFetchRequest()
{
$str_gql = "SELECT * FROM Kind";
$obj_request = new \google\appengine\datastore\v4\RunQueryRequest();
$obj_request->mutableReadOptions();
$obj_partition = $obj_request->mutablePartitionId();
$obj_partition->setDatasetId('Dataset');
return $obj_request;
}

/**
* Fetch one test
*/
public function testFetchOneNoParams()
{
$str_gql = "SELECT * FROM Kind";
$obj_request = $this->getBasicFetchRequest();
$obj_gql_query = $obj_request->mutableGqlQuery();
$obj_gql_query->setAllowLiteral(TRUE);
$obj_gql_query->setQueryString($str_gql . " LIMIT 1");
Expand All @@ -50,13 +61,14 @@ public function testFetchOneNoParams()
*/
public function testFetchPageNoParams(){
$str_gql = "SELECT * FROM Kind";
$obj_request = new \google\appengine\datastore\v4\RunQueryRequest();
$obj_request->mutableReadOptions();
$obj_partition = $obj_request->mutablePartitionId();
$obj_partition->setDatasetId('Dataset');
$obj_request = $this->getBasicFetchRequest();
$obj_gql_query = $obj_request->mutableGqlQuery();
$obj_gql_query->setAllowLiteral(TRUE);
$obj_gql_query->setQueryString($str_gql . " LIMIT 11 ");
$obj_gql_query->setQueryString($str_gql . " LIMIT @intPageSize ");

$obj_arg = $obj_gql_query->addNameArg();
$obj_arg->setName('intPageSize');
$obj_arg->mutableValue()->setIntegerValue(11);

$this->apiProxyMock->expectCall('datastore_v4', 'RunQuery', $obj_request, new \google\appengine\datastore\v4\RunQueryResponse());

Expand All @@ -67,16 +79,68 @@ public function testFetchPageNoParams(){
$this->apiProxyMock->verify();
}

/**
* Fetch Page with record integer offset
*/
public function testFetchPageIntegerOffset(){
$str_gql = "SELECT * FROM Kind";
$obj_request = $this->getBasicFetchRequest();
$obj_gql_query = $obj_request->mutableGqlQuery();
$obj_gql_query->setAllowLiteral(TRUE);
$obj_gql_query->setQueryString($str_gql . " LIMIT @intPageSize OFFSET @intOffset");

$obj_arg = $obj_gql_query->addNameArg();
$obj_arg->setName('intPageSize');
$obj_arg->mutableValue()->setIntegerValue(11);

$obj_arg_offset = $obj_gql_query->addNameArg();
$obj_arg_offset->setName('intOffset');
$obj_arg_offset->mutableValue()->setIntegerValue(22);

$this->apiProxyMock->expectCall('datastore_v4', 'RunQuery', $obj_request, new \google\appengine\datastore\v4\RunQueryResponse());

$obj_store = $this->createBasicStore();
$obj_result = $obj_store->query($str_gql)->fetchPage(11, 22);

$this->assertEquals($obj_result, []);
$this->apiProxyMock->verify();
}

/**
* Fetch Page with cursor offset
*/
public function testFetchPageCursorOffset(){
$str_gql = "SELECT * FROM Kind";
$obj_request = $this->getBasicFetchRequest();

$obj_gql_query = $obj_request->mutableGqlQuery();
$obj_gql_query->setAllowLiteral(TRUE);
$obj_gql_query->setQueryString($str_gql . " LIMIT @intPageSize OFFSET @startCursor");

$obj_arg = $obj_gql_query->addNameArg();
$obj_arg->setName('intPageSize');
$obj_arg->mutableValue()->setIntegerValue(11);

$obj_arg_offset = $obj_gql_query->addNameArg();
$obj_arg_offset->setName('startCursor');
$obj_arg_offset->setCursor('some-cursor-string');

$this->apiProxyMock->expectCall('datastore_v4', 'RunQuery', $obj_request, new \google\appengine\datastore\v4\RunQueryResponse());

$obj_store = $this->createBasicStore();
$obj_result = $obj_store->query($str_gql)->fetchPage(11, 'some-cursor-string');

$this->assertEquals($obj_result, []);
$this->apiProxyMock->verify();
}

/**
* GQL Fetch ONE with one string parameter
*/
public function testFetchOneStringParam()
{
$str_gql = "SELECT * FROM Kind WHERE property = @param";
$obj_request = new \google\appengine\datastore\v4\RunQueryRequest();
$obj_request->mutableReadOptions();
$obj_partition = $obj_request->mutablePartitionId();
$obj_partition->setDatasetId('Dataset');
$obj_request = $this->getBasicFetchRequest();

$obj_gql_query = $obj_request->mutableGqlQuery();
$obj_gql_query->setAllowLiteral(TRUE);
Expand All @@ -100,10 +164,7 @@ public function testFetchOneStringParam()
public function testFetchAllNoParams()
{
$str_gql = "SELECT * FROM Kind";
$obj_request = new \google\appengine\datastore\v4\RunQueryRequest();
$obj_request->mutableReadOptions();
$obj_partition = $obj_request->mutablePartitionId();
$obj_partition->setDatasetId('Dataset');
$obj_request = $this->getBasicFetchRequest();
$obj_gql_query = $obj_request->mutableGqlQuery();
$obj_gql_query->setAllowLiteral(TRUE);
$obj_gql_query->setQueryString($str_gql);
Expand All @@ -123,10 +184,7 @@ public function testFetchAllNoParams()
public function testFetchOneMultiParam()
{
$str_gql = "SELECT * FROM Kind WHERE property1 = @param1 AND property2 = @param2 AND property3 = @param3";
$obj_request = new \google\appengine\datastore\v4\RunQueryRequest();
$obj_request->mutableReadOptions();
$obj_partition = $obj_request->mutablePartitionId();
$obj_partition->setDatasetId('Dataset');
$obj_request = $this->getBasicFetchRequest();

$obj_gql_query = $obj_request->mutableGqlQuery();
$obj_gql_query->setAllowLiteral(TRUE);
Expand Down Expand Up @@ -163,10 +221,7 @@ public function testFetchOneMultiParam()
public function testFetchOneEntityParam()
{
$str_gql = "SELECT * FROM Kind WHERE property = @param";
$obj_request = new \google\appengine\datastore\v4\RunQueryRequest();
$obj_request->mutableReadOptions();
$obj_partition = $obj_request->mutablePartitionId();
$obj_partition->setDatasetId('Dataset');
$obj_request = $this->getBasicFetchRequest();

$obj_gql_query = $obj_request->mutableGqlQuery();
$obj_gql_query->setAllowLiteral(TRUE);
Expand Down Expand Up @@ -196,10 +251,7 @@ public function testFetchOneEntityParam()
public function testFetchEntityGroup()
{
$str_gql = "SELECT * FROM `Book` WHERE __key__ HAS ANCESTOR @ancestorKey";
$obj_request = new \google\appengine\datastore\v4\RunQueryRequest();
$obj_request->mutableReadOptions();
$obj_partition = $obj_request->mutablePartitionId();
$obj_partition->setDatasetId('Dataset');
$obj_request = $this->getBasicFetchRequest();

$obj_gql_query = $obj_request->mutableGqlQuery();
$obj_gql_query->setAllowLiteral(TRUE);
Expand Down

0 comments on commit 6d86c0b

Please sign in to comment.