Esempio n. 1
0
 /**
  * Test the build process.
  *
  * @return void
  */
 public function testBuild()
 {
     $metaModel = new MetaModel(array('id' => '1', 'sorting' => '1', 'tstamp' => '0', 'name' => 'MetaModel', 'tableName' => 'mm_test', 'mode' => '', 'translated' => '1', 'languages' => array('en' => array('isfallback' => '1'), 'de' => array('isfallback' => '')), 'varsupport' => '1'));
     /** @var \MetaModels\Attribute\Base $attribute */
     $attribute = $this->getMockForAbstractClass('MetaModels\\Attribute\\Base', array($metaModel, array('colname' => 'test1')));
     $metaModel->addAttribute($attribute);
     $config = DefaultConfig::init();
     $config->setFilter(array(array('operation' => '=', 'property' => 'foo', 'value' => 0)));
     $dataBase = Database::getNewTestInstance();
     $builder = new FilterBuilderSql($metaModel->getTableName(), 'AND', $dataBase);
     $dataBase->getQueryCollection()->theQuery('SELECT id FROM mm_test WHERE ((test = ?))')->with(0)->result()->addRows(array(array('id' => 0), array('id' => 1), array('id' => 2), array('id' => 3), array('id' => 4), array('id' => 5)));
     $this->assertTrue($builder->isEmpty());
     $this->assertEquals($builder, $builder->addChild(array('operation' => '=', 'property' => 'test', 'value' => 0)));
     $this->assertEquals(array(0, 1, 2, 3, 4, 5), $builder->build()->getMatchingIds());
 }
Esempio n. 2
0
 /**
  * Return empty config object.
  *
  * @return ConfigInterface
  */
 public function getEmptyConfig()
 {
     return DefaultConfig::init();
 }
Esempio n. 3
0
 /**
  * Test the build process.
  *
  * @link https://github.com/MetaModels/core/issues/700
  *
  * @return void
  */
 public function testIssue700()
 {
     $metaModel = $this->mockMetaModel();
     $dataBase = $metaModel->getServiceContainer()->getDatabase();
     $attribute = $this->getMockForAbstractClass('MetaModels\\Attribute\\Base', array($metaModel, array('colname' => 'test1')), '', true, true, true, array('searchFor'));
     $attribute->expects($this->any())->method('searchFor')->with('*test*')->will($this->returnValue(array(0, 1, 2, 3)));
     /** @var \MetaModels\Attribute\Base $attribute */
     $metaModel->addAttribute($attribute);
     $config = DefaultConfig::init();
     $config->setFilter(array(array('operation' => 'AND', 'children' => array(array('operation' => 'AND', 'children' => array(array('operation' => 'LIKE', 'property' => 'test1', 'value' => '*test*')))))));
     /** @var Database $dataBase */
     $dataBase->getQueryCollection()->theQuery('SELECT id FROM mm_test WHERE ((foo = ?))')->with(0)->result()->addRows(array(array('id' => 0), array('id' => 1), array('id' => 2), array('id' => 3), array('id' => 4), array('id' => 5)));
     $builder = new FilterBuilder($metaModel, $config);
     $filter = $builder->build();
     $this->assertEquals(array(0, 1, 2, 3), $filter->getMatchingIds());
 }