Example #1
0
 public function test_save()
 {
     $model = new Example();
     $backend = new MockBackend();
     $model->set_backend($backend);
     $model->set_attributes($this->example_user);
     $result = $model->save();
     $this->assertEquals($result->username, "test1");
     $this->assertEquals($result->password, "password");
     $this->assertEquals($result->email, "*****@*****.**");
 }
Example #2
0
 public function test_validate_length()
 {
     $this->model->define("username", "CharField", array("maxlength" => "3"));
     $res = $this->model->set_attributes($this->get_fixture("user1"));
     $this->assertFalse($res->validate());
     $res = new Example();
     $res->define("username", "CharField", array("maxlength" => "6"));
     $res->set_attributes($this->get_fixture("user1"));
     $this->assertTrue($res->validate());
     $res = new Example();
     $res->define("username", "CharField", array("minlength" => "6"));
     $res->set_attributes($this->get_fixture("user1"));
     $this->assertFalse($res->validate());
 }
Example #3
0
 /**
  * 
  *
  **/
 public function test_observers()
 {
     $model = new Example();
     $backend = new MockBackend();
     $model->set_backend($backend);
     $model->set_attributes($this->example_user);
     $this->assertEquals($model->fieldset()->key, 'example');
     $model->mock = "now_set";
     $this->assertContains("before_set", $model->fieldset()->mock->observer_calls);
     $this->assertContains("after_set", $model->fieldset()->mock->observer_calls);
     $this->assertEquals($model->mock, 'intercepted');
     $this->assertContains("before_get", $model->fieldset()->mock->observer_calls);
     $this->assertContains("after_get", $model->fieldset()->mock->observer_calls);
     $model->save();
     $this->assertContains("before_save", $model->fieldset()->mock->observer_calls);
     $this->assertContains("after_save", $model->fieldset()->mock->observer_calls);
 }