예제 #1
0
 function Test_of_findBy()
 {
     $Users = new AkTestUser();
     $User = $Users->findBy('first', "first_name AND last_name", 'Tim', "O'Reilly");
     $this->assertTrue($User->first_name == 'Tim' && $User->last_name == "O'Reilly" && $User->user_name == 'tim_oreilly');
     $User_arr = $Users->findBy("first_name AND last_name", 'Tim', "O'Reilly");
     $this->assertTrue($User_arr[0]->first_name == 'Tim' && $User_arr[0]->last_name == "O'Reilly" && $User_arr[0]->user_name == 'tim_oreilly');
     $User_arr = $Users->findBy('all', "first_name AND last_name", 'Tim', "O'Reilly");
     $this->assertTrue($User_arr[0]->first_name == 'Tim' && $User_arr[0]->last_name == "O'Reilly" && $User_arr[0]->user_name == 'tim_oreilly');
     $FoundUsers = $Users->findBy("first_name OR first_name:begins", 'Tim', 'Al', array('order' => 'last_name ASC'));
     $this->assertTrue($FoundUsers[0]->first_name == 'Tim');
     $this->assertTrue($FoundUsers[1]->first_name == 'Alicia');
     $this->assertErrorPattern('/Argument list did not match expected set/', $Users->findBy("username", 'tim_oreilly'));
     $this->assertErrorPattern('/Argument list did not match expected set/', $Users->findBy("user_name AND password", 'tim_oreilly'));
     //$Users->findBy("user_name AND password",'tim_oreilly','1234');
     $AkTestFields = new AkTestField();
     $this->assertTrue($AkTestField = $AkTestFields->findBy('numeric_field:< AND boolean_field', 4, 'yes'));
     $this->assertEqual($AkTestField[0]->varchar_field, '2 string');
     $this->assertEqual(count($AkTestField), 1);
     $this->assertTrue($AkTestField = $AkTestFields->findBy('varchar_field:begins', 2));
     $this->assertEqual($AkTestField[0]->varchar_field, '2 string');
     $this->assertEqual(count($AkTestField), 1);
     $this->assertTrue($AkTestField = $AkTestFields->findBy('(varchar_field:begins OR int8_field OR timestamp_field:<) AND tinyint_field:>=', 2, 3, '2005/05/04 23:00:00', 2));
     $this->assertEqual($AkTestField[0]->varchar_field, '2 string');
     $this->assertEqual($AkTestField[1]->varchar_field, '3 string');
     $this->assertEqual($AkTestField[2]->varchar_field, '4 string');
     $this->assertEqual(count($AkTestField), 3);
     $this->assertTrue($AkTestField = $AkTestFields->findBy('(varchar_field:begins OR int8_field OR timestamp_field:<) AND tinyint_field:>=', 2, 3, '2005/05/04 23:00:00', 2, array('order' => 'numeric_field DESC')));
     $this->assertEqual($AkTestField[0]->varchar_field, '4 string');
     $this->assertEqual($AkTestField[1]->varchar_field, '3 string');
     $this->assertEqual($AkTestField[2]->varchar_field, '2 string');
     $this->assertEqual(count($AkTestField), 3);
 }
