home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / Get.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  5.2 KB  |  134 lines

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