<?php
/**
 * This file contains the PMO_MyTest basic class
 *
 * 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
 */ 

/**
 * we need this class to provide some general setUp and tearDown
 * plus some helper methods to all test cases.
 *
 * @package			PhpMyObject
 * @subpackage		PMO_Tests
 */
class PMO_MyTest extends UnitTestCase
{

	public function __construct($authdb = null) {
		parent::UnitTestCase();
		if (!empty($authdb)) {
			$this->authdb = $authdb;
			$this->setConfig();
		}
	}

	function setUp() {
		include (dirname(__FILE__).'/your_config.php');
		PMO_MyDbms::setDb(NULL);
		PMO_MyDbms::killInstance();
		$this->setData();
  	}

	function tearDown() { }

	/**
	 * destroys and recreates the test tables.
	 */
	protected function resetTestTables() {
		$ctrl = new PMO_MyController;
		foreach ($this->drops as $drop) {
			$ctrl->rawquery($drop);
		}
		foreach ($this->creates as $create) {
			$ctrl->rawquery($create);
		}
		foreach($this->inserts as $insert) {
			$ctrl->rawquery($insert);
		}
	}

	/**
	 * loads the SQL to drop and recreate the test tables.
	 */
	protected function setData() {
		include(PMO_TESTS.DS.'__db'.DS.'pmo_test_data.php');

		$this->creates = $creates;
		$this->drops 	= $drops;
		$this->deletes = $deletes;
		$this->inserts = $inserts;
	}

	/**
	 * sets a database for inserts/updates/deletes.
	 */
	protected function setConfig() {
		$config = PMO_MyConfig::factory();
		$config->set('PMO_MyDbms.DRIVER',$this->authdb['driver']);
		$config->set('PMO_MyDbms.PDODRIVER', $this->authdb['pdodriver']);
		$config->set('PMO_MyDbms.HOST', $this->authdb['host']);
		$config->set('PMO_MyDbms.USER', $this->authdb['user']);
		$config->set('PMO_MyDbms.PASS', $this->authdb['pass']);
		$config->set('PMO_MyDbms.BASE', $this->authdb['base']);
		$config->set('PMO_MyDbms.DSN',  $this->authdb['dsn']);
	}
}
