Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add basic unit testing framework; update API docs

  • Loading branch information...
commit be958605d36d62b77fcb61ea63c5a3265c6d6a11 1 parent cb73528
Shaun McCormick authored
View
2  .gitignore
@@ -1,3 +1,5 @@
_build/build.config.php
config.core.php
.idea
+core/components/formit/test/properties.inc.php
+core/components/formit/test/config.inc.php
View
2  _build/docs/build/_firequest.class.html
@@ -93,7 +93,7 @@
</dl>
<dl></dl>
<h3>Description</h3>
-<p class="short-description">Handles all POST requests for FormIt and abstracts postHook and validation processing.</p>
+<p class="short-description">Handles all pre and POST requests for FormIt and abstracts hooks and validation processing.</p>
<div class="long-description">
</div>
<h3>Properties</h3>
View
4 _build/docs/build/nav.html
@@ -21,7 +21,7 @@
<li class="closed"><span class="class"><a href="_fidictionary.class.html#%5CfiDictionary" target="content">fiDictionary<br><small>Abstracts storage of values of posted fields and fields set by hooks.</small></a></span></li>
<li class="closed"><span class="class"><a href="_fihooks.class.html#%5CfiHooks" target="content">fiHooks<br><small>Base Hooks handling class. Hooks can be used to run scripts prior to loading the form, or after a form has been
submitted.</small></a></span></li>
-<li class="closed"><span class="class"><a href="_firequest.class.html#%5CfiRequest" target="content">fiRequest<br><small>Handles all POST requests for FormIt and abstracts postHook and validation processing.</small></a></span></li>
+<li class="closed"><span class="class"><a href="_firequest.class.html#%5CfiRequest" target="content">fiRequest<br><small>Handles all pre and POST requests for FormIt and abstracts hooks and validation processing.</small></a></span></li>
<li class="closed"><span class="class"><a href="_fivalidator.class.html#%5CfiValidator" target="content">fiValidator<br><small>Handles custom validation on fields. Allows for specific, defined validators by FormIt, or custom Validators
that are MODX Snippets.</small></a></span></li>
</ul>
@@ -36,7 +36,7 @@
submitted.</small></a></span></li></ul>
</li>
<li class="closed">
-<span class="file"><a href="_firequest.class.html" target="content">firequest.class.php</a></span><ul id="files_997ff2e9e04073d49d1da286fe601aa1" class="filetree"><li><span class="class"><a href="_firequest.class.html#%5CfiRequest" target="content">fiRequest<br><small>Handles all POST requests for FormIt and abstracts postHook and validation processing.</small></a></span></li></ul>
+<span class="file"><a href="_firequest.class.html" target="content">firequest.class.php</a></span><ul id="files_a6dfa6f70f4e083f27319f1ef6b85f9d" class="filetree"><li><span class="class"><a href="_firequest.class.html#%5CfiRequest" target="content">fiRequest<br><small>Handles all pre and POST requests for FormIt and abstracts hooks and validation processing.</small></a></span></li></ul>
</li>
<li class="closed">
<span class="file"><a href="_fivalidator.class.html" target="content">fivalidator.class.php</a></span><ul id="files_a88c62e4cde9fe4e7d6ac8e9ec40e7f3" class="filetree"><li><span class="class"><a href="_fivalidator.class.html#%5CfiValidator" target="content">fiValidator<br><small>Handles custom validation on fields. Allows for specific, defined validators by FormIt, or custom Validators
View
4 _build/docs/build/structure.xml
@@ -770,7 +770,7 @@ field or the emailsender setting.
</method>
</class>
</file>
- <file path="firequest.class.php" hash="997ff2e9e04073d49d1da286fe601aa1">
+ <file path="firequest.class.php" hash="a6dfa6f70f4e083f27319f1ef6b85f9d">
<docblock>
<description>FormIt</description>
<long-description>&lt;p&gt;Copyright 2009-2011 by Shaun McCormick &lt;a href="&amp;#x6d;&amp;#x61;&amp;#x69;&amp;#x6c;&amp;#116;&amp;#111;&amp;#58;&amp;#115;&amp;#104;&amp;#x61;&amp;#x75;&amp;#x6e;&amp;#x40;&amp;#x6d;&amp;#111;&amp;#100;&amp;#120;&amp;#46;&amp;#99;&amp;#x6f;&amp;#x6d;"&gt;&amp;#115;&amp;#104;&amp;#x61;&amp;#x75;&amp;#x6e;&amp;#x40;&amp;#x6d;&amp;#111;&amp;#100;&amp;#120;&amp;#46;&amp;#99;&amp;#x6f;&amp;#x6d;&lt;/a&gt;&lt;/p&gt;
@@ -795,7 +795,7 @@ Suite 330, Boston, MA 02111-1307 USA&lt;/p&gt;
<extends/>
<full_name>\fiRequest</full_name>
<docblock>
- <description>Handles all POST requests for FormIt and abstracts postHook and validation processing.</description>
+ <description>Handles all pre and POST requests for FormIt and abstracts hooks and validation processing.</description>
<long-description>
</long-description>
<tag name="package" description="formit" line="22"/>
View
9 core/components/formit/model/formit/formit.class.php
@@ -81,6 +81,7 @@ function __construct(modX &$modx,array $config = array()) {
'snippetsPath' => $corePath.'elements/snippets/',
'controllersPath' => $corePath.'controllers/',
'includesPath' => $corePath.'includes/',
+ 'testsPath' => $corePath.'test/',
'assetsPath' => $assetsPath,
'assetsUrl' => $assetsUrl,
@@ -120,6 +121,14 @@ public function initialize($context = 'web') {
}
/**
+ * Sees if the FormIt class has been initialized already
+ * @return boolean
+ */
+ public function isInitialized() {
+ return $this->_initialized;
+ }
+
+ /**
* Load the fiRequest class
* @return fiRequest
*/
View
34 core/components/formit/test/FiTestCase.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * @package formit-test
+ */
+/**
+ * Extends the basic PHPUnit TestCase class to provide FormIt specific methods
+ *
+ * @package formit-test
+ */
+class FiTestCase extends PHPUnit_Framework_TestCase {
+ /**
+ * @var modX
+ */
+ protected $modx = null;
+ protected $formit = null;
+
+ /**
+ * Ensure all tests have a reference to the MODX object
+ */
+ public function setUp() {
+ $this->modx =& FiTestHarness::_getConnection();
+ $fiCorePath = $this->modx->getOption('formit.core_path',null,$this->modx->getOption('core_path',null,MODX_CORE_PATH).'components/formit/');
+ require_once $fiCorePath.'model/formit/formit.class.php';
+ $this->formit = new FormIt($this->modx);
+ }
+
+ /**
+ * Remove reference at end of test case
+ */
+ public function tearDown() {
+ $this->modx = null;
+ $this->formit = null;
+ }
+}
View
79 core/components/formit/test/FiTestHarness.php
@@ -0,0 +1,79 @@
+<?php
+require_once strtr(realpath(dirname(__FILE__)) . '/FiTestCase.php','\\','/');
+/**
+ * Main FormIt test harness.
+ *
+ * @package modx-test
+ */
+class FiTestHarness {
+ /**
+ * @var modX Static reference to modX instance.
+ */
+ public static $modx = null;
+ /**
+ * @var array Static reference to configuration array.
+ */
+ public static $properties = array();
+
+ /**
+ * Load all Test Suites for xPDO Test Harness.
+ *
+ * @return FiTestHarness
+ */
+ public static function suite() {
+ $suite = new FiTestHarness('FiHarness');
+ return $suite;
+ }
+
+ /**
+ * Grab a persistent instance of the xPDO class to share connection data
+ * across multiple tests and test suites.
+ *
+ * @param array $options An array of configuration parameters.
+ * @return xPDO An xPDO object instance.
+ */
+ public static function _getConnection($options = array()) {
+ $modx = FiTestHarness::$modx;
+ if (is_object($modx)) {
+ if (!$modx->request) { $modx->getRequest(); }
+ if (!$modx->error) { $modx->request->loadErrorHandler(); }
+ $modx->error->reset();
+ FiTestHarness::$modx = $modx;
+ return FiTestHarness::$modx;
+ }
+
+ /* include config.core.php */
+ $properties = array();
+ include_once strtr(realpath(dirname(__FILE__)) . '/config.inc.php','\\','/');
+ require_once $config['modx_base_path'].'config.core.php';
+ require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
+ require_once MODX_CORE_PATH.'model/modx/modx.class.php';
+ include_once strtr(realpath(dirname(__FILE__)) . '/properties.inc.php','\\','/');
+
+ if (!defined('MODX_REQP')) {
+ define('MODX_REQP',false);
+ }
+ $modx = new modX(null,$properties);
+ $ctx = !empty($options['ctx']) ? $options['ctx'] : 'web';
+ $modx->initialize($ctx);
+
+ $debug = !empty($options['debug']);
+ $modx->setDebug($debug);
+ if (!empty($properties['logTarget'])) $modx->setLogTarget($properties['logTarget']);
+ if (!empty($properties['logLevel'])) $modx->setLogLevel($properties['logLevel']);
+ $modx->user = $modx->newObject('modUser');
+ $modx->user->set('id',$modx->getOption('modx.test.user.id',null,1));
+ $modx->user->set('username',$modx->getOption('modx.test.user.username',null,'test'));
+
+ $modx->getRequest();
+ $modx->getParser();
+ $modx->request->loadErrorHandler();
+
+ FiTestHarness::$modx = $modx;
+ return $modx;
+ }
+
+ public function getFormIt() {
+
+ }
+}
View
35 core/components/formit/test/Tests/Core/FormItClassTest.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @package formit-test
+ */
+/**
+ * Tests related to basic MODX class methods
+ *
+ * @package formit-test
+ * @group Core
+ */
+class FormItClassTest extends FiTestCase {
+
+ /**
+ * Test the FormIt::initialize method and ensure it returns true.
+ *
+ * @return void
+ */
+ public function testInitialize() {
+ $success = $this->formit->initialize();
+ $this->assertTrue($success,'FormIt::initialize() did not return true.');
+ }
+
+ /**
+ * Test FormIt::loadRequest and ensure it loads a fiRequest instance
+ *
+ * @todo Test passing a custom request class and path
+ *
+ * @return void
+ */
+ public function testLoadRequest() {
+ $request = $this->formit->loadRequest();
+
+ $this->assertInstanceOf('fiRequest',$request,'FormIt::loadRequest did not return an fiRequest type.');
+ }
+}
View
2  core/components/formit/test/config.sample.inc.php
@@ -0,0 +1,2 @@
+<?php
+$config['modx_base_path'] = '/www/path/to/modx/';
View
16 core/components/formit/test/phpunit.xml
@@ -0,0 +1,16 @@
+<phpunit colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="true"
+ verbose="true"
+ bootstrap="FiTestHarness.php"
+ strict="true">
+ <testsuites>
+ <testsuite name="Core">
+ <file>Tests/Core/FormItClassTest.php</file>
+ </testsuite>
+ </testsuites>
+</phpunit>
View
41 core/components/formit/test/properties.sample.inc.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * MODX Revolution
+ *
+ * Copyright 2006-2011 by MODX, LLC.
+ * All rights reserved.
+ *
+ * This program 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 2 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, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * @package modx-test
+ */
+/**
+ * Sample properties file for testing.
+ *
+ * @package modx-test
+ */
+$properties = array(
+ xPDO::OPT_CACHE_PATH => MODX_CORE_PATH.'cache/',
+ xPDO::OPT_HYDRATE_FIELDS => true,
+ xPDO::OPT_HYDRATE_RELATED_OBJECTS => true,
+ xPDO::OPT_HYDRATE_ADHOC_FIELDS => true,
+);
+
+/* PHPUnit test config */
+$properties['modx_test_path'] = dirname(__FILE__) . '/';
+$properties['modx_config_path'] = '';
+$properties['logLevel']= modX::LOG_LEVEL_INFO;
+$properties['ctx'] = 'web';
+$properties['debug'] = false;
Please sign in to comment.
Something went wrong with that request. Please try again.