Location: PHPKode > projects > Moc10 PHP Library > tests/Moc10/RecordTest.php
<?php
/**
 * Moc10 Library
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.TXT.
 * It is also available through the world-wide-web at this URL:
 * http://www.moc10phplibrary.com/LICENSE.TXT
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to hide@address.com so we can send you a copy immediately.
 *
 * @category   Moc10
 * @package    Moc10_Record
 * @author     Nick Sagona, III <hide@address.com>
 * @copyright  Copyright (c) 2009-2011 Moc 10 Media, LLC. (http://www.moc10media.com)
 * @license    http://www.moc10phplibrary.com/LICENSE.TXT     New BSD License
 */

require_once dirname(__FILE__) . '/../../library/Moc10/Autoloader.php';
set_include_path(dirname(__FILE__) . '/../../application/' . PATH_SEPARATOR . get_include_path());
Moc10_Autoloader::bootstrap();

class Moc10_RecordTest extends PHPUnit_Framework_TestCase
{

    public function testRecordConstructor()
    {
        $r = new Test_Table_Users(null, 'MySQLi', 'testdb', 'localhost', 'testuser', '12test34');
        $parent = 'Moc10_Record';
        $child = 'Test_Table_Users';
        $this->assertTrue($r instanceof $child);
        $this->assertTrue($r instanceof $parent);
    }

    public function testRecordFindById()
    {
        $r = new Test_Table_Users(null, 'MySQLi', 'testdb', 'localhost', 'testuser', '12test34');
        $r->findById(1);
        $this->assertEquals('hide@address.com', $r->email);
    }

    public function testRecordFindBy()
    {
        $r = new Test_Table_Users(null, 'MySQLi', 'testdb', 'localhost', 'testuser', '12test34');
        $r->findBy('user_id', 2);
        $this->assertEquals('hide@address.com', $r->email);
    }

    public function testRecordFindAll()
    {
        $r = new Test_Table_Users(null, 'MySQLi', 'testdb', 'localhost', 'testuser', '12test34');
        $r->findAll();
        $this->assertEquals(8, count($r->rows));
    }

    public function testRecordSave()
    {
        $r = new Test_Table_Users(array('username' => 'test3', 'email' => 'hide@address.com'), 'MySQLi', 'testdb', 'localhost', 'testuser', '12test34');
        $r->save();

        $r = new Test_Table_Users();
        $r->findBy('username', 'test3');
        $this->assertEquals('hide@address.com', $r->email);
    }

    public function testRecordDelete()
    {
        $r = new Test_Table_Users(null, 'MySQLi', 'testdb', 'localhost', 'testuser', '12test34');
        $r->findBy('username', 'test3');
        $r->delete();
        $this->assertFalse(isset($r->username));
    }

}

?>
Return current item: Moc10 PHP Library