Location: PHPKode > projects > Emailr > tests/IOHelperTest.php
<?

/**
 * This file contains classes to unit test the Emailr IO Helper functions
 *
 * This file provides classes that will unit test the Emailr IO Helper functions
 * @package Emailr
 * @subpackage UnitTests
 * @author Jon Herron
 * @version 0.1.5
 * @since 03.16.2008
 */


require_once "../common/Environment.inc";
require_once "../common/IOHelper.inc";
require_once "PHPUnit/Framework.php";

/**
 * Tests that the Emailr IOHelper.inc is working properly
 *
 * This class will contain logic for unit testing the Emailr IOHelper.inc common 
 * include file, to make sure that it is working properly.
 * @package Emailr
 * @subpackage UnitTests
 * @author Jon Herron
 * @version 0.0.0.1
 * @since 02.24.2008
 */
class IOHelperTest extends PHPUnit_Framework_TestCase
{
	/**
	 * Private data member to hold a reference to the DirectoryBrowser class
	 * @access private
	 * @var _directoryBrowser
	 * @author Jon Herron
	 * @version 0.0.0.1
	 * @since 02.24.2008
	 */
	private $_directoryBrowser;

	/**
	 * Private data member to hold an incrementing value
	 * @access private
	 * @var _i
	 * @author Jon Herron
	 * @version 0.0.0.1
	 * @since 02.24.2008
	 */
	private $_i;

	/**
	 * Private data member to store the root folder used during this test fixture
	 * @access private
	 * @var _rootFolder
	 * @author Jon Herron
	 * @version 0.0.0.1
	 * @since 02.24.2008
	 */
	private $_rootFolder;

	/**
	 * Public function to set up the Emailr IOHelper test fixture
	 *
	 * This public method will prep the test fixture to allow it to properly make sure 
	 * the Emailr IOHelper.inc include file is functioning properly.
	 * @access public
	 * @author Jon Herron
	 * @version 0.0.0.1
	 * @since 02.28.2008
	 */
	public function setUp()
	{
		// create a new DirectoryBrowser, one of the classes available via IOHelper
		$this->_directoryBrowser = new DirectoryBrowser();

		// set _i to 0
		$this->_i = 0;

		// set the root folder for use during this text fixture
		$this->_rootFolder = realpath(dirname(__file__) . "/../");
	}

	/**
	 * Public function to make sure the DirectoryBrowser constructor is working
	 *
	 * This public method will make sure that the DirectoryBrowser class has a working constructor, 
	 * and that the instance we are about to use as the basis of our tests is a valid new object.
	 * @access public
	 * @author Jon Herron
	 * @version 0.0.0.1
	 * @since 02.28.2008
	 */
	public function testCreateDirectoryBrowser()
	{
		$this->assertEquals($this->_directoryBrowser, 
			new DirectoryBrowser(), 
			"DirectoryBrowser Constructor not functioning properly");
	}

	/**
	 * Public function to make sure the DirectoryBrowser's ParseDirectory method works
	 *
	 * This public method will make sure that the DirectoryBrowser's ParseDirectory method works 
	 * properly, using the sampleemails folder in the tests folder as the target of this unit test.
	 * @access public
	 * @author Jon Herron
	 * @version 0.0.0.1
	 * @since 02.28.2008
	 */
	public function testParseDirectory()
	{
		// parse the sampleemails folder found in the test folder
		$this->_directoryBrowser->ParseDirectory("$this->_rootFolder/tests/sampleemails");

		// make sure we found 10 files
		$this->assertEquals($this->_directoryBrowser->GetFileCount(), 
			10, 
			"Incorrect number of files found in $this->_rootFolder/tests/sampleemails");

		// clear the directory browser object for the next test
		$this->_directoryBrowser->Clear();
	}

	/**
	 * Public function to make sure the DirectoryBrowser's ParseDirectory method works
	 *
	 * This public method will make sure that the DirectoryBrowser's ParseDirectory method works 
	 * properly, using the sampleemails folder in the tests folder as the target of this unit test.  
	 * This case also specifies the optional perform file check option to false.  Default is true.
	 * @access public
	 * @author Jon Herron
	 * @version 0.0.0.1
	 * @since 02.28.2008
	 */
	public function testParseDirectorySkipFileCheck()
	{
		// parse the sampleemails folder found in the test folder
		$this->_directoryBrowser->ParseDirectory("$this->_rootFolder/tests/sampleemails", false);

		// make sure we found 13 files
		$this->assertEquals($this->_directoryBrowser->GetFileCount(), 
			13, 
			"Incorrect number of files found in $this->_rootFolder/tests/sampleemails");

		// clear the directory browser object for the next test
		$this->_directoryBrowser->Clear();
	}

	/**
	 * Public function to make sure the DirectoryBrowser's GetFiles method works
	 *
	 * This public method will make sure that the DirectoryBrowser's GetFiles method works 
	 * properly, using the sampleemails folder in the tests folder as the target of this unit test.
	 * @access public
	 * @author Jon Herron
	 * @version 0.0.0.1
	 * @since 02.28.2008
	 */
	public function testGetFiles()
	{
		// parse the sampleemails folder found in the test folder
		$this->_directoryBrowser->ParseDirectory("$this->_rootFolder/tests/sampleemails");

		// pull an array of the files in the directory
		$files = $this->_directoryBrowser->GetFiles();

		// make sure count($files) and get file count are the same number
		$this->assertEquals($this->_directoryBrowser->GetFileCount(), 
			count($files), 
			"Incorrect number of files found in $this->_rootFolder/tests/sampleemails");

		// clear the directory browser object for the next test
		$this->_directoryBrowser->Clear();
	}
}

?>
Return current item: Emailr