예제 #2
0
 public function Test_of_findBy()
 {
     $Users = new AkTestUser();
     $User = $Users->findBy('first', "first_name AND last_name", 'Tim', "O'Reilly");
     $this->assertTrue($User->first_name == 'Tim' && $User->last_name == "O'Reilly" && $User->user_name == 'tim_oreilly');
     $User_arr = $Users->findBy("first_name AND last_name", 'Tim', "O'Reilly");
     $this->assertTrue($User_arr[0]->first_name == 'Tim' && $User_arr[0]->last_name == "O'Reilly" && $User_arr[0]->user_name == 'tim_oreilly');
     $User_arr = $Users->findBy('all', "first_name AND last_name", 'Tim', "O'Reilly");
     $this->assertTrue($User_arr[0]->first_name == 'Tim' && $User_arr[0]->last_name == "O'Reilly" && $User_arr[0]->user_name == 'tim_oreilly');
     $FoundUsers = $Users->findBy("first_name OR first_name:begins", 'Tim', 'Al', array('order' => 'last_name ASC'));
     $this->assertTrue($FoundUsers[0]->first_name == 'Tim');
     $this->assertTrue($FoundUsers[1]->first_name == 'Alicia');
     // $this->expectError(new PatternExpectation('/Argument list did not match expected set/'));
     try {
         $Users->findBy("username", 'tim_oreilly');
         $this->fail();
     } catch (InvalidArgumentException $e) {
         $this->pass();
     }
     // $this->expectError(new PatternExpectation('/Argument list did not match expected set/'));
     try {
         $Users->findBy("user_name AND password", 'tim_oreilly');
         $this->fail();
     } catch (InvalidArgumentException $e) {
         $this->pass();
     }
     //$Users->findBy("user_name AND password",'tim_oreilly','1234');
     $AkTestField = new AkTestField();
     foreach ($AkTestField->find() as $Field) {
         $Field->destroy();
     }
     //Now we add some more records for next tests
     foreach (range(2, 10) as $i) {
         $details = array('varchar_field' => "{$i} string", 'text_field' => "{$i} text", 'date_field' => "2005/05/{$i}", 'datetime_field' => "2005/05/{$i}", 'tinyint_field' => $i, 'integer_field' => $i, 'smallint_field' => $i, 'bigint_field' => $i, 'double_field' => "{$i}.{$i}", 'numeric_field' => $i, 'timestamp_field' => "2005/05/{$i} {$i}:{$i}:{$i}", 'boolean_field' => !($i % 2), 'int2_field' => "{$i}", 'int4_field' => $i, 'int8_field' => $i, 'foat_field' => "{$i}.{$i}", 'varchar4000_field' => "{$i} text", 'clob_field' => "{$i} text", 'nvarchar2000_field' => "{$i} text", 'nvarchar_field' => "{$i}", 'decimal3_field' => $i, 'decimal5_field' => $i, 'decimal10_field' => "{$i}", 'decimal20_field' => $i, 'decimal_field' => $i);
         $AkTestField = new AkTestField($details);
         $this->assertTrue($AkTestField->save());
     }
     $AkTestFields = new AkTestField();
     $this->assertTrue($AkTestField = $AkTestFields->findBy('numeric_field:< AND boolean_field', 4, 'yes'));
     $this->assertEqual($AkTestField[0]->varchar_field, '2 string');
     $this->assertEqual(count($AkTestField), 1);
     $this->assertTrue($AkTestField = $AkTestFields->findBy('varchar_field:begins', 2));
     $this->assertEqual($AkTestField[0]->varchar_field, '2 string');
     $this->assertEqual(count($AkTestField), 1);
     $this->assertTrue($AkTestField = $AkTestFields->findBy('(varchar_field:begins OR int8_field OR timestamp_field:<) AND tinyint_field:>=', 2, 3, '2005/05/04 23:00:00', 2));
     $this->assertEqual($AkTestField[0]->varchar_field, '2 string');
     $this->assertEqual($AkTestField[1]->varchar_field, '3 string');
     $this->assertEqual($AkTestField[2]->varchar_field, '4 string');
     $this->assertEqual(count($AkTestField), 3);
     $this->assertTrue($AkTestField = $AkTestFields->findBy('(varchar_field:begins OR int8_field OR timestamp_field:<) AND tinyint_field:>=', 2, 3, '2005/05/04 23:00:00', 2, array('order' => 'numeric_field DESC')));
     $this->assertEqual($AkTestField[0]->varchar_field, '4 string');
     $this->assertEqual($AkTestField[1]->varchar_field, '3 string');
     $this->assertEqual($AkTestField[2]->varchar_field, '2 string');
     $this->assertEqual(count($AkTestField), 3);
 }