/**
  * 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 ambiguous 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 MDB_QT(TABLE_QUESTION);
     $newQuest = array(TABLE_QUESTION => $theQuestion);
     $qid = $question->add($newQuest);
     $answer = new MDB_QT(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 )'));
 }
 /**
  * This method checks if the getJoin() method is working correctly
  */
 function test_getJoin()
 {
     $question = new MDB_QT(TABLE_QUESTION);
     $joinOn1 = TABLE_QUESTION . '.id=' . TABLE_ANSWER . '.question_id';
     $question->setJoin(TABLE_ANSWER, $joinOn1);
     $all = array('default' => array(TABLE_ANSWER => $joinOn1));
     $tables = array(TABLE_ANSWER);
     $right = array();
     $left = array();
     $this->assertEqual($all, $question->getJoin());
     $this->assertEqual($tables, $question->getJoin('tables'));
     $this->assertEqual($right, $question->getJoin('right'));
     $this->assertEqual($left, $question->getJoin('left'));
     //--------------------------------------------------------
     $joinOn2 = TABLE_USER . '.id=' . TABLE_ANSWER . '.question_id';
     $question->setRightJoin(TABLE_USER, $joinOn2);
     $all = array('default' => array(TABLE_ANSWER => $joinOn1), 'right' => array(TABLE_USER => $joinOn2));
     $tables = array(TABLE_ANSWER, TABLE_USER);
     $right = array(TABLE_USER => $joinOn2);
     $left = array();
     $this->assertEqual($all, $question->getJoin());
     $this->assertEqual($tables, $question->getJoin('tables'));
     $this->assertEqual($right, $question->getJoin('right'));
     $this->assertEqual($left, $question->getJoin('left'));
 }