function test_ouwiki_pages_and_versions()
 {
     $user = $this->get_new_user();
     $course = $this->get_new_course();
     // setup a wiki to use
     $ouwiki = $this->get_new_ouwiki($course->id, OUWIKI_SUBWIKIS_SINGLE);
     $cm = $this->get_new_course_module($course->id, $ouwiki->id, NOGROUPS);
     $context = get_context_instance(CONTEXT_MODULE, $cm->instance);
     $groupid = 0;
     $subwiki = ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $user->id, true);
     // create the start page
     $startpagename = 'startpage';
     $formdata = null;
     $startpageversion = ouwiki_get_current_page($subwiki, $startpagename, OUWIKI_GETPAGE_CREATE);
     ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $startpagename, $startpagename, -1, -1, -1, null, $formdata);
     $this->assertIsA($subwiki, "stdClass");
     // create a page
     $pagename1 = 'testpage1';
     $content1 = 'testcontent';
     // we don't get anything returned for this
     ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $startpagename, $pagename1, $content1, $formdata);
     // try get that page
     $pageversion = ouwiki_get_current_page($subwiki, $pagename1);
     $this->assertIsA($subwiki, "stdClass");
     $this->assertEqual($pageversion->title, $pagename1);
     // make some more version
     $content2 = "testcontent2";
     $content3 = "testcontent3";
     ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $pagename1, $content2, -1, -1, -1, null, $formdata);
     ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $pagename1, $content3, -1, -1, -1, null, $formdata);
     // get the history
     $history = ouwiki_get_page_history($pageversion->pageid, true);
     $this->assertIsA($history, "array");
     // last version should match $content3
     $lastversion = array_shift($history);
     $pageversion = ouwiki_get_page_version($subwiki, $pagename1, $lastversion->versionid);
     $this->assertEqual($pageversion->xhtml, $content3);
     // add another page
     $pagename2 = 'testpage2';
     $content4 = 'testcontent4';
     // we don't get anything returned for this
     ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $startpagename, $pagename2, $content4, $formdata);
     // test recent pages
     $changes = ouwiki_get_subwiki_recentpages($subwiki->id);
     $this->assertIsA($changes, "array");
     // first page should be startpage
     $this->assertEqual($changes[1]->title, $startpagename);
     // 3rd page should be pagename2
     $this->assertEqual($changes[3]->title, $pagename2);
     // test recent wiki changes
     $changes = ouwiki_get_subwiki_recentchanges($subwiki->id);
     $this->assertEqual($changes[1]->title, $startpagename);
     // sixth change should be to testpage2  - when we created testpage2
     $this->assertEqual($changes[6]->title, $pagename2);
     // seventh change shouldbe start page again - when we linked to testpage2 to startpage
     $this->assertEqual($changes[7]->title, $startpagename);
     // test deleting a version
 }
