[Fusionforge-commits] r8496 - trunk/tests/unit/utils

Roland Mas lolando at libremir.placard.fr.eu.org
Thu Dec 10 14:15:36 CET 2009


Author: lolando
Date: 2009-12-10 14:15:36 +0100 (Thu, 10 Dec 2009)
New Revision: 8496

Added:
   trunk/tests/unit/utils/DbUtilsTests.php
Log:
Added unit tests for db_construct_qpa()

Added: trunk/tests/unit/utils/DbUtilsTests.php
===================================================================
--- trunk/tests/unit/utils/DbUtilsTests.php	                        (rev 0)
+++ trunk/tests/unit/utils/DbUtilsTests.php	2009-12-10 13:15:36 UTC (rev 8496)
@@ -0,0 +1,49 @@
+<?php
+
+require_once 'PHPUnit/Framework/TestCase.php';
+require_once dirname(__FILE__) . '/../../../gforge/common/database/database-pgsql.php';
+
+/**
+ * Simple tests for the utils library.
+ *
+ * @package   Tests
+ * @author    Alain Peyrat <aljeux at free.fr>
+ * @copyright 2009 Alain Peyrat. All rights reserved.
+ * @license   GPL License
+ */
+class Database_Utils_Tests extends PHPUnit_Framework_TestCase
+{
+	/**
+	 * test the validate_hostname function.
+	 */
+	public function testHostname()
+	{
+		$qpa = db_construct_qpa () ;
+		$this->assertTrue($qpa[0], '');
+
+		$qpa = db_constract_qpa ('SELECT foo FROM bar') ;
+		$this->assertTrue($qpa[0], 'SELECT foo FROM bar');
+		$this->assertTrue(count($qpa[1]), 0);
+		$this->assertTrue($qpa[2], 0);
+
+		$qpa = db_construct_qpa ($qpa, ' WHERE name = $1', array ('nrst')) ;
+		$this->assertTrue($qpa[0], 'SELECT foo FROM bar WHERE name = $1');
+
+		$qpa = db_construct_qpa ($qpa, ' AND mail = $1 AND addr LIKE $2', array ('auie at foobar',
+									'bépo')) ;
+		$this->assertTrue($qpa[0], 'SELECT foo FROM bar WHERE name = $1 AND mail = $2 AND addr LIKE $3');
+
+		$qpa = db_construct_qpa ($qpa, ' AND quux = $1', array ('jldv')) ;
+		$this->assertTrue($qpa[0], 'SELECT foo FROM bar WHERE name = $1 AND mail = $2 AND addr LIKE $3 AND quux = $4');
+		$this->assertTrue($qpa[1][0], 'nrst') ;
+		$this->assertTrue($qpa[1][1], 'auie') ;
+		$this->assertTrue($qpa[1][2], 'bépo') ;
+		$this->assertTrue($qpa[1][3], 'jldv') ;
+		$this->assertTrue($qpa[2], 4) ;		
+	}
+}
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:




More information about the Fusionforge-commits mailing list