/** * @covers WindowsAzure\Table\Models\Filters\Filter::applyOr * @covers WindowsAzure\Table\Models\Filters\Filter::applyPropertyName * @covers WindowsAzure\Table\Models\Filters\Filter::applyQueryString */ public function testApplyOr() { // Setup $left = Filter::applyPropertyName('test'); $right = Filter::applyQueryString('raw string'); // Test $actual = Filter::applyOr($left, $right); // Assert $this->assertEquals($left, $actual->getLeft()); $this->assertEquals($right, $actual->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; }
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'); }
private static function generateFilterWithBooleanParameters($targetDepth, $depth) { // Use the filter grammar to construct a tree. // The random here is not to generate random values, but to // get a good mix of values in the table entities. // TODO: Treat raw string special if ($depth == $targetDepth) { switch (mt_rand(0, 2)) { case 0: return self::generateBinaryFilterWithAnyParameters(); case 1: return Filter::applyConstant(mt_rand(0, 1) == 1, EdmType::BOOLEAN); case 2: $e = self::getEntityFromTable(); $boolPropNames = array(); foreach ($e->getProperties() as $key => $p) { if ($p->getEdmType() == EdmType::BOOLEAN) { array_push($boolPropNames, $key); } } if (count($boolPropNames) == 0) { return Filter::applyConstant(mt_rand(0, 1) == 1, EdmType::BOOLEAN); } else { $key = $boolPropNames[mt_rand(0, count($boolPropNames) - 1)]; return Filter::applyPropertyName($key); } default: return null; } } else { switch (mt_rand(0, 8)) { case 0: case 1: case 2: case 3: return Filter::applyAnd(self::generateFilterWithBooleanParameters($targetDepth, $depth + 1), self::generateFilterWithBooleanParameters($targetDepth, $depth + 1)); case 4: case 5: case 6: case 7: return Filter::applyOr(self::generateFilterWithBooleanParameters($targetDepth, $depth + 1), self::generateFilterWithBooleanParameters($targetDepth, $depth + 1)); case 8: return Filter::applyNot(self::generateFilterWithBooleanParameters($targetDepth, $depth + 1)); default: return null; } } }