Inheritance: extends PHPUnit_Framework_TestCase
Exemplo n.º 1
0
 /**
  *
  * @param Node $n The node for which calculate the previous and next node link
  * @param array $params
  */
 public function __construct(Node $n, $params = array())
 {
     $this->_currentNode = $n->id;
     $prevId = DataValidator::validate_node_id($params['prevId']);
     if ($prevId !== false) {
         $this->_previousNode = $prevId;
     } else {
         $this->findPreviousNode($n, $params['userLevel']);
     }
     $nextId = DataValidator::validate_node_id($params['nextId']);
     if ($nextId !== false) {
         $this->_nextNode = $nextId;
     } else {
         $this->findNextNode($n, $params['userLevel']);
     }
     /**
      * @author giorgio 08/ott/2013
      * check if this is a node wich has been generated when creating a test.
      * If it is, next node is the first topic of the test.
      * BUT, I'll pass the computed $this->_nextNode to give a callBack point
      * to be used when user is in the last topic of the test.
      */
     if (MODULES_TEST && strpos($n->type, (string) constant('ADA_PERSONAL_EXERCISE_TYPE')) === 0) {
         if (isset($GLOBALS['dh'])) {
             $GLOBALS['dh']->disconnect();
         }
         $test_db = AMATestDataHandler::instance(MultiPort::getDSN($_SESSION['sess_selected_tester']));
         $res = $test_db->test_getNodes(array('id_nodo_riferimento' => $n->id));
         if (!empty($res) && count($res) == 1 && !AMA_DataHandler::isError($res)) {
             $node = array_shift($res);
             $this->_nextTestNode = $node['id_nodo'];
         }
         /**
          * @author giorgio 06/nov/2013
          * must check if computed $this->_previousNode points to a test
          * and get last topic if it does.
          */
         if (!is_null($this->_previousNode)) {
             $res = $test_db->test_getNodes(array('id_nodo_riferimento' => $this->_previousNode));
         } else {
             $res = array();
         }
         if (!empty($res) && count($res) == 1 && !AMA_DataHandler::isError($res)) {
             $node = array_shift($res);
             $test = NodeTest::readTest($node['id_nodo'], $test_db);
             $this->_prevTestTopic = count($test->_children);
             $this->_prevTestNode = $node['id_nodo'];
         }
         $test_db->disconnect();
     }
 }
  /**
   * {@inheritdoc}
   */
  public function providerSource() {
    // Get the source data from parent.
    $tests = parent::providerSource();

    // The expected results.
    $tests[0]['expected_data'] = [
      [
        'nid' => 7,
        'vid' => 7,
        'type' => 'story',
        'language' => 'fr',
        'title' => 'node title 7',
        'node_uid' => 1,
        'revision_uid' => 2,
        'status' => 1,
        'created' => 1279290910,
        'changed' => 1279308995,
        'comment' => 0,
        'promote' => 1,
        'moderate' => 0,
        'sticky' => 0,
        'tnid' => 6,
        'translate' => 0,
        // Node revision fields.
        'body' => 'body for node 7',
        'teaser' => 'body for node 7',
        'log' => '',
        'timestamp' => 1279308995,
        'format' => 1,
      ],
    ];

    // Do an automatic count.
    $tests[0]['expected_count'] = NULL;

    // Set up source plugin configuration.
    $tests[0]['configuration'] = [
      'translations' => TRUE,
    ];

    return $tests;
  }
Exemplo n.º 3
0
 public function testCreateNewNodes()
 {
     $root = $this->getStore()->rootNode;
     // Create content node
     self::$newNode = $this->getCompanyHome()->createChild("cm_content", "cm_contains", "cm_" . self::$fileName1);
     self::$newNode->cm_name = self::$fileName1;
     self::$newNode->addAspect("cm_titled");
     self::$newNode->cm_title = NodeTest::TITLE;
     self::$newNode->cm_description = NodeTest::DESCRIPTION;
     // Create a new folder node
     self::$newFolderNode = $this->getCompanyHome()->createChild("cm_folder", "cm_contains", "cm_" . self::$folderName1);
     self::$newFolderNode->cm_name = self::$folderName1;
     // Create another content node in the folder just created
     self::$newNode2 = $this->getCompanyHome()->createChild("cm_content", "cm_contains", "cm_" . self::$fileName2);
     self::$newNode2->cm_name = self::$fileName2;
     self::$newNode2->addAspect("cm_titled");
     self::$newNode2->cm_title = NodeTest::TITLE;
     self::$newNode2->cm_description = NodeTest::DESCRIPTION;
     // Save the newly created nodes
     $this->getSession()->save();
     // Do a couple of sanity checks to ensure that the nodes have been created correctly
     $this->assertEquals(NodeTest::TITLE, self::$newNode->cm_title);
     // TODO add more tests ...
 }
Exemplo n.º 4
0
/**
 * Performs basic controls before entering this module
 */
/*if isset $_GET['unload'] means that the system is closing test, so there is no need to save 
  the page in NavigationHistory  */
