a tiny mvc framework for php using php-activerecord
1<?php
2include 'helpers/config.php';
3
4class BookPresence extends ActiveRecord\Model
5{
6 static $table_name = 'books';
7
8 static $validates_presence_of = array(
9 array('name')
10 );
11}
12
13class AuthorPresence extends ActiveRecord\Model
14{
15 static $table_name = 'authors';
16
17 static $validates_presence_of = array(
18 array('some_date')
19 );
20};
21
22class ValidatesPresenceOfTest extends DatabaseTest
23{
24 public function test_presence()
25 {
26 $book = new BookPresence(array('name' => 'blah'));
27 $this->assert_false($book->is_invalid());
28 }
29
30 public function test_presence_on_date_field_is_valid()
31 {
32 $author = new AuthorPresence(array('some_date' => '2010-01-01'));
33 $this->assert_true($author->is_valid());
34 }
35
36 public function test_presence_on_date_field_is_not_valid()
37 {
38 $author = new AuthorPresence();
39 $this->assert_false($author->is_valid());
40 }
41
42 public function test_invalid_null()
43 {
44 $book = new BookPresence(array('name' => null));
45 $this->assert_true($book->is_invalid());
46 }
47
48 public function test_invalid_blank()
49 {
50 $book = new BookPresence(array('name' => ''));
51 $this->assert_true($book->is_invalid());
52 }
53
54 public function test_valid_white_space()
55 {
56 $book = new BookPresence(array('name' => ' '));
57 $this->assert_false($book->is_invalid());
58 }
59
60 public function test_custom_message()
61 {
62 BookPresence::$validates_presence_of[0]['message'] = 'is using a custom message.';
63
64 $book = new BookPresence(array('name' => null));
65 $book->is_valid();
66 $this->assert_equals('is using a custom message.', $book->errors->on('name'));
67 }
68
69 public function test_valid_zero()
70 {
71 $book = new BookPresence(array('name' => 0));
72 $this->assert_true($book->is_valid());
73 }
74};
75?>