예제 #1
0
 public function testSearchColumns()
 {
     $this->engine->searchColumns('id');
     $this->assertEquals(array('id'), $this->engine->getSearchingColumns());
     $this->engine->searchColumns('name', 'email');
     $this->assertEquals(array('name', 'email'), $this->engine->getSearchingColumns());
     $this->engine->searchColumns(array('foo', 'bar'));
     $this->assertEquals(array('foo', 'bar'), $this->engine->getSearchingColumns());
 }
 public function testSearch()
 {
     // Facade expection
     Input::replace(array('sSearch' => 'eoo'));
     $engine = new CollectionEngine(new Collection($this->getTestArray()));
     $engine->addColumn($this->getTestColumns());
     $engine->searchColumns('id');
     $engine->setAliasMapping();
     $should = '{"aaData":[{"id":"eoo"}],"sEcho":0,"iTotalRecords":2,"iTotalDisplayRecords":1}';
     $actual = $engine->make()->getContent();
     $this->assertEquals($should, $actual);
     //------------------TEST 2-----------------
     // search in outputed data
     $engine = new CollectionEngine(new Collection(array(array('foo', 'foo2', 'foo3'), array('bar', 'bar2', 'bar3'))));
     $engine->addColumn(new FunctionColumn('bla', function ($row) {
         return $row[0] . " - " . $row[1];
     }));
     $engine->addColumn(new FunctionColumn('1', function ($row) {
         return $row[2];
     }));
     $engine->addColumn(new FunctionColumn('bla3', function ($row) {
         return $row[0] . " - " . $row[2];
     }));
     $engine->searchColumns("bla", 1);
     $engine->setAliasMapping();
     Input::replace(array('sSearch' => 'foo2'));
     $should = array(array('bla' => 'foo - foo2', '1' => 'foo3', 'bla3' => 'foo - foo3'));
     $response = json_decode($engine->make()->getContent());
     $this->assertEquals(json_encode($should), json_encode((array) $response->aaData));
     //------------------TEST 3-----------------
     // search in initial data
     // TODO: Search in initial data columns?
     $engine = new CollectionEngine(new Collection(array(array('foo', 'foo2', 'foo3'), array('bar', 'bar2', 'bar3'))));
     $engine->addColumn(new FunctionColumn('bla3', function ($row) {
         return $row[0] . " - " . $row[2];
     }));
     $engine->addColumn(new FunctionColumn('1', function ($row) {
         return $row[1];
     }));
     $engine->searchColumns("bla3", 1);
     $engine->setAliasMapping();
     Input::replace(array('sSearch' => 'foo2'));
     $should = array(array('bla3' => 'foo - foo3', '1' => 'foo2'));
     $response = json_decode($engine->make()->getContent());
     $this->assertEquals(json_encode($should), json_encode($response->aaData));
 }