Exemple #1
0
 function test_setHaving()
 {
     // which company has exactly 2 workers???
     $userIds = array();
     $user = new tests_Common(TABLE_USER);
     $newData = array('login' => 'hans', 'password' => '0', 'name' => 'Hans Dampf', 'address_id' => 0, 'company_id' => 1);
     $userIds[] = $user->add($newData);
     $user->reset();
     $user->setWhere('id IN (' . implode(', ', $userIds) . ')');
     $user->setGroup('company_id');
     $user->setHaving('count(id) = 2');
     $this->assertEquals(array(), $user->getCol('company_id'));
     // there are no company with 2 workers
     $newData = array('login' => 'rudi', 'password' => '0', 'name' => 'Rudi Ratlos', 'address_id' => 0, 'company_id' => 1);
     $userIds[] = $user->add($newData);
     $newData = array('login' => 'susi', 'password' => '0', 'name' => 'Susi Sorglos', 'address_id' => 0, 'company_id' => 5);
     $userIds[] = $user->add($newData);
     $user->reset();
     $user->setWhere('id IN (' . implode(', ', $userIds) . ')');
     $user->setGroup('company_id');
     $user->setHaving('count(id) = 2');
     $this->assertEquals(array(1), $user->getCol('company_id'));
     // company 1 has exactly 2 workers
     $newData = array('login' => 'lieschen', 'password' => '0', 'name' => 'Lieschen Mueller', 'address_id' => 0, 'company_id' => 5);
     $userIds[] = $user->add($newData);
     $user->reset();
     $user->setWhere('id IN (' . implode(', ', $userIds) . ')');
     $user->setGroup('company_id');
     $user->setHaving('count(id) = 2');
     $this->assertEquals(array(1, 5), $user->getCol('company_id'));
     // company 1 and 5 has exactly 2 workers
 }
Exemple #2
0
 function test_addWhereSearch()
 {
     $user = new tests_Common(TABLE_USER);
     $user->removeAll();
     $user->add(array('name' => 'Wolfram Kriesing'));
     $user->add(array('name' => 'WOLFRAM Daniel KrIESIng'));
     $user->add(array('name' => ' kriesing   wolfram '));
     $user->setWhere();
     $user->addWhereSearch('name', 'Wolfram Kriesing');
     $this->assertEquals(2, $user->getCount(), 'getCount(): Did not find the inserted number of user names.');
     $user->add(array('name' => 'Wolfram and here goes some string Kriesing but it should be found'));
     $user->add(array('name' => '%Wolfram man in the middle :-) Kriesing and smthg behind%'));
     $this->assertEquals(4, $user->getCount(), 'getCount(): Did not find the inserted number of user names.');
     $user->removeAll();
 }