示例#1
0
 /**
  * @covers WindowsAzure\Table\Models\Filters\Filter::applyEq
  * @covers WindowsAzure\Table\Models\Filters\Filter::applyPropertyName
  * @covers WindowsAzure\Table\Models\Filters\Filter::applyQueryString
  */
 public function testApplyEq()
 {
     // Setup
     $left = Filter::applyPropertyName('test');
     $right = Filter::applyQueryString('raw string');
     // Test
     $actual = Filter::applyEq($left, $right);
     // Assert
     $this->assertEquals($left, $actual->getLeft());
     $this->assertEquals($right, $actual->getRight());
 }
 /**
  * @covers WindowsAzure\Table\TableRestProxy::deleteEntity
  * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  */
 public function testDeleteEntityTroublesomeRowKey()
 {
     // TODO: Fails because of https://github.com/WindowsAzure/azure-sdk-for-php/issues/180
     // The service does not allow the following common characters in keys:
     // 35 '#'
     // 47 '/'
     // 63 '?'
     // 92 '\'
     // In addition, the following values are not allowed, as they make the URL bad:
     // 0-31, 127-159
     // That still leaves several options for making troublesome keys
     // spaces
     // single quotes
     // Unicode
     // These need to be properly encoded when passed on the URL, else there will be trouble
     $table = TableServiceFunctionalTestData::$TEST_TABLE_NAMES[0];
     $e = new Entity();
     $e->setRowKey('row\'Key\'');
     $e->setPartitionKey('niceKey');
     $this->restProxy->insertEntity($table, $e);
     $this->restProxy->deleteEntity($table, $e->getPartitionKey(), $e->getRowKey());
     $qopts = new QueryEntitiesOptions();
     $qopts->setFilter(Filter::applyEq(Filter::applyPropertyName('RowKey'), Filter::applyConstant($e->getRowKey(), EdmType::STRING)));
     $queryres = $this->restProxy->queryEntities($table, $qopts);
     $this->assertEquals(0, count($queryres->getEntities()), 'entities returned');
     $e = new Entity();
     $e->setRowKey('row Key');
     $e->setPartitionKey('niceKey');
     $this->restProxy->insertEntity($table, $e);
     $this->restProxy->deleteEntity($table, $e->getPartitionKey(), $e->getRowKey());
     $qopts = new QueryEntitiesOptions();
     $qopts->setFilter(Filter::applyEq(Filter::applyPropertyName('RowKey'), Filter::applyConstant($e->getRowKey(), EdmType::STRING)));
     $queryres = $this->restProxy->queryEntities($table, $qopts);
     $this->assertEquals(0, count($queryres->getEntities()), 'entities returned');
     $e = new Entity();
     $e->setRowKey('row ' . TableServiceFunctionalTestData::getUnicodeString());
     $e->setPartitionKey('niceKey');
     $this->restProxy->insertEntity($table, $e);
     $this->restProxy->deleteEntity($table, $e->getPartitionKey(), $e->getRowKey());
     $qopts = new QueryEntitiesOptions();
     $qopts->setFilter(Filter::applyEq(Filter::applyPropertyName('RowKey'), Filter::applyConstant($e->getRowKey(), EdmType::STRING)));
     $queryres = $this->restProxy->queryEntities($table, $qopts);
     $this->assertEquals(0, count($queryres->getEntities()), 'entities returned');
     $this->clearTable($table);
 }
 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;
     }
 }
 /**
  * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  */
 public function testQueryEntitiesWithFilterWorks()
 {
     // Arrange
     $table = self::$testTable5;
     $numberOfEntries = 5;
     $entities = array();
     for ($i = 0; $i < $numberOfEntries; $i++) {
         $entity = new Entity();
         $entity->setPartitionKey('001');
         $entity->setRowKey('queryEntitiesWithFilterWorks-' . $i);
         $entity->addProperty('test', EdmType::BOOLEAN, $i % 2 == 0);
         $entity->addProperty('test2', EdmType::STRING, '\'value" ' . $i);
         $entity->addProperty('test3', EdmType::INT32, $i);
         $entity->addProperty('test4', EdmType::INT64, strval('12345678901' + $i));
         $entity->addProperty('test5', EdmType::DATETIME, new \DateTime('2012-01-0' . $i));
         $entity->addProperty('test6', EdmType::BINARY, chr($i));
         $entity->addProperty('test7', EdmType::GUID, Utilities::getGuid());
         $entities[$i] = $entity;
         $this->restProxy->insertEntity($table, $entity);
     }
     // Act
     $f = Filter::applyEq(Filter::applyPropertyName('RowKey'), Filter::applyConstant('queryEntitiesWithFilterWorks-3', EdmType::STRING));
     $q = new Query();
     $q->setFilter($f);
     $qeo = new QueryEntitiesOptions();
     $qeo->setQuery($q);
     $result = $this->restProxy->queryEntities($table, $qeo);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())');
     $resEnts = $result->getEntities();
     $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()');
     // Act
     $q = new Query();
     $q->setFilter(Filter::applyQueryString('RowKey eq \'queryEntitiesWithFilterWorks-3\''));
     $qeo = new QueryEntitiesOptions();
     $qeo->setQuery($q);
     $result = $this->restProxy->queryEntities($table, $qeo);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())');
     $resEnts = $result->getEntities();
     $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()');
     // Act
     $q = new Query();
     $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test'), Filter::applyConstant(true, EdmType::BOOLEAN)));
     $qeo = new QueryEntitiesOptions();
     $qeo->setQuery($q);
     $result = $this->restProxy->queryEntities($table, $qeo);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertEquals(3, count($result->getEntities()), 'count($result->getEntities())');
     // Act
     $q = new Query();
     $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test2'), Filter::applyConstant('\'value" 3', EdmType::STRING)));
     $qeo = new QueryEntitiesOptions();
     $qeo->setQuery($q);
     $result = $this->restProxy->queryEntities($table, $qeo);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())');
     $resEnts = $result->getEntities();
     $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()');
     // Act
     $q = new Query();
     $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test4'), Filter::applyConstant(12345678903, EdmType::INT64)));
     $qeo = new QueryEntitiesOptions();
     $qeo->setQuery($q);
     $result = $this->restProxy->queryEntities($table, $qeo);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())');
     $resEnts = $result->getEntities();
     $this->assertEquals('queryEntitiesWithFilterWorks-2', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()');
     // Act
     $q = new Query();
     $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test5'), Filter::applyConstant(new \DateTime('2012-01-03'), EdmType::DATETIME)));
     $qeo = new QueryEntitiesOptions();
     $qeo->setQuery($q);
     $result = $this->restProxy->queryEntities($table, $qeo);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())');
     $resEnts = $result->getEntities();
     $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()');
     // Act
     $q = new Query();
     $ent3 = $entities[3];
     $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test6'), Filter::applyConstant(chr(3), EdmType::BINARY)));
     $qeo = new QueryEntitiesOptions();
     $qeo->setQuery($q);
     $result = $this->restProxy->queryEntities($table, $qeo);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())');
     $resEnts = $result->getEntities();
     $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()');
     // Act
     $q = new Query();
     $ent3 = $entities[3];
     $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test7'), Filter::applyConstant($ent3->getPropertyValue('test7'), EdmType::GUID)));
     $qeo = new QueryEntitiesOptions();
     $qeo->setQuery($q);
     $result = $this->restProxy->queryEntities($table, $qeo);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())');
     $resEnts = $result->getEntities();
     $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()');
 }