示例#2
0
 public function create_content($instance, $record = array())
 {
     global $USER, $DB, $CFG;
     require_once $CFG->dirroot . '/mod/ouwiki/locallib.php';
     $cm = get_coursemodule_from_instance('ouwiki', $instance->id);
     $context = context_module::instance($cm->id);
     // Setup subwiki.
     if (!isset($record['subwiki'])) {
         // Create a new sub wiki object for current user.
         $subwiki = ouwiki_get_subwiki($instance->course, $instance, $cm, $context, 0, $USER->id, true);
     } else {
         $subwiki = $record['subwiki'];
     }
     if (isset($record['newversion'])) {
         // Update an existing page with a new version.
         $newverinfo = $record['newversion'];
         if (!isset($newverinfo->formdata)) {
             $newverinfo->formdata = null;
         }
         if (!isset($newverinfo->pagename)) {
             $newverinfo->pagename = null;
         }
         if (!isset($newverinfo->content)) {
             $newverinfo->content = 'Test content';
         }
         return ouwiki_save_new_version($instance->course, $cm, $instance, $subwiki, $newverinfo->pagename, $newverinfo->content, -1, -1, -1, null, $newverinfo->formdata);
     } else {
         // Create a new page - does this by default (off start page).
         if (!isset($record['newpage'])) {
             $record['newpage'] = new stdClass();
         }
         $newpageinfo = $record['newpage'];
         if (!isset($newpageinfo->formdata)) {
             $newpageinfo->formdata = null;
         }
         if (!isset($newpageinfo->pagename)) {
             $newpageinfo->pagename = null;
         }
         // Ensure linked from page exists.
         ouwiki_get_current_page($subwiki, $newpageinfo->pagename, OUWIKI_GETPAGE_CREATE);
         if (!isset($newpageinfo->newpagename)) {
             $this->pagecount++;
             $newpageinfo->newpagename = 'OU Wiki Test Page' . $this->pagecount;
         }
         if (!isset($newpageinfo->content)) {
             $newpageinfo->content = 'Test content';
         }
         ouwiki_create_new_page($instance->course, $cm, $instance, $subwiki, $newpageinfo->pagename, $newpageinfo->newpagename, $newpageinfo->content, $newpageinfo->formdata);
         return ouwiki_get_current_page($subwiki, $newpageinfo->newpagename);
     }
 }
 public function test_ouwiki_structure()
 {
     $this->resetAfterTest(true);
     $user = $this->get_new_user();
     $course = $this->get_new_course();
     // Setup a wiki to use.
     $ouwiki = $this->get_new_ouwiki($course->id, OUWIKI_SUBWIKIS_SINGLE);
     $cm = get_coursemodule_from_instance('ouwiki', $ouwiki->id);
     $this->assertNotEmpty($cm);
     $context = context_module::instance($cm->id);
     $groupid = 0;
     $this->setUser($user);
     $subwiki = ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $user->id, true);
     // Create the start page.
     $startpagename = 'testpage1';
     $formdata = null;
     $startpageversion = ouwiki_get_current_page($subwiki, $startpagename, OUWIKI_GETPAGE_CREATE);
     $verid = ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $startpagename, $startpagename, -1, -1, -1, null, $formdata);
     // Create a page with no sub pages.
     $pagename2 = 'testpage2';
     $content2 = 'testcontent2';
     ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $startpagename, $pagename2, $content2, $formdata);
     // Try get that page.
     $pageversion = ouwiki_get_current_page($subwiki, $pagename2);
     $this->assertEquals($pageversion->title, $pagename2);
     // Test fullname info from ouwiki_get_current_page.
     $this->assertEquals(fullname($user), fullname($pageversion));
     // Add another page to start page.
     $pagename3 = 'testpage3';
     $content3 = 'testcontent3';
     // We don't get anything returned for this.
     ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $startpagename, $pagename3, $content3, $formdata);
     // Try get that page.
     $pageversion = ouwiki_get_current_page($subwiki, $pagename3);
     $this->assertEquals($pageversion->title, $pagename3);
     // Test fullname info from ouwiki_get_current_page.
     $this->assertEquals(fullname($user), fullname($pageversion));
     // Add another page to start page.
     $pagename9 = 'testpage9';
     $content9 = 'testcontent9';
     // We don't get anything returned for this.
     ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $startpagename, $pagename9, $content9, $formdata);
     // Try get that page.
     $pageversion = ouwiki_get_current_page($subwiki, $pagename9);
     $this->assertEquals($pageversion->title, $pagename9);
     // Test fullname info from ouwiki_get_current_page.
     $this->assertEquals(fullname($user), fullname($pageversion));
     // Add pages to testpage3.
     // Add page to test page 3.
     $pagename4 = 'testpage4';
     $content4 = 'testcontent4';
     // We don't get anything returned for this.
     ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $pagename3, $pagename4, $content4, $formdata);
     // Try get that page.
     $pageversion = ouwiki_get_current_page($subwiki, $pagename4);
     $this->assertEquals($pageversion->title, $pagename4);
     // Test fullname info from ouwiki_get_current_page.
     $this->assertEquals(fullname($user), fullname($pageversion));
     // Add another page to testpage 3.
     $pagename8 = 'testpage8';
     $content8 = 'testcontent8';
     // We don't get anything returned for this.
     ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $pagename3, $pagename8, $content8, $formdata);
     // Try get that page.
     $pageversion = ouwiki_get_current_page($subwiki, $pagename8);
     $this->assertEquals($pageversion->title, $pagename8);
     // Test fullname info from ouwiki_get_current_page.
     $this->assertEquals(fullname($user), fullname($pageversion));
     // Add pages to testpage4.
     // Add page to test page 4.
     $pagename5 = 'testpage5';
     $content5 = 'testcontent5';
     // We don't get anything returned for this.
     ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $pagename4, $pagename5, $content5, $formdata);
     // Try get that page.
     $pageversion = ouwiki_get_current_page($subwiki, $pagename5);
     $this->assertEquals($pageversion->title, $pagename5);
     // Test fullname info from ouwiki_get_current_page.
     $this->assertEquals(fullname($user), fullname($pageversion));
     // Add another page to testpage 4.
     $pagename7 = 'testpage7';
     $content7 = 'testcontent7';
     // We don't get anything returned for this.
     ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $pagename4, $pagename7, $content7, $formdata);
     // Try get that page.
     $pageversion = ouwiki_get_current_page($subwiki, $pagename7);
     $this->assertEquals($pageversion->title, $pagename7);
     // Test fullname info from ouwiki_get_current_page.
     $this->assertEquals(fullname($user), fullname($pageversion));
     // Add page to test page 5.
     $pagename6 = 'testpage6';
     $content6 = 'testcontent6';
     // We don't get anything returned for this.
     ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $pagename5, $pagename6, $content6, $formdata);
     // Try get that page.
     $pageversion = ouwiki_get_current_page($subwiki, $pagename6);
     $this->assertEquals($pageversion->title, $pagename6);
     // Test fullname info from ouwiki_get_current_page.
     $this->assertEquals(fullname($user), fullname($pageversion));
     // Add page to test page 9.
     $pagename10 = 'testpage10';
     $content10 = 'testcontent10';
     // We don't get anything returned for this.
     ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $pagename9, $pagename10, $content10, $formdata);
     // Try get that page.
     $pageversion = ouwiki_get_current_page($subwiki, $pagename10);
     $this->assertEquals($pageversion->title, $pagename10);
     // Test fullname info from ouwiki_get_current_page.
     $this->assertEquals(fullname($user), fullname($pageversion));
     // Add another page to testpage 9.
     $pagename12 = 'testpage12';
     $content12 = 'testcontent12';
     // We don't get anything returned for this.
     ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $pagename9, $pagename12, $content12, $formdata);
     // Try get that page.
     $pageversion = ouwiki_get_current_page($subwiki, $pagename12);
     $this->assertEquals($pageversion->title, $pagename12);
     // Test fullname info from ouwiki_get_current_page.
     $this->assertEquals(fullname($user), fullname($pageversion));
     // Add page to test page 10.
     $pagename11 = 'testpage11';
     $content11 = 'testcontent11';
     // We don't get anything returned for this.
     ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $pagename10, $pagename11, $content11, $formdata);
     // Try get that page.
     $pageversion = ouwiki_get_current_page($subwiki, $pagename11);
     $this->assertEquals($pageversion->title, $pagename11);
     // Test fullname info from ouwiki_get_current_page.
     $this->assertEquals(fullname($user), fullname($pageversion));
     // Create the index.
     $index = ouwiki_get_subwiki_index($subwiki->id);
     // Check to see that there are 12 posts.
     $this->assertEquals(count($index), 12);
     reset($index);
     $orphans = false;
     // Check for orphan posts - there should be none.
     foreach ($index as $indexitem) {
         if (count($indexitem->linksfrom) == 0 && $indexitem->title !== 'testpage1') {
             $orphans = true;
             break;
         }
     }
     $this->assertEquals($orphans, false);
     // Test tree structure functions.
     // Build tree.
     ouwiki_build_tree($index);
     // Check to see whether pages have the correct number of children in them including the root node.
     $page = $this->get_page_from_index_by_pagename('testpage3', $index);
     $subtree = ouwiki_get_sub_tree_from_index($page->pageid, $index);
     $this->assertEquals(6, count($subtree));
     // Check to see whether pages have the correct number of children in them including the root node.
     $page = $this->get_page_from_index_by_pagename('testpage4', $index);
     $subtree = ouwiki_get_sub_tree_from_index($page->pageid, $index);
     $this->assertEquals(4, count($subtree));
     // Check linkto, linksfrom, and children arrays for testpage 4
     // - see structure diagram in function description for links to, from, and children for P4.
     $linksfrom = $page->linksfrom;
     $linksto = $page->linksto;
     $children = $page->children;
     $this->assertEquals(count($linksfrom), 1);
     $this->assertEquals(count($linksto), 2);
     $this->assertEquals(count($children), 2);
     // Test linksfrom from testpage 4.
     $p = $this->get_page_from_index_by_pageid($linksfrom[0], $index);
     $this->assertEquals($p->title, $pagename3);
     // Test linksto for testpage 4.
     $p = $this->get_page_from_index_by_pageid($linksto[0], $index);
     $this->assertEquals($p->title, $pagename5);
     $p = $this->get_page_from_index_by_pageid($linksto[1], $index);
     $this->assertEquals($p->title, $pagename7);
     // Test children for testpage 4.
     $p = $this->get_page_from_index_by_pageid($children[0], $index);
     $this->assertEquals($p->title, $pagename5);
     $p = $this->get_page_from_index_by_pageid($children[1], $index);
     $this->assertEquals($p->title, $pagename7);
     // Check to see whether pages have the correct number of children in them including the root node.
     $page = $this->get_page_from_index_by_pagename('testpage5', $index);
     $this->assertEquals(2, count(ouwiki_get_sub_tree_from_index($page->pageid, $index)));
     // Check to see whether pages have the correct number of children in them including the root node.
     $page = $this->get_page_from_index_by_pagename('testpage9', $index);
     $this->assertEquals(4, count(ouwiki_get_sub_tree_from_index($page->pageid, $index)));
     // Check to see whether pages have the correct number of children in them including the root node.
     $page = $this->get_page_from_index_by_pagename('testpage10', $index);
     $this->assertEquals(2, count(ouwiki_get_sub_tree_from_index($page->pageid, $index)));
 }
