function offsetSet($offset, $criterion)
 {
     if (!$criterion instanceof QueryCriterion) {
         if (is_null($offset)) {
             throw new QueryCriteriaException('offset must be specified for non QueryCriterion value');
         }
         $criterion = QueryCriterionFactory::create(array('name' => $offset, 'value' => $criterion));
     }
     // if the offset is null, use the criterions name as the key
     if ($offset == '') {
         $offset = $criterion->name;
     }
     $this->array[$offset] = $criterion;
     // add to the qs_key container
     $qs_key = $criterion->get_qs_key(TRUE);
     // in certain circumstances, the criterion may act as a composite of
     // two QS values.
     if (is_array($qs_key)) {
         foreach ($qs_key as $qsk) {
             $this->criteria_qs_keys[$qsk] = $criterion;
         }
     } else {
         $this->criteria_qs_keys[$qs_key] = $criterion;
     }
 }
 function test_single_value_get()
 {
     global $CONF;
     $criterion = QueryCriterionFactory::create(array('name' => 'flag', 'type' => QC_TYPE_FLAG));
     $criterion->set_value(TRUE);
     $this->assertFalse($criterion->get_value(0));
     $this->assertTrue($criterion->get_value(1));
     $this->assertFalse($criterion->get_value(2));
     $this->assertFalse($criterion->get_value(3));
     $this->assertFalse($criterion->get_value(4));
 }
 private function create_page_size_criterion()
 {
     $result = QueryCriterionFactory::create(array('name' => 'page_size', 'label' => 'Display', 'type' => QC_TYPE_SORT, 'list' => array('10' => '10', '50' => '50', '100' => '100'), 'is_renderable' => FALSE, 'is_encodable' => FALSE, 'default' => 10));
     return $result;
 }
 function test_compare_ignore()
 {
     $this->container = new QueryCriteria(array(QueryCriterionFactory::create(array('name' => 'elf', 'qs_key' => 'ELF', 'value' => 'pointy_ears')), QueryCriterionFactory::create(array('name' => 'wizard', 'qs_key' => 'WIZ', 'value' => 'pointy_hat')), QueryCriterionFactory::create(array('name' => 'warrior', 'qs_key' => 'WAR', 'value' => 'pointy_sword'))));
     $other_container = new QueryCriteria(array(QueryCriterionFactory::create(array('name' => 'elf', 'qs_key' => 'ELF', 'value' => 'pointy_ears')), QueryCriterionFactory::create(array('name' => 'wizard', 'qs_key' => 'WIZ', 'value' => 'long_beard')), QueryCriterionFactory::create(array('name' => 'warrior', 'qs_key' => 'WAR', 'value' => 'pointy_sword'))));
     // ignore the fact that the wizard values don't match
     $this->assertTrue($this->container->compare($other_container, 'wizard'));
     // ignore the fact that both the wizard and warrior have mismatched values
     $other_container['warrior']->set_value('goes_by_name_of_conan');
     $this->assertTrue($this->container->compare($other_container, array('wizard', 'warrior')));
 }
 function test_search()
 {
     $table = '/test';
     $query_string = '{test=123}';
     // $criteria = Array('test'=>'123');
     $criteria = new QueryCriteria(array(QueryCriterionFactory::create(array('name' => 'test', 'value' => '123'))));
     $expected_results = array('data' => array(array('url' => '/test/123')), 'offset' => 0, 'count' => 1, 'total' => 1);
     $ds = new MockDataSource();
     // search will populate cache
     $this->cache->size = 20;
     $ds->expect('search', array($table, $query_string, 0, 20));
     $ds->setReturnValue('search', $expected_results);
     $results = $this->cache->search($ds, $table, $query_string, 0, 10, $criteria);
     $this->assertEqual($results, $expected_results);
     $this->assertEqual($this->cache->results, $expected_results);
     $this->assertEqual($this->cache->criteria, $criteria);
     // disable cache
     $this->cache->size = 0;
     $ds->expect('search', array($table, $query_string, 0, 10));
     $ds->setReturnValue('search', $expected_results);
     $results = $this->cache->search($ds, $table, $query_string, 0, 10, $criteria);
     $this->assertEqual($results, $expected_results);
 }
 function test_new_style_criteria_set()
 {
     // Accepts array or criterion
     $this->factory->configure(array('criteria_defs' => array(array('name' => 'x'), QueryCriterionFactory::create(array('name' => 'y')))));
     $query = $this->factory->new_query(array('x' => 'foo', 'y' => 'bar'));
     $this->assertEqual('foo', $query['x']->get_value());
     $this->assertEqual('bar', $query['y']->get_value());
 }