home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / xamp / xampp-win32.exe / xampp / Get.php < prev    next >
Encoding:
PHP Script  |  2004-10-01  |  5.2 KB  |  135 lines

  1. <?php
  2. //
  3. //  $Id: Get.php,v 1.1 2003/06/06 14:39:44 cain Exp $
  4. //
  5.  
  6. class tests_Get extends tests_UnitTest
  7. {
  8.     function test_AddGet()
  9.     {
  10.         $user = new tests_Common(TABLE_USER);
  11.         $newData = array(   'login'     =>  'cain',
  12.                             'password'  =>  '0',
  13.                             'name'      =>  'Lutz Testern',
  14.                             'address_id'=>  0,
  15.                             'company_id'=>  0
  16.                         );
  17.         $userId = $user->add( $newData );       
  18.         $newData['id'] = $userId;
  19.         $this->assertEquals($newData,$user->get($userId));
  20.     
  21.         $newData = array(   'login'     =>  '',
  22.                             'password'  =>  '',
  23.                             'name'      =>  '',
  24.                             'address_id'=>  0,
  25.                             'company_id'=>  0
  26.                         );
  27.         $userId = $user->add( $newData );       
  28.         $newData['id'] = $userId;
  29.         $this->assertEquals($newData,$user->get($userId));
  30.     }
  31.     
  32.     // test if column==table works, using the table TABLE_QUESTION
  33.     function test_tableEqualsColumn()
  34.     {
  35.         $question = new tests_Common(TABLE_QUESTION);
  36.         $newData = array(TABLE_QUESTION=>'Why does this not work?');
  37.         $id=$question->add($newData);
  38.         
  39.         $newData['id']=$id;
  40.         $this->assertEquals($newData,$question->get($id));
  41.     }    
  42.     
  43.     // test if column==table works, using the table TABLE_QUESTION
  44.     function test_tableEqualsColumnGetAll()
  45.     {
  46.         $question = new tests_Common(TABLE_QUESTION);
  47.         $newData = array(TABLE_QUESTION=>'Why does this not work?');
  48.         $id=$question->add($newData);
  49.         
  50.         $newData['id']=$id;
  51.         $data = $question->getAll();
  52.         // assertEquals doesnt sort arrays recursively, so we have to extract the data :-(
  53.         // we cant do this:     $this->assertEquals(array($newData),$question->getAll());
  54.         $this->assertEquals($newData,$data[0]);
  55.     }    
  56.     
  57.     // test if column==table works, using the table TABLE_QUESTION
  58.     // this fails in v0.9.3
  59.     // a join makes it fail!!!, the tests above are just convinience tests
  60.     // they are actually meant to work !always! :-)
  61.     function test_tableEqualsColumnJoinedGetAll()
  62.     {
  63.         $theQuestion = 'Why does this not work?';
  64.         $theAnswer = 'I dont know!';
  65.     
  66.         $question = new tests_Common(TABLE_QUESTION);        
  67.         $newQuest = array(TABLE_QUESTION=>$theQuestion);
  68.         $qid=$question->add($newQuest);
  69.         
  70.         $answer = new tests_Common(TABLE_ANSWER);
  71.         $newAnswer = array(TABLE_QUESTION.'_id'=>$qid,TABLE_ANSWER=>$theAnswer);
  72.         $aid=$answer->add($newAnswer);
  73.         
  74.         $question->autoJoin(TABLE_ANSWER);
  75.         //$newData['id']=$id;
  76.         $data = $question->getAll();
  77.         
  78.         $expected =  array( '_answer_id'=>$aid,
  79.                             '_answer_answer'=>$theAnswer,
  80.                             '_answer_question_id'=>$qid,
  81.                             'id'=>$qid,
  82.                             'question'=>$theQuestion);
  83.         // assertEquals doesnt sort arrays recursively, so we have to extract the data :-(
  84.         // we cant do this:     $this->assertEquals(array($newData),$question->getAll());
  85.         $this->assertEquals($expected,$data[0]);
  86.     }    
  87.  
  88.     /**
  89.     *   This method actually checks if the functionality that needs to be changed
  90.     *   for the above test to work will still work after the change ...
  91.     *
  92.     *   check if stuff like MAX(id), LOWER(question), etc. will be converted to 
  93.     *       MAX(TABLE_QUESTION.id), LOWER(TABLE_QUESTION.question)
  94.     *   this is done for preventing ambigious column names, that's why it only applies
  95.     *   in joined queries ...
  96.     */
  97.     function test_testSqlFunction()
  98.     {
  99.         $theQuestion = 'Why does this not work?';
  100.         $theAnswer = 'I dont know!';
  101.     
  102.         $question = new tests_Common(TABLE_QUESTION);        
  103.         $newQuest = array(TABLE_QUESTION=>$theQuestion);
  104.         $qid=$question->add($newQuest);
  105.         
  106.         $answer = new tests_Common(TABLE_ANSWER);
  107.         $newAnswer = array(TABLE_QUESTION.'_id'=>$qid,TABLE_ANSWER=>$theAnswer);
  108.         $aid=$answer->add($newAnswer);
  109.         
  110.         $question->autoJoin(TABLE_ANSWER);
  111. //        $question->setSelect('id,'.TABLE_QUESTION.' as question,'.TABLE_ANSWER.' as answer');
  112.         $question->setSelect('MAX(id),'.TABLE_ANSWER.'.id');
  113.         $this->assertTrue(strpos($question->_buildSelectQuery(),'MAX('.TABLE_QUESTION.'.id)')); 
  114.     
  115.         // check '(question)'
  116.         $question->setSelect('LOWER(question),'.TABLE_ANSWER.'.*');
  117.         $this->assertTrue(strpos($question->_buildSelectQuery(),'LOWER('.TABLE_QUESTION.'.question)')); 
  118.     
  119.         // check 'id,'
  120.         $question->setSelect('id,'.TABLE_ANSWER.'.*');
  121.         $this->assertTrue(strpos($question->_buildSelectQuery(),TABLE_QUESTION.'.id')); 
  122.     
  123.         // check 'id as qid'
  124.         $question->setSelect('id as qid,'.TABLE_ANSWER.'.*');
  125.         $this->assertTrue(strpos($question->_buildSelectQuery(),TABLE_QUESTION.'.id as qid')); 
  126.     
  127.         // check 'id as qid'
  128.         $question->setSelect('LOWER( question ),'.TABLE_ANSWER.'.*');
  129.         $this->assertTrue(strpos($question->_buildSelectQuery(),'LOWER( '.TABLE_QUESTION.'.question )')); 
  130.     }    
  131.         
  132. }
  133.  
  134. ?>
  135.