Skip to content

Commit

Permalink
Behat: mod/ouwiki (tt, OUVLE_458) - Test editing for past, future and…
Browse files Browse the repository at this point in the history
… together + 3 more... #679632
  • Loading branch information
lamtranb authored and sammarshallou committed Jun 15, 2023
1 parent 3b6fd2f commit bc36df8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1627,8 +1627,11 @@ function ouwiki_get_subwiki_missingpages($subwikiid, $limitfrom = '', $limitnum
* @return array Associative array of section ID => current title
*/
function ouwiki_find_sections($content) {
$results = array();
$matchlist = array();
$results = [];
if (is_null($content)) {
return $results;
}
$matchlist = [];
preg_match_all('~<h([0-9]) id="ouw_s([0-9]+_[0-9]+)">(.*?)</h([0-9])>~s',
$content, $matchlist, PREG_SET_ORDER);
foreach ($matchlist as $matches) {
Expand Down
9 changes: 8 additions & 1 deletion tests/sections_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_ouwiki;

if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
global $CFG;

require_once($CFG->dirroot . '/mod/ouwiki/locallib.php');

class ouwiki_test_sections extends advanced_testcase {
class sections_test extends advanced_testcase {

public $sample = '
<h1 id="ouw_s0_0">Start</h1>
Expand Down Expand Up @@ -67,4 +69,9 @@ public function test_find_sections() {
'0_1' => 'End'
), $sections);
}

public function test_find_sections_with_null_content(): void {
$sections = ouwiki_find_sections(null);
$this->assertEquals([], $sections);
}
}

0 comments on commit bc36df8

Please sign in to comment.