cvs: pear /DB_QueryTool/docs/UnitTest Common.php DB_QueryTool_UnitTest_Get.php index.php sql.php

From: Date: Fri, 04 Apr 2003 18:15:59 +0000
Subject: cvs: pear /DB_QueryTool/docs/UnitTest Common.php DB_QueryTool_UnitTest_Get.php index.php sql.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-9742@lists.php.net to get a copy of this message
cain Fri Apr 4 13:15:59 2003 EDT Modified files: /pear/DB_QueryTool/docs/UnitTest Common.php DB_QueryTool_UnitTest_Get.php index.php sql.php Log: - add test cases for the bugfix

Index: pear/DB_QueryTool/docs/UnitTest/Common.php diff -u pear/DB_QueryTool/docs/UnitTest/Common.php:1.1 pear/DB_QueryTool/docs/UnitTest/Common.php:1.2 --- pear/DB_QueryTool/docs/UnitTest/Common.php:1.1 Fri Mar 14 15:35:13 2003 +++ pear/DB_QueryTool/docs/UnitTest/Common.php Fri Apr 4 13:15:59 2003 @@ -1,6 +1,6 @@ <?php // -// $Id: Common.php,v 1.1 2003/03/14 20:35:13 cain Exp $ +// $Id: Common.php,v 1.2 2003/04/04 18:15:59 cain Exp $ // require_once 'DB/QueryTool.php'; @@ -11,6 +11,11 @@ class Common extends DB_QueryTool { + var $tableSpec = array( + array('name' => TABLE_QUESTION, 'shortName' => TABLE_QUESTION) + ,array('name' => TABLE_ANSWER, 'shortName' => TABLE_ANSWER) + ); + function Common($table=null) { if ($table != null) { @@ -42,4 +47,4 @@ } -?> \ No newline at end of file +?> Index: pear/DB_QueryTool/docs/UnitTest/DB_QueryTool_UnitTest_Get.php diff -u pear/DB_QueryTool/docs/UnitTest/DB_QueryTool_UnitTest_Get.php:1.1 pear/DB_QueryTool/docs/UnitTest/DB_QueryTool_UnitTest_Get.php:1.2 --- pear/DB_QueryTool/docs/UnitTest/DB_QueryTool_UnitTest_Get.php:1.1 Fri Mar 14 15:35:13 2003 +++ pear/DB_QueryTool/docs/UnitTest/DB_QueryTool_UnitTest_Get.php Fri Apr 4 13:15:59 2003 @@ -1,6 +1,6 @@ <?php // -// $Id: DB_QueryTool_UnitTest_Get.php,v 1.1 2003/03/14 20:35:13 cain Exp $ +// $Id: DB_QueryTool_UnitTest_Get.php,v 1.2 2003/04/04 18:15:59 cain Exp $ // require_once 'DB_QueryTool_UnitTest.php'; @@ -31,6 +31,107 @@ $newData['id'] = $userId; $this->assertEquals($newData,$user->get($userId)); } + + // test if column==table works, using the table TABLE_QUESTION + function test_tableEqualsColumn() + { + $question = new Common(TABLE_QUESTION); + $newData = array(TABLE_QUESTION=>'Why does this not work?'); + $id=$question->add($newData); + + $newData['id']=$id; + $this->assertEquals($newData,$question->get($id)); + } + + // test if column==table works, using the table TABLE_QUESTION + function test_tableEqualsColumnGetAll() + { + $question = new Common(TABLE_QUESTION); + $newData = array(TABLE_QUESTION=>'Why does this not work?'); + $id=$question->add($newData); + + $newData['id']=$id; + $data = $question->getAll(); + // assertEquals doesnt sort arrays recursively, so we have to extract the data :-( + // we cant do this: $this->assertEquals(array($newData),$question->getAll()); + $this->assertEquals($newData,$data[0]); + } + + // test if column==table works, using the table TABLE_QUESTION + // this fails in v0.9.3 + // a join makes it fail!!!, the tests above are just convinience tests + // they are actually meant to work !always! :-) + function test_tableEqualsColumnJoinedGetAll() + { + $theQuestion = 'Why does this not work?'; + $theAnswer = 'I dont know!'; + + $question = new Common(TABLE_QUESTION); + $newQuest = array(TABLE_QUESTION=>$theQuestion); + $qid=$question->add($newQuest); + + $answer = new Common(TABLE_ANSWER); + $newAnswer = array(TABLE_QUESTION.'_id'=>$qid,TABLE_ANSWER=>$theAnswer); + $aid=$answer->add($newAnswer); + + $question->autoJoin(TABLE_ANSWER); + //$newData['id']=$id; + $data = $question->getAll(); + + $expected = array( '_answer_id'=>$aid, + '_answer_answer'=>$theAnswer, + '_answer_question_id'=>$qid, + 'id'=>$qid, + 'question'=>$theQuestion); + // assertEquals doesnt sort arrays recursively, so we have to extract the data :-( + // we cant do this: $this->assertEquals(array($newData),$question->getAll()); + $this->assertEquals($expected,$data[0]); + } + + /** + * This method actually checks if the functionality that needs to be changed + * for the above test to work will still work after the change ... + * + * check if stuff like MAX(id), LOWER(question), etc. will be converted to + * MAX(TABLE_QUESTION.id), LOWER(TABLE_QUESTION.question) + * this is done for preventing ambigious column names, that's why it only applies + * in joined queries ... + */ + function test_testSqlFunction() + { + $theQuestion = 'Why does this not work?'; + $theAnswer = 'I dont know!'; + + $question = new Common(TABLE_QUESTION); + $newQuest = array(TABLE_QUESTION=>$theQuestion); + $qid=$question->add($newQuest); + + $answer = new Common(TABLE_ANSWER); + $newAnswer = array(TABLE_QUESTION.'_id'=>$qid,TABLE_ANSWER=>$theAnswer); + $aid=$answer->add($newAnswer); + + $question->autoJoin(TABLE_ANSWER); +// $question->setSelect('id,'.TABLE_QUESTION.' as question,'.TABLE_ANSWER.' as answer'); + $question->setSelect('MAX(id),'.TABLE_ANSWER.'.id'); + $this->assertTrue(strpos($question->_buildSelectQuery(),'MAX('.TABLE_QUESTION.'.id)')); + + // check '(question)' + $question->setSelect('LOWER(question),'.TABLE_ANSWER.'.*'); + $this->assertTrue(strpos($question->_buildSelectQuery(),'LOWER('.TABLE_QUESTION.'.question)')); + + // check 'id,' + $question->setSelect('id,'.TABLE_ANSWER.'.*'); + $this->assertTrue(strpos($question->_buildSelectQuery(),TABLE_QUESTION.'.id')); + + // check 'id as qid' + $question->setSelect('id as qid,'.TABLE_ANSWER.'.*'); + $this->assertTrue(strpos($question->_buildSelectQuery(),TABLE_QUESTION.'.id as qid')); + + // check 'id as qid' + $question->setSelect('LOWER( question ),'.TABLE_ANSWER.'.*'); + $this->assertTrue(strpos($question->_buildSelectQuery(),'LOWER( '.TABLE_QUESTION.'.question )')); + } + } ?> Index: pear/DB_QueryTool/docs/UnitTest/index.php diff -u pear/DB_QueryTool/docs/UnitTest/index.php:1.3 pear/DB_QueryTool/docs/UnitTest/index.php:1.4 --- pear/DB_QueryTool/docs/UnitTest/index.php:1.3 Wed Mar 26 10:16:14 2003 +++ pear/DB_QueryTool/docs/UnitTest/index.php Fri Apr 4 13:15:59 2003 @@ -1,6 +1,6 @@ <?php // -// $Id: index.php,v 1.3 2003/03/26 15:16:14 cain Exp $ +// $Id: index.php,v 1.4 2003/04/04 18:15:59 cain Exp $ // @@ -12,7 +12,11 @@ define(DB_DSN,'mysql://root@localhost/test'); define(TABLE_USER, 'QueryTool_user'); define(TABLE_ADDRESS, 'QueryTool_address'); -$allTables = array(TABLE_USER,TABLE_ADDRESS); + +define(TABLE_QUESTION, 'question'); +define(TABLE_ANSWER, 'answer'); + +$allTables = array(TABLE_USER,TABLE_ADDRESS,TABLE_QUESTION,TABLE_ANSWER); require_once 'sql.php'; require_once 'Common.php'; @@ -30,6 +34,7 @@ // // run the test suite // + require_once 'DB_QueryTool_UnitTest_Get.php'; require_once 'DB_QueryTool_UnitTest_GetAll.php'; require_once 'DB_QueryTool_UnitTest_GetCount.php'; @@ -40,13 +45,14 @@ $suites[] = new PHPUnit_TestSuite('DB_QueryTool_UnitTest_GetAll'); $suites[] = new PHPUnit_TestSuite('DB_QueryTool_UnitTest_GetCount'); $suites[] = new PHPUnit_TestSuite('DB_QueryTool_UnitTest_Where'); -//require_once 'PHPUnit/GUI/SetupDecorator.php'; -//$gui = new PHPUnit_GUI_SetupDecorator(new PHPUnit_GUI_HTML()); -//$gui->getSuitesFromDir(dirname(__FILE__),'DB_QueryTool_UnitTest_.*'); $gui = new PHPUnit_GUI_HTML(); $gui->addSuites($suites); $gui->show(); - +/* +require_once 'PHPUnit/GUI/SetupDecorator.php'; +$gui = new PHPUnit_GUI_SetupDecorator(new PHPUnit_GUI_HTML()); +$gui->getSuitesFromDir(dirname(__FILE__),'.*\.php',array('UnitTest.php')); +*/ //print_r($errors); ?> Index: pear/DB_QueryTool/docs/UnitTest/sql.php diff -u pear/DB_QueryTool/docs/UnitTest/sql.php:1.1 pear/DB_QueryTool/docs/UnitTest/sql.php:1.2 --- pear/DB_QueryTool/docs/UnitTest/sql.php:1.1 Fri Mar 14 15:35:13 2003 +++ pear/DB_QueryTool/docs/UnitTest/sql.php Fri Apr 4 13:15:59 2003 @@ -1,24 +1,28 @@ <?php - // $Id: sql.php,v 1.1 2003/03/14 20:35:13 cain Exp $ + // $Id: sql.php,v 1.2 2003/04/04 18:15:59 cain Exp $ $dbStructure = array( 'mysql' => array( 'setup' => array( - "DROP TABLE IF EXISTS ".TABLE_USER.";", - "DROP TABLE IF EXISTS ".TABLE_ADDRESS.";", - "DROP TABLE IF EXISTS ".TABLE_USER."_seq;", - "DROP TABLE IF EXISTS ".TABLE_ADDRESS."_seq;", + "DROP TABLE IF EXISTS ".TABLE_USER.";" + ,"DROP TABLE IF EXISTS ".TABLE_ADDRESS.";" + ,"DROP TABLE IF EXISTS ".TABLE_USER."_seq;" + ,"DROP TABLE IF EXISTS ".TABLE_ADDRESS."_seq;" + ,"DROP TABLE IF EXISTS ".TABLE_QUESTION.";" + ,"DROP TABLE IF EXISTS ".TABLE_QUESTION."_seq;" + ,"DROP TABLE IF EXISTS ".TABLE_ANSWER.";" + ,"DROP TABLE IF EXISTS ".TABLE_ANSWER."_seq;" - "CREATE TABLE ".TABLE_ADDRESS." ( + ,"CREATE TABLE ".TABLE_ADDRESS." ( id int(11) NOT NULL default '0', city varchar(100) NOT NULL default '', zip varchar(5) NOT NULL default '', street varchar(100) NOT NULL default '', phone varchar(100) NOT NULL default '', PRIMARY KEY (id) - ) TYPE=MyISAM;", + ) TYPE=MyISAM;" - "CREATE TABLE ".TABLE_USER." ( + ,"CREATE TABLE ".TABLE_USER." ( id int(11) NOT NULL default '0', login varchar(255) NOT NULL default '', password varchar(255) NOT NULL default '', @@ -27,13 +31,31 @@ company_id int(11) NOT NULL default '0', PRIMARY KEY (id) ) TYPE=MyISAM;" + + ,"CREATE TABLE ".TABLE_QUESTION." ( + id int(11) NOT NULL default '0', + ".TABLE_QUESTION." varchar(255) NOT NULL default '', + PRIMARY KEY (id) + ) TYPE=MyISAM;" + + ,"CREATE TABLE ".TABLE_ANSWER." ( + id int(11) NOT NULL default '0', + ".TABLE_ANSWER." varchar(255) NOT NULL default '', + ".TABLE_QUESTION."_id int(11) NOT NULL default '0', + PRIMARY KEY (id) + ) TYPE=MyISAM;" + ), 'tearDown' => array( - "DROP TABLE IF EXISTS ".TABLE_USER.";", - "DROP TABLE IF EXISTS ".TABLE_ADDRESS.";", - "DROP TABLE IF EXISTS ".TABLE_USER."_seq;", - "DROP TABLE IF EXISTS ".TABLE_ADDRESS."_seq;" + "DROP TABLE IF EXISTS ".TABLE_USER.";" + ,"DROP TABLE IF EXISTS ".TABLE_USER."_seq;" + ,"DROP TABLE IF EXISTS ".TABLE_ADDRESS.";" + ,"DROP TABLE IF EXISTS ".TABLE_ADDRESS."_seq;" + ,"DROP TABLE IF EXISTS ".TABLE_QUESTION.";" + ,"DROP TABLE IF EXISTS ".TABLE_QUESTION."_seq;" + ,"DROP TABLE IF EXISTS ".TABLE_ANSWER.";" + ,"DROP TABLE IF EXISTS ".TABLE_ANSWER."_seq;" ) ),
« previous php.pear.cvs (#9742) next »