示例#4
0
     ouwiki_release_lock($pageversion->pageid);
     echo $OUTPUT->header();
     $pagefield = '';
     if ($returnpage !== '') {
         $pagefield = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'page', 'value' => $returnpage));
     }
     print '<div id="ouwiki_savefail">' . '<h2>' . $savefailtitle . '</h2>' . '<p>' . $specificmessage . '</p>' . '<form action="view.php" method="get">' . '<input type="hidden" name="id" value="' . $cm->id . '" />' . $pagefield . '<input type="submit" value="' . $returntoview . '" />' . '</form>' . '<p>' . $savefailcontent . '</p>' . '<div class="ouwiki_savefailcontent">' . $actualcontent . '</div>' . '</div><div>';
     ouwiki_print_footer($course, $cm, $subwiki, $pagename);
     exit;
 }
 $event = null;
 if ($section) {
     ouwiki_save_new_version_section($course, $cm, $ouwiki, $subwiki, $pagename, $pageversion->xhtml, $formdata->content['text'], $sectiondetails, $formdata);
 } else {
     if ($addpage) {
         ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $frompage, $pagename, $content, $formdata);
     } else {
         if ($addsection) {
             ouwiki_create_new_section($course, $cm, $ouwiki, $subwiki, $pagename, $formdata->content['text'], $sectionheader, $formdata);
         } else {
             // Normal save
             ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $pagename, $content, -1, -1, -1, null, $formdata);
         }
     }
 }
 // Update completion state
 $completion = new completion_info($course);
 if ($completion->is_enabled($cm) && ($ouwiki->completionedits || $ouwiki->completionpages)) {
     $completion->update_state($cm, COMPLETION_COMPLETE);
 }
 // Release lock, log and redirect.
        ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $pagename, $context);
        $savefailtitle = get_string('savefailtitle', 'ouwiki');
        $specificmessage = get_string(!$versionok ? 'savefaildesynch' : 'savefaillocked', 'ouwiki');
        $returntoview = get_string('returntoview', 'ouwiki');
        $savefailcontent = get_string('savefailcontent', 'ouwiki');
        $actualcontent = ouwiki_convert_content($content, $subwiki, $cm);
        print "\n<div id='ouwiki_savefail'>\n  <h2>{$savefailtitle}</h2>\n  <p>{$specificmessage}</p>\n  <form action='view.php' method='get'>\n    {$wikiformfields}\n    <input type='submit' value='{$returntoview}' />\n  </form>\n  <p>{$savefailcontent}</p>\n  <div class='ouwiki_savefailcontent'>\n    {$actualcontent}\n  </div>\n</div>";
        print_footer($course);
        exit;
    }
    $section = optional_param('section', null, PARAM_RAW);
    if ($section) {
        ouwiki_save_new_version_section($course, $cm, $ouwiki, $subwiki, $pagename, $pageversion->xhtml, $content, $sectiondetails);
    } else {
        if ($createnewpage) {
            ouwiki_create_new_page($course, $cm, $ouwiki, $subwiki, $originalpagename, $pagename, $content);
        } else {
            if ($addnewsection) {
                ouwiki_create_new_section($course, $cm, $ouwiki, $subwiki, $pagename, $content, $sectionheader);
            } else {
                // do normal save
                ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, $pagename, $content);
            }
            // endif
        }
        // endif
    }
}
// Redirect for save or cancel
if ($actionsave || $actioncancel) {
    ouwiki_release_lock($pageversion->pageid);