Esempio n. 1
0
 public function test_validation()
 {
     MemoryStore::flush();
     UserLogin::delete_all();
     User::delete_all();
     $user = new User();
     FuzzyTest::assert_false($user->validate(), "User write should fail because required properties were not set");
     FuzzyTest::assert_true(key_exists("email", $user->validation_errors), "Email validation error not set");
     FuzzyTest::assert_true(key_exists("password", $user->validation_errors), "Password validation error not set");
     FuzzyTest::assert_true(key_exists("accepted_terms_and_conditions", $user->validation_errors), "Boolean validation error not set");
     FuzzyTest::assert_true(key_exists("registration_date", $user->validation_errors), "Required validation error not set");
     $user->accepted_terms_and_conditions = true;
     $user->validate();
     FuzzyTest::assert_false(key_exists("accepted_terms_and_conditions", $user->validation_errors), "Boolean validation error erroneously set");
     $user->email = "*****@*****.**";
     $user->validate();
     FuzzyTest::assert_false(key_exists("email", $user->validation_errors), "Email validation error erroneously set");
     $user->password = "******";
     $user->validate();
     FuzzyTest::assert_false(key_exists("password", $user->validation_errors), "Password validation error erroneously set");
     $user->registration_date = new Date();
     $user->validate();
     FuzzyTest::assert_false(key_exists("registration_date", $user->validation_errors), "Required validation error erroneously set");
     $user->first_name = "Ben";
     $user->last_name = "Copsey";
     $user->validate();
     FuzzyTest::assert_false(key_exists("first_name", $user->validation_errors), "Length validation error erroneously set");
     FuzzyTest::assert_false(key_exists("last_name", $user->validation_errors), "Length validation error erroneously set");
     FuzzyTest::assert_true($user->validate(), "Validate should succeed because required properties were set");
 }
Esempio n. 2
0
 public function test_simple_write()
 {
     MemoryStore::flush();
     UserLogin::delete_all();
     User::delete_all();
     $user = new User();
     $user->email = "*****@*****.**";
     $user->password = "******";
     $user->accepted_terms_and_conditions = true;
     $user->registration_date = new Date("2008-12-12");
     $user->first_name = "Ben";
     $user->last_name = "Copsey";
     FuzzyTest::assert_true($user->write_new(), "Write should succeed because required properties were set");
     $user = new User();
     $user->email = "*****@*****.**";
     $user->password = "******";
     $user->accepted_terms_and_conditions = true;
     $user->registration_date = new Date();
     $user->first_name = "Ben";
     $user->last_name = "Copsey";
     FuzzyTest::assert_false($user->write_new(), "Write should fail because we have a duplicate for a unique property");
     $user = new User();
     $user->email = "*****@*****.**";
     $user->password = "******";
     $user->accepted_terms_and_conditions = true;
     $user->registration_date = new Date();
     $user->first_name = "Ben";
     $user->last_name = "Copsey";
     FuzzyTest::assert_true($user->save(), "Save should succeed as a write_new");
 }
Esempio n. 3
0
 public function __construct()
 {
     MemoryStore::flush();
     UserLogin::delete_all();
     User::delete_all();
     $user = new User();
     $user->email = "*****@*****.**";
     $user->password = "******";
     $user->accepted_terms_and_conditions = true;
     $user->registration_date = new Date();
     $user->first_name = "Ben";
     $user->last_name = "Copsey";
     $user->save();
     $user = new User();
     $user->email = "*****@*****.**";
     $user->password = "******";
     $user->accepted_terms_and_conditions = true;
     $user->registration_date = new Date();
     $user->first_name = "Ben";
     $user->last_name = "Copsey";
     $user->save();
     $user = new User();
     $user->email = "*****@*****.**";
     $user->password = "******";
     $user->accepted_terms_and_conditions = true;
     $user->registration_date = new Date();
     $user->first_name = "Benjamus";
     $user->last_name = "Copso";
     $user->save();
     Page::delete_all();
     $page = new Page();
     $page->title = "test page";
     $page->url = "test-page";
     $page->body = "thing";
     $page->save();
     $page = new Page();
     $page->title = "test page 2";
     $page->url = "test-page-2";
     $page->body = "thing 2";
     $page->save();
     $page = new Page();
     $page->title = "test page 3";
     $page->url = "test-page-3";
     $page->body = "thing 3";
     $page->save();
 }
