Exemplo n.º 1
0
 function testFactory()
 {
     $filter = Filter::col('test', '=', 1);
     $actual = $filter->render();
     $expected = array("test = ?", array(1));
     $this->assertSame($expected, $actual);
 }
Exemplo n.º 2
0
 function testFactory()
 {
     $condition = "lower(name) = ?";
     $arguments = array('foo');
     $filter = Filter::raw($condition, $arguments);
     $actual = $filter->render();
     $expected = array($condition, $arguments);
 }
Exemplo n.º 3
0
 /**
  * Adds a new filter to the queryset. If multiple filters are added, they
  * will be joined by an AND composite filter.
  */
 private function addFilter(Filter $filter)
 {
     // Start with an empty AND composite filter
     if (!isset($this->filter)) {
         $this->filter = Filter::_and();
     }
     $this->checkFilter($filter);
     $this->filter->add($filter);
 }
Exemplo n.º 4
0
 public function testFactoryAndOr()
 {
     $actual = Filter::_and();
     $expected = new CompositeFilter(CompositeFilter::OP_AND);
     $this->assertEquals($expected, $actual);
     $actual = Filter::_or();
     $expected = new CompositeFilter(CompositeFilter::OP_OR);
     $this->assertEquals($expected, $actual);
 }
Exemplo n.º 5
0
 public function testFilterQS()
 {
     $f = new ColumnFilter('name', '=', 'x');
     $qs1 = Person::objects();
     $qs2 = $qs1->filter('name', '=', 'x');
     $this->assertNotEquals($qs1, $qs2);
     $this->assertNotSame($qs1, $qs2);
     $this->assertInstanceOf("\\Phormium\\Filter\\CompositeFilter", $qs2->getFilter());
     $this->assertCount(1, $qs2->getFilter()->getFilters());
     $this->assertEmpty($qs1->getOrder());
     $this->assertEmpty($qs2->getOrder());
     $expected = Filter::_and($f);
     $actual = $qs2->getFilter();
     $this->assertEquals($expected, $actual);
 }
Exemplo n.º 6
0
 /** Constructs a WHERE clause for a given filter. */
 private function constructWhere(Filter $filter = null)
 {
     if ($filter === null) {
         return array("", array());
     }
     list($where, $args) = $filter->render();
     if (empty($where)) {
         return array("", array());
     }
     $where = " WHERE {$where}";
     return array($where, $args);
 }