Exemple #1
0
 /**
  * Tests the get_full_information() function.
  */
 public function test_get_full_information()
 {
     global $PAGE;
     $renderer = $PAGE->get_renderer('core', 'availability');
     // Setup.
     $info = new \core_availability\mock_info();
     // No conditions.
     $structure = tree::get_root_json(array(), tree::OP_OR);
     $tree = new tree($structure);
     $this->assertEquals('', $tree->get_full_information($info));
     // Condition (normal and NOT).
     $structure->c = array(self::mock(array('m' => 'thing')));
     $tree = new tree($structure);
     $this->assertEquals('SA: [FULL]thing', $tree->get_full_information($info));
     $structure->op = '!&';
     $tree = new tree($structure);
     $this->assertEquals('SA: ![FULL]thing', $tree->get_full_information($info));
     // Complex structure.
     $structure->op = '|';
     $structure->c = array(tree::get_nested_json(array(self::mock(array('m' => '1')), self::mock(array('m' => '2'))), tree::OP_AND), self::mock(array('m' => 3)));
     $tree = new tree($structure);
     $this->assertRegExp('~<ul.*<ul.*<li.*1.*<li.*2.*</ul>.*<li.*3~', $renderer->render($tree->get_full_information($info)));
     // Test intro messages before list. First, OR message.
     $structure->c = array(self::mock(array('m' => '1')), self::mock(array('m' => '2')));
     $tree = new tree($structure);
     $this->assertRegExp('~Not available unless any of:.*<ul>~', $renderer->render($tree->get_full_information($info)));
     // Now, OR message when not shown.
     $structure->show = false;
     $tree = new tree($structure);
     $this->assertRegExp('~hidden.*<ul>~', $renderer->render($tree->get_full_information($info)));
     // AND message.
     $structure->op = '&';
     unset($structure->show);
     $structure->showc = array(false, false);
     $tree = new tree($structure);
     $this->assertRegExp('~Not available unless:.*<ul>~', $renderer->render($tree->get_full_information($info)));
     // Hidden markers on items.
     $this->assertRegExp('~1.*hidden.*2.*hidden~', $renderer->render($tree->get_full_information($info)));
     // Hidden markers on child tree and items.
     $structure->c[1] = tree::get_nested_json(array(self::mock(array('m' => '2')), self::mock(array('m' => '3'))), tree::OP_AND);
     $tree = new tree($structure);
     $this->assertRegExp('~1.*hidden.*All of \\(hidden.*2.*3~', $renderer->render($tree->get_full_information($info)));
     $structure->c[1]->op = '|';
     $tree = new tree($structure);
     $this->assertRegExp('~1.*hidden.*Any of \\(hidden.*2.*3~', $renderer->render($tree->get_full_information($info)));
     // Hidden markers on single-item display, AND and OR.
     $structure->showc = array(false);
     $structure->c = array(self::mock(array('m' => '1')));
     $tree = new tree($structure);
     $this->assertRegExp('~1.*hidden~', $tree->get_full_information($info));
     unset($structure->showc);
     $structure->show = false;
     $structure->op = '|';
     $tree = new tree($structure);
     $this->assertRegExp('~1.*hidden~', $tree->get_full_information($info));
     // Hidden marker if single item is tree.
     $structure->c[0] = tree::get_nested_json(array(self::mock(array('m' => '1')), self::mock(array('m' => '2'))), tree::OP_AND);
     $tree = new tree($structure);
     $this->assertRegExp('~Not available \\(hidden.*1.*2~', $renderer->render($tree->get_full_information($info)));
     // Single item tree containing single item.
     unset($structure->c[0]->c[1]);
     $tree = new tree($structure);
     $this->assertRegExp('~SA.*1.*hidden~', $tree->get_full_information($info));
 }