Example #1
0
 public function test_basic_find()
 {
     $count = User::count();
     FuzzyTest::assert_equal($count, 3, "Should find three users here");
     $matches = User::find_all();
     FuzzyTest::assert_equal(count($matches), 3, "Should find three users here");
     $count = User::count(array('email' => '*****@*****.**'));
     FuzzyTest::assert_equal($count, 1, "Should find one user here");
     $matches = User::find(array('email' => '*****@*****.**'));
     FuzzyTest::assert_equal(count($matches), 1, "Should find one user here");
     $u = $matches[0];
     FuzzyTest::assert_equal($u->email, "*****@*****.**", "Found wrong user");
     $count = User::count(array('first_name' => 'Ben'));
     FuzzyTest::assert_equal($count, 2, "Should find two users here");
     $matches = User::find(array('first_name' => 'Ben'));
     FuzzyTest::assert_equal(count($matches), 2, "Should find two users here");
     $matches = User::find_all_by_first_name('Ben');
     FuzzyTest::assert_equal(count($matches), 2, "Should find two users here");
     $count = User::count_by_first_name('Ben');
     FuzzyTest::assert_equal($count, 2, "Should find two users here");
     $matches = User::find_all_by_email('*****@*****.**');
     FuzzyTest::assert_equal(count($matches), 1, "Should find one user here");
     $count = User::count_by_email('*****@*****.**');
     FuzzyTest::assert_equal($count, 1, "Should find one user here");
     $u = $matches[0];
     FuzzyTest::assert_equal($u->email, "*****@*****.**", "Found wrong user");
     $u = User::find_by_email('*****@*****.**');
     FuzzyTest::assert_equal($u->email, "*****@*****.**", "Found wrong user");
     $matches = User::find_all_by_email_and_first_name('*****@*****.**', 'Ben');
     FuzzyTest::assert_equal(count($matches), 1, "Should find one user here");
     $count = User::count_by_email_and_first_name('*****@*****.**', 'Ben');
     FuzzyTest::assert_equal($count, 1, "Should find one user here");
     $u = $matches[0];
     FuzzyTest::assert_equal($u->email, "*****@*****.**", "Found wrong user");
     $matches = User::find(array('first_name' => 'Ben', 'limit' => 1));
     FuzzyTest::assert_equal(count($matches), 1, "Should find one user here");
     $matches = User::find(array('first_name' => 'Ben', 'order_by' => 'registration_date'));
     FuzzyTest::assert_equal(count($matches), 2, "Should find two users here");
     $u = $matches[0];
     FuzzyTest::assert_equal($u->email, "*****@*****.**", "Sorted results in the wrong order");
     $matches = User::find(array('first_name' => 'Ben', 'order_by' => 'email', 'sort' => "descending"));
     FuzzyTest::assert_equal(count($matches), 2, "Should find two users here");
     $u = $matches[0];
     FuzzyTest::assert_equal($u->email, "*****@*****.**", "Sorted results in the wrong order");
     $matches = User::find(array('first_name' => 'Ben', 'order_by' => 'email', 'sort' => "ascending"));
     FuzzyTest::assert_equal(count($matches), 2, "Should find two users here");
     $u = $matches[1];
     FuzzyTest::assert_equal($u->email, "*****@*****.**", "Found wrong user");
     $matches = User::find(array('email_not' => '*****@*****.**'));
     FuzzyTest::assert_equal(count($matches), 2, "Should find two users here");
 }