if (isset($_GET['unload'])) {
    $trackPageToNavigationHistory = false;
}
require_once ROOT_DIR . '/include/module_init.inc.php';
require_once ROOT_DIR . '/browsing/include/browsing_functions.inc.php';
require_once MODULES_TEST_PATH . '/config/config.inc.php';
require_once MODULES_TEST_PATH . '/include/init.inc.php';
//needed to promote AMADataHandler to AMATestDataHandler. $sess_selected_tester is already present in session
$GLOBALS['dh'] = AMATestDataHandler::instance(MultiPort::getDSN($_SESSION['sess_selected_tester']));
$self = whoami();
$test = NodeTest::readTest($_GET['id_test']);
if (!AMATestDataHandler::isError($test)) {
    /**
     * If user has completed or has a terminated status for the instance,
     * redirect to $test->id_nodo_riferimento or its parent depending on 
     * ADA_REDIRECT_TO_TEST being true or false
     */
    if ($userObj->getType() == AMA_TYPE_STUDENT && isset($sess_id_course_instance) && intval($sess_id_course_instance) > 0 && in_array($userObj->get_student_status($userObj->getId(), $sess_id_course_instance), array(ADA_STATUS_COMPLETED, ADA_STATUS_TERMINATED))) {
        /**
         * @author giorgio 07/apr/2015
         *
         * if user has the terminated status for the course instance, redirect to view
         */
        $id_node = $sess_id_course . '_0';
        // if nothing better is found, redirect to course root node
        if (!ADA_REDIRECT_TO_TEST) {
Exemplo n.º 5
0
 /**
  * Create a full structured test
  *
  * @access public
  *
  * @param $data id node
  * @return the relative nodes structure or an AMA_Error object
  */
 public static function readTest($id_nodo, $dh = null)
 {
     if (is_null($dh)) {
         $dh = $GLOBALS['dh'];
     }
     //check if $id_nodo param is an integer and retrieve rows from database
     if (intval($id_nodo) > 0) {
         $id_nodo = intval($id_nodo);
         $data = $dh->test_getNodesByRadix($id_nodo);
         if (AMA_DataHandler::isError($data)) {
             return $data;
         } else {
             $objects = array();
             $root = null;
             //ciclying all rows to instantiate and attach nodes to form a three
             //the external loop is used to catch all the nodes that doesn't find a father on first tries
             while (!empty($data)) {
                 foreach ($data as $k => $v) {
                     $tipo = $v['tipo'][0];
                     $parent = $v['id_nodo_parent'];
                     $id = $v['id_nodo'];
                     //this search the root
                     if (is_null($root) && ($tipo == ADA_TYPE_TEST || $tipo == ADA_TYPE_SURVEY)) {
                         $objects[$id] = NodeTest::readNode($v);
                         $root = $objects[$id];
                         self::$nodesArray[$root->id_nodo] = $root;
                         //once the row is attach, it can be deleted
                         unset($data[$k]);
                     } else {
                         if (!is_null($parent) && isset($objects[$parent])) {
                             $objects[$id] = NodeTest::readNode($v, $objects[$parent]);
                             $objects[$parent]->addChild($objects[$id]);
                             //once the row is attach, it can be deleted
                             unset($data[$k]);
                         }
                     }
                 }
             }
             //free resources
             unset($objects);
             //if $root is still null, the test doesn't exists!
             if (is_null($root)) {
                 return new AMA_Error(AMA_ERR_INCONSISTENT_DATA);
             } else {
                 return $root;
             }
         }
     } else {
         return new AMA_Error(AMA_ERR_WRONG_ARGUMENTS);
     }
 }
Exemplo n.º 6
0
 /**
  * function that return a specific history test
  *
  * @global db $dh
  *
  * @return array an array composed of 'html', 'path' and 'title' keys
  */
 protected function view_history_tests()
 {
     $dh = $GLOBALS['dh'];
     $test = NodeTest::readTest($this->test['id_nodo']);
     if ($dh->isError($test)) {
         $html = sprintf(translateFN('%s non trovato'), $this->singolare);
     } else {
         $test->run($this->history_test['id_history_test'], true);
         $html = $test->render(true);
     }
     $path = '<a href="' . $this->filepath . '?op=' . $this->what . '&id_course_instance=' . $this->course_instanceObj->id . '&id_course=' . $this->courseObj->id . '">' . translateFN('Valutazione') . ' ' . ucfirst($this->plurale) . '</a> &gt; <a href="' . $this->filepath . '?op=' . $this->what . '&id_course_instance=' . $this->course_instanceObj->id . '&id_course=' . $this->courseObj->id . '&id_student=' . $this->history_test['id_utente'] . '">' . $this->student['cognome'] . ' ' . $this->student['nome'] . '</a> &gt; <a href="' . $this->filepath . '?op=' . $this->what . '&id_course_instance=' . $this->course_instanceObj->id . '&id_course=' . $this->courseObj->id . '&id_student=' . $this->history_test['id_utente'] . '&id_test=' . $this->test['id_nodo'] . '">' . $this->test['titolo'] . '</a> &gt; ' . translateFN('Tentativo') . ' #' . $this->history_test['id_history_test'];
     return array('html' => $html, 'path' => $path, 'title' => translateFN('Valutazione') . ' ' . ucfirst($this->plurale));
 }