Esempio n. 4
0
 public function test_has_many()
 {
     UserLogin::delete_all();
     User::delete_all();
     $user = new User();
     $user->email = "*****@*****.**";
     $user->password = "******";
     $user->accepted_terms_and_conditions = true;
     $user->registration_date = new Date();
     $user->first_name = "Ben";
     $user->last_name = "Copsey";
     $user->save();
     $user = new User();
     $user->email = "*****@*****.**";
     $user->password = "******";
     $user->accepted_terms_and_conditions = true;
     $user->registration_date = new Date();
     $user->first_name = "Ben";
     $user->last_name = "Copsey";
     $user->save();
     $user = User::find_by_email('*****@*****.**');
     $user_login = new UserLogin();
     $user_login->user_id = $user->id;
     $user_login->date = new Date();
     $user_login->ip_address = "127.0.0.1";
     $user_login->save();
     $matches = $user->logins();
     FuzzyTest::assert_equal(count($matches), 1, "Should find one login here");
     $user_login = new UserLogin();
     $user_login->user_id = $user->id;
     $user_login->date = new Date();
     $user_login->ip_address = "127.0.0.1";
     $user_login->save();
     $matches = UserLogin::find_all_by_user($user);
     FuzzyTest::assert_equal(count($matches), 2, "Should find two logins here");
     $matches = UserLogin::find_all_where("user_id = " . DB::escape($user->id));
     FuzzyTest::assert_equal(count($matches), 2, "Should find two logins here");
     $matches = UserLogin::find_all_where("user_id = " . DB::escape($user->id), 1);
     FuzzyTest::assert_equal(count($matches), 1, "Should find one login here");
     $login = $matches[0];
     $matches = UserLogin::find_all_where("user_id = " . DB::escape($user->id), 2);
     $login2 = $matches[0];
     FuzzyTest::assert_equal($login->id, $login2->id, "Two logins should be equal");
     $matches = UserLogin::find_all_where("user_id = " . DB::escape($user->id), 0, 2);
     $login2 = $matches[0];
     FuzzyTest::assert_equal($login->id, $login2->id, "Two logins should be equal");
     $matches = UserLogin::find_all_where("user_id = " . DB::escape($user->id), 1, 2);
     $login2 = $matches[0];
     FuzzyTest::assert_not_equal($login->id, $login2->id, "Two logins should be equal");
     $matches = $user->logins();
     FuzzyTest::assert_equal(count($matches), 2, "Should find two logins here");
     $login = UserLogin::find_by_user_id($user->id);
     FuzzyTest::assert_equal($login->user_id, $user->id, "Found wrong login");
     $login = UserLogin::find_by_user($user);
     FuzzyTest::assert_equal($login->user_id, $user->id, "Found wrong login");
     $u = User::find_by_login($user_login);
     FuzzyTest::assert_equal($u->id, $user->id, "Found wrong user");
     $user_login = new UserLogin();
     $user_login->user = $user;
     $user_login->date = new Date();
     $user_login->ip_address = "127.0.0.1";
     $user_login->save();
     $matches = $user->logins();
     FuzzyTest::assert_equal(count($matches), 3, "Should find three logins here");
     $user->delete();
     $matches = UserLogin::find_by_user_id($user->id);
     FuzzyTest::assert_equal(count($matches), 0, "Should find zero logins here");
     $matches = UserLogin::find_by_user($user);
     FuzzyTest::assert_equal(count($matches), 0, "Should find zero logins here");
     UserLogin::delete_all();
     $user_login1 = new UserLogin();
     $user_login1->date = new Date();
     $user_login1->ip_address = "127.0.0.1";
     $user_login2 = new UserLogin();
     $user_login2->date = new Date();
     $user_login2->ip_address = "127.0.0.1";
     //$user->save();
     $user->logins = array($user_login1, $user_login2);
     $user->save();
     $matches = $user->logins;
     FuzzyTest::assert_equal(count($matches), 2, "Should find two logins here");
     $user2 = new User();
     $user2 = User::find_by_email('*****@*****.**');
     $user_login1->user = $user2;
     $user_login1->save();
     $matches = $user->logins;
     FuzzyTest::assert_equal(count($matches), 1, "Should find one login here");
     $matches = $user2->logins();
     FuzzyTest::assert_equal(count($matches), 1, "Should find one login here");
 }