I’m just writing some selenium tests for a website. Some actions create entrys in the database which I would like to retrieve, to test if everything works out like I want it.
The functions I need to read the values from database already exist - so I dont have to write them just for the tests ;-). - so don’t worry about that.
Lol, ok … seems that it already uses the test database for retrieving the datasets from the database …
The problem is, that it creates the database entry in the "dev" database instead of the "test" database (the user interaction leads to the "actionCreate", which points to the "dev" database instead of the "test" database)
–> how can I make it write to the "test" database should be the correct question.
Thanks for your reply, but that’s what I actualy do right now. Like i sayed, when I call a function in a model from a selenium test file it uses the test database. But when I call a website (with index-test.php instead of index.php) it seems to always use the “dev” database.
Weird …
My test.php looks as follows:
return CMap::mergeArray(
require(dirname(__FILE__) . '/main.php'),
array(
'components' => array(
'fixture' => array(
'class' => 'system.test.CDbFixtureManager',
),
/* uncomment the following to provide test database connection
'db'=>array(
'connectionString'=>'DSN for test database',
),
*/
'db' => array(
'connectionString' => 'mysql:host=127.0.0.1;dbname=startregie_test',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
/*'tablePrefix' => 'tbl_',*/
),
),
)
);
And my index-test.php:
// change the following paths if necessary
$yii=dirname(__FILE__).'/../Yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/test.php';
// remove the following line when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
require_once($yii);
Yii::createWebApplication($config)->run();
Ok, I changed the database in the main.php config file to the “test” database and now it works … so it seems, that somewhere it’s using the main.php config instead of the test.php … wtf…
Hmm … well, that’s a solution, but a bit hacky … when I have to change something in the main.php … always got a second place to change that stuff as well :-(.
Is there a way to figure out, why the override doesn’t work when the database inserts come through the views?
… because - as sayed before - a call to a model function from the selenium test files works. O_o
First of all I think you should use the createUrl() method (of course from PHP-land) for generating the url, this way it will reflect the current urlManager config.
If this doesn’t help, next I would try to set showScriptName to true in the test config (should be possible to overwrite).
Finally the use of “createUrl()” didn’t solve anything, but setting showScriptName to true did the work. Maybe someone could explain to me, why this did the job? I’d like to understand, why it didn’t work in first place?
… and I just can repeat myself: I f***ing LOVE Yii! Great job guys!