Permalink
Browse files

Tests: add new Helper API test script

Currently only covers helper_array_transpose() function
  • Loading branch information...
1 parent 787c4d4 commit acb902123731b5e70aacea068a545d4247e203ae @dregad dregad committed May 23, 2013
Showing with 87 additions and 0 deletions.
  1. +2 −0 tests/Mantis/AllTests.php
  2. +85 −0 tests/Mantis/HelperTest.php
@@ -29,6 +29,7 @@
require_once dirname( dirname(__FILE__) ) . DIRECTORY_SEPARATOR . 'TestConfig.php';
require_once 'EnumTest.php';
+require_once 'HelperTest.php';
require_once 'StringTest.php';
@@ -44,6 +45,7 @@ public static function suite()
$suite = new Mantis_AllTests('Main Code');
$suite->addTestSuite('MantisEnumTest');
+ $suite->addTestSuite('Mantis_HelperTest');
$suite->addTestSuite('Mantis_StringTest');
return $suite;
@@ -0,0 +1,85 @@
+<?php
+# MantisBT - a php based bugtracking system
+
+# MantisBT 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.
+#
+# MantisBT 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 MantisBT. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package Tests
+ * @subpackage Helper
+ * @copyright Copyright (C) 2002 - 2013 MantisBT Team - mantisbt-dev@lists.sourceforge.net
+ * @link http://www.mantisbt.org
+ */
+
+/**
+ * Includes
+ */
+require_once dirname( dirname(__FILE__) ) . DIRECTORY_SEPARATOR . 'TestConfig.php';
+
+require_once( 'constant_inc.php' );
+require_once( 'config_defaults_inc.php' );
+require_once( 'helper_api.php' );
+
+
+/**
+ * Helper API tests
+ * @package Tests
+ * @subpackage String
+ */
+class Mantis_HelperTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * Tests helper_array_transpose()
+ * @dataProvider providerArrayTranspose
+ */
+ public function testArrayTranspose( $in, $out )
+ {
+ $this->assertEquals( $out, helper_array_transpose( $in ) );
+ }
+
+ public function providerArrayTranspose()
+ {
+ return array(
+ # null
+ array( null, null ),
+
+ # scalar
+ array( 123, 123 ),
+
+ # object
+ array( $this, $this ),
+
+ # simple array
+ array( array(123,456), array(123,456) ),
+
+ # mixed (1st element array, 2nd scalar)
+ array(
+ array('a'=>array('k1'=>1,'k2'=>2),'b'=>123),
+ array('a'=>array('k1'=>1,'k2'=>2),'b'=>123),
+ ),
+
+ # bidimentional array
+ array(
+ array('a'=>array('k1'=>1,'k2'=>2),'b'=>array('k1'=>3,'k2'=>4)),
+ array('k1'=>array('a'=>1,'b'=>3),'k2'=>array('a'=>2,'b'=>4))
+ ),
+
+ # bidimentional array with arrays as elements' data
+ array(
+ array('a'=>array('k1'=>array(1,2,3),'k2'=>2),'b'=>array('k1'=>array(4,5,6),'k2'=>4)),
+ array('k1'=>array('a'=>array(1,2,3),'b'=>array(4,5,6)),'k2'=>array('a'=>2,'b'=>4))
+ ),
+ );
+ }
+
+}

0 comments on commit acb9021

Please sign in to comment.