| Server IP : 210.245.233.93 / Your IP : 216.73.216.226 Web Server : Apache/2.2.15 (CentOS) System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : apache ( 48) PHP Version : 5.3.3 Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/(Del)gepgroup.hk/php-activerecord/test/ |
Upload File : |
<?php
include 'helpers/config.php';
class BookPresence extends ActiveRecord\Model
{
static $table_name = 'books';
static $validates_presence_of = array(
array('name')
);
}
class AuthorPresence extends ActiveRecord\Model
{
static $table_name = 'authors';
static $validates_presence_of = array(
array('some_date')
);
};
class ValidatesPresenceOfTest extends DatabaseTest
{
public function test_presence()
{
$book = new BookPresence(array('name' => 'blah'));
$this->assert_false($book->is_invalid());
}
public function test_presence_on_date_field_is_valid()
{
$author = new AuthorPresence(array('some_date' => '2010-01-01'));
$this->assert_true($author->is_valid());
}
public function test_presence_on_date_field_is_not_valid()
{
$author = new AuthorPresence();
$this->assert_false($author->is_valid());
}
public function test_invalid_null()
{
$book = new BookPresence(array('name' => null));
$this->assert_true($book->is_invalid());
}
public function test_invalid_blank()
{
$book = new BookPresence(array('name' => ''));
$this->assert_true($book->is_invalid());
}
public function test_valid_white_space()
{
$book = new BookPresence(array('name' => ' '));
$this->assert_false($book->is_invalid());
}
public function test_custom_message()
{
BookPresence::$validates_presence_of[0]['message'] = 'is using a custom message.';
$book = new BookPresence(array('name' => null));
$book->is_valid();
$this->assert_equals('is using a custom message.', $book->errors->on('name'));
}
public function test_valid_zero()
{
$book = new BookPresence(array('name' => 0));
$this->assert_true($book->is_valid());
}
};
?>