<?php
/**
 * This file contains the PMO_MyController tests.
 *
 * This file is part of the PhpMyObject project,
 * an Object-Relational Mapping (ORM) system.
 * 
 * For questions, help, comments, discussion, etc., please join our
 * forum at {@link http://www.developpez.net/forums/forumdisplay.php?f=770} 
 * or our mailing list at {@link http://groups.google.com/group/pmo-dev}.
 *
 * PhpMyObject is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see {@link http://www.gnu.org/licenses/}.
 *
 * @package			PhpMyObject
 * @subpackage		PMO_Tests
 * @author			Louis Lapointe <laplix@gmail.com>
 * @link				http://pmo.developpez.com/
 * @since			PhpMyObject v0.15
 * @version			$Revision$
 * @copyright		Copyright (C) 2008 Louis Lapointe
 * @license			GPLv3 {@link http://www.gnu.org/licenses/gpl}
 * @filesource
 */ 

/**
 * setup this test case if called individually
 */
if (!defined('PMO_TEST_SUITE')) {
	require_once(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'config.php');
	require_once(SIMPLETEST.DS.'autorun.php');
}


/**
 * requires the PMO_MyController which includes everything needed
 */
require_once(PMO_CORE . DS . 'PMO_MyController.php');

/**
 * requires our basic PMO_MyTest template
 */
require_once(dirname(__FILE__).DS.'PMO_MyTest.php');

/**
 * loads the Html reporter
 */
require_once(PMO_TESTS . DS . 'simpletest' . DS . 'PMO_HTMLReporter.php');

/**
 * tests the PMO_MyController class
 */
class PMO_MyController_Test extends PMO_MyTest
{
	public function __construct() {
		parent::__construct();
		$this->setData();
	}

	function test_simple_query() {
		$controller = new PMO_MyController;

		$map = $controller->query('SELECT * FROM actor LIMIT 5');
		$this->assertTrue(($map instanceof PMO_Map), 'controller returned a PMO_Map');

		// then we make sure we have the right number of rows
		$this->assertEqual($map->count(), 5);

		// and the right data (1, 2, last)
		$result = $map->fetch();
		$this->assertEqual($result['actor']->first_name, 'Nicolas');
		$result = $map->fetch();
		$this->assertEqual($result['actor']->first_name, 'NICK');
		$result = $map->fetch();
		$result = $map->fetch();
		$result = $map->fetch();
		$this->assertEqual($result['actor']->first_name, 'JOHNNY');
	}


	function test_basic_rawquery() {
		$controller = new PMO_MyController;

		$dbms = $controller->rawquery('SELECT * FROM actor LIMIT 5');
		$this->assertTrue(($dbms instanceof PMO_Dbms), 'controller returned a PMO_Dbms object');

		$row = $dbms->fetchArray();
		$this->assertTrue($row['first_name'], 'Nicolas');
		$row = $dbms->fetchArray();
		$this->assertTrue($row['first_name'], 'NICK');
		$row = $dbms->fetchArray();
		$row = $dbms->fetchArray();
		$row = $dbms->fetchArray();
		$this->assertTrue($row['first_name'], 'JOHNNY');
	}
}



// run the tests if called individually
if (!defined('PMO_TEST_SUITE')) {
	$level = '';
	if (isset($_GET['level']))
		$level = $_GET['level'];

	$test = new TestSuite('PMO_MyController Tests');
	$test->add(new PMO_MyController_Test);
	$test->run(new PMO_HTMLReporter($level));
}

