FUEL CMS User Guide : Version 1.5.2


Tester Module Documentation

This Tester documentation is for version 1.0.

Overview

The Tester module allows you to easily create tests and run them in the FUEL admin. To create a test, add a test folder within your applications folder. Tester will read that folder to create it's list of tests you are able to run. It will even scan other modules for test directories to include in it's list of tests to run. You can also run your tests via the command line in a terminal prompt:

php index.php tester/run fuel Fuel_cache_test.php

If you are on a Mac and having trouble where the script is outputting nothing, you may need to make sure you are calling the right php binary. For exmaple, you may need to use something like /Applications/MAMP/bin/php/php5.3.6/bin/php. Here is a thread that talks about it more: http://codeigniter.com/forums/viewthread/130383/ Hopefully it saves you some time too!

Some other important features to point out:

Tester Configuration

The following configuration parameters can be found in the modules/tester/config/tester.php configuration file. It is recommended that you copy the config file and place it in your fuel/application/config directory which will override the defaults and make it easier for future updates.

Property Default Value Description
dsn_group
'test'
dsn for database connection. If not supplied, it will assume a test group name is created in the database.php config set this to 'test' if you want load_page method to load pages from the test database to test
db_name
'fuel_test'
the name of the test database... this will be used regardless of what is set in your DSN value
session_cookiejar_file
APPPATH.'cache/cookiefile.txt'
the cookie jar file path used for CURL sessions more info http:www.php.net/manual/en/function.curl-setopt.php
valid_testing_server_names
array('localhost', '192\.168\.:any')
servers allowed to run tests

You must use a database user that has the ability to create databases since a separate database is created for testing.

Example

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class My_site_test extends Tester_base {
	
	public function __construct()
	{
		parent::__construct();
	}

	public function setup()
	{
		$this->load_sql('test_generic_schema.sql');

		// load a basic MY_Model to test
		require_once('test_custom_records_model.php');
	}
	
	public function test_find_by_key()
	{
		$test_custom_records_model = new Test_custom_records_model();

		// test find_by_key
		$record = $test_custom_records_model->find_by_key(1);
		$test = $record->full_name;
		$expected = 'Darth Vader';
		$this->run($test, $expected, 'find_by_key custom record object property test');
	
		// test get_full_name() method version
		$test = $record->get_full_name();
		$this->run($test, $expected, 'find_one custom record object method test');
	}
	
	public function test_goto_page()
	{
		//http://code.google.com/p/phpquery/wiki/Manual
		$post['test']= 'test';
		$home = $this->load_page('home', $post);

		$test = pq("#content")->size();
		$expected = 1;
		$this->run($test, $expected, 'Test for content node');

		$test = pq("#logo")->size();
		$expected = 1;
		$this->run($test, $expected, 'Test for logo node');
	}
	

}


Libraries