Esempio n. 1
0
 public function testQueryDao()
 {
     // Use Query DAO to insert a new query.
     $dao = new CreateQueryDAO();
     if ($dao == null) {
         echo "dao is null";
     }
     $dao->initTransaction();
     $queryID = $dao->persistNewQuery('title', 1);
     if ($queryID == null) {
         echo "queryID is null";
     }
     $dao->persistQuestion('text');
     $dao->persistAnswer('q0', 0);
     $dao->persistAnswer('q1', 1);
     $dao->persistAnswer('q2', 2);
     $dao->endTransaction();
     // Check DB contains new query with correct values.
     $this->initDBConnection();
     $result = $this->doAssertedQuery('SELECT * FROM queries WHERE id=' . $queryID, 1);
     $row = mysql_fetch_assoc($result);
     if ('title' != $row['title']) {
         echo "title is wrong";
     }
     mysql_free_result($result);
     $result = $this->doAssertedQuery('SELECT * FROM question WHERE FK_queries=' . $queryID, 1);
     $row = mysql_fetch_assoc($result);
     if ('text' != $row['text']) {
         echo "text is wrong";
     }
     $questionID = $row['id'];
     mysql_free_result($result);
     $result = $this->doAssertedQuery('SELECT * FROM qoption WHERE FK_question=' . $questionID, 3);
     $answers = array();
     for ($i = 0; $i < 3; $i++) {
         $row = mysql_fetch_assoc($result);
         $answers[$i] = $row['id'];
         if ('q' . $i != $row['text']) {
             echo 'q' . $i . " not equals " . $row['text'];
         }
         if ($i != $row['number']) {
             echo $i . " not equals " . $row['number'];
         }
     }
     mysql_free_result($result);
     $this->closeDBConnection();
     // Delete query using Query DAO
     $dao->deleteQueryByID($queryID);
     $this->initDBConnection();
     // Verify querry has been deleted
     $result = $this->doAssertedQuery('SELECT * FROM queries WHERE id=' . $queryID, 0);
     mysql_free_result($result);
     $this->closeDBConnection();
 }
Esempio n. 2
0
<?php

namespace Qnet\Controller;

require_once dirname(__FILE__) . '\\..\\util.php';
require_model('User');
require_dao('createQueryDAO');
use Qnet\Dao\CreateQueryDAO;
use Qnet\Model\User;
$queryName = $_POST['queryname'];
$qlength = $_POST['qlength'];
$filterslength = $_POST['filterslength'];
$uid = getUID();
$dao = new CreateQueryDAO();
$dao->initTransaction();
$dao->persistNewQuery($queryName, $uid);
for ($i = 0; $i < $qlength; $i++) {
    $dao->persistQuestion($_POST['questionname' . $i]);
    switch ($_POST['answers' . $i]) {
        case 'yesno':
            $dao->persistAnswer("Yes", 0);
            $dao->persistAnswer("No", 1);
            break;
        case 'lml':
            $dao->persistAnswer("A lot", 0);
            $dao->persistAnswer("Medium", 1);
            $dao->persistAnswer("Low", 2);
            break;
        case 'mf':
            $dao->persistAnswer("Male", 0);
            $dao->persistAnswer("Female", 1);
Esempio n. 3
0
<?php

/**
 * Created by IntelliJ IDEA.
 * User: Tomi
 * Date: 23/06/2010
 * Time: 10:08:29
 * To change this template use File | Settings | File Templates.
 */
use PHPUnit_Framework_TestCase;
require_once dirname(__FILE__) . '\\..\\util.php';
require_dao('queryDAO');
require_dao('createQueryDAO');
use Qnet\Dao\QueryDAO;
use Qnet\Dao\CreateQueryDAO;
$cqd = new CreateQueryDAO();
$qd = new QueryDAO();
$cqd->initTransaction();
$expectedId = $cqd->persistNewQuery("testQuery", 1);
if ($expectedId == null) {
    echo "Coudn't persist query";
}
$foundId = $qd->getQueryIdByQueryTitle("testQuery");
if ($expectedId != $foundId) {
    echo "Queries id doesn't match. Expected {$expectedId}, found {$foundId}";
}