Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Moodle Filter Opencast
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
Moodle Filter Opencast
Commits
e09b654c
Commit
e09b654c
authored
1 year ago
by
Justus Dieckmann
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for the filter
parent
a80464e1
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
filter.php
+5
-5
5 additions, 5 deletions
filter.php
tests/replacement_test.php
+106
-0
106 additions, 0 deletions
tests/replacement_test.php
tests/testable_filter.php
+55
-0
55 additions, 0 deletions
tests/testable_filter.php
with
166 additions
and
5 deletions
filter.php
+
5
−
5
View file @
e09b654c
...
@@ -137,7 +137,7 @@ class filter_opencast extends moodle_text_filter {
...
@@ -137,7 +137,7 @@ class filter_opencast extends moodle_text_filter {
if
(
self
::
str_starts_with
(
$match
,
"</
$currenttag
"
))
{
if
(
self
::
str_starts_with
(
$match
,
"</
$currenttag
"
))
{
$replacement
=
null
;
$replacement
=
null
;
if
(
$episode
)
{
if
(
$episode
)
{
$replacement
=
self
::
render_player
(
$episode
[
0
],
$episode
[
1
],
$i
++
,
$width
,
$height
);
$replacement
=
$this
->
render_player
(
$episode
[
0
],
$episode
[
1
],
$i
++
,
$width
,
$height
);
}
}
if
(
$replacement
)
{
if
(
$replacement
)
{
$newtext
.
=
$replacement
;
$newtext
.
=
$replacement
;
...
@@ -149,14 +149,14 @@ class filter_opencast extends moodle_text_filter {
...
@@ -149,14 +149,14 @@ class filter_opencast extends moodle_text_filter {
$height
=
null
;
$height
=
null
;
$texttoreplace
=
null
;
$texttoreplace
=
null
;
$currenttag
=
null
;
$currenttag
=
null
;
}
else
if
(
!
$episode
&&
$currenttag
===
'video'
&&
self
::
str_starts_with
(
$
match
,
'
<source
'
))
{
}
else
if
(
!
$episode
&&
$currenttag
===
'video'
&&
preg_
match
(
'/^
<source
\s/'
,
$match
))
{
$src
=
self
::
get_attribute
(
$match
,
'src'
);
$src
=
self
::
get_attribute
(
$match
,
'src'
);
if
(
$src
)
{
if
(
$src
)
{
$episode
=
self
::
test_url
(
$src
,
$occurrences
);
$episode
=
self
::
test_url
(
$src
,
$occurrences
);
}
}
}
}
}
else
{
}
else
{
if
(
self
::
str_starts_with
(
$
match
,
'
<video
'
))
{
if
(
preg_
match
(
'/^
<video
[>\s]/'
,
$match
))
{
$currenttag
=
'video'
;
$currenttag
=
'video'
;
$width
=
self
::
get_attribute
(
$match
,
'width'
,
'[0-9]+'
);
$width
=
self
::
get_attribute
(
$match
,
'width'
,
'[0-9]+'
);
$height
=
self
::
get_attribute
(
$match
,
'height'
,
'[0-9]+'
);
$height
=
self
::
get_attribute
(
$match
,
'height'
,
'[0-9]+'
);
...
@@ -164,7 +164,7 @@ class filter_opencast extends moodle_text_filter {
...
@@ -164,7 +164,7 @@ class filter_opencast extends moodle_text_filter {
if
(
$src
)
{
if
(
$src
)
{
$episode
=
self
::
test_url
(
$src
,
$occurrences
);
$episode
=
self
::
test_url
(
$src
,
$occurrences
);
}
}
}
else
if
(
self
::
str_starts_with
(
$match
,
'<a '
))
{
}
else
if
(
preg_match
(
'/^<a\s/'
,
$match
))
{
$src
=
self
::
get_attribute
(
$match
,
'href'
);
$src
=
self
::
get_attribute
(
$match
,
'href'
);
if
(
$src
)
{
if
(
$src
)
{
$episode
=
self
::
test_url
(
$src
,
$occurrences
);
$episode
=
self
::
test_url
(
$src
,
$occurrences
);
...
@@ -195,7 +195,7 @@ class filter_opencast extends moodle_text_filter {
...
@@ -195,7 +195,7 @@ class filter_opencast extends moodle_text_filter {
* @param int|null $height Optionally height for player.
* @param int|null $height Optionally height for player.
* @return string|null
* @return string|null
*/
*/
pr
ivate
static
function
render_player
(
int
$ocinstanceid
,
string
$episodeid
,
int
$playerid
,
pr
otected
function
render_player
(
int
$ocinstanceid
,
string
$episodeid
,
int
$playerid
,
$width
=
null
,
$height
=
null
):
string
|
null
{
$width
=
null
,
$height
=
null
):
string
|
null
{
global
$OUTPUT
,
$PAGE
;
global
$OUTPUT
,
$PAGE
;
...
...
This diff is collapsed.
Click to expand it.
tests/replacement_test.php
0 → 100644
+
106
−
0
View file @
e09b654c
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Testcases for the opencast filter.
*
* @package filter_opencast
* @copyright 2024 Justus Dieckmann, University of Münster.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace
filter_opencast
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
global
$CFG
;
require_once
(
$CFG
->
dirroot
.
'/filter/opencast/tests/testable_filter.php'
);
/**
* Testcases for the opencast filter.
*
* @package filter_opencast
* @copyright 2024 Justus Dieckmann, University of Münster.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @group filter_opencast
*/
class
replacement_test
extends
\advanced_testcase
{
public
function
setUp
():
void
{
$this
->
resetAfterTest
();
set_config
(
'episodeurl_1'
,
"http://localhost:8080/play/[EPISODEID]
\n
https://stable.opencast.de/play/[EPISODEID]"
,
'filter_opencast'
);
}
/**
* Actual test function.
*
* @dataProvider replacement_provider
* @covers \filter_opencast
* @param string $input input for filter
* @param string $output expected filter output.
*/
public
function
test_replacement
(
$input
,
$output
)
{
$filter
=
new
testable_filter
(
\context_system
::
instance
(),
[]);
$this
->
assertEquals
(
$output
,
$filter
->
filter
(
$input
));
}
/**
* Provides test cases.
*/
public
function
replacement_provider
()
{
return
[
[
' <p> hello </p> <video src="http://localhost:8080/play/f78ac136-8252-4b8e-bfea-4786c6993f03"> hello </video>'
,
' <p> hello </p> <oc-video episode="f78ac136-8252-4b8e-bfea-4786c6993f03"/>'
],
[
'<video src="https://somethingother.com"></video><video>
<source
src="https://stable.opencast.de/play/370e5bef-1d59-4440-858a-4df62e767dfc">
</video>'
,
'<video src="https://somethingother.com"></video><oc-video episode="370e5bef-1d59-4440-858a-4df62e767dfc"/>'
],
[
'<video
autoplay loopdiloop
src="http://localhost:8080/play/f9e7b289-c8be-462f-80bf-d1f493c6ed55"></video>'
,
'<oc-video episode="f9e7b289-c8be-462f-80bf-d1f493c6ed55"/>'
],
[
'begin <video>
<source src="https://somethingother.de/play/4380f73a-47a6-41c6-b854-ec0fa9d0261b">
<source
src="https://stable.opencast.de/play/2e0ca3bb-df8e-4913-9380-c925efaf5ac2">
</video> end'
,
'begin <oc-video episode="2e0ca3bb-df8e-4913-9380-c925efaf5ac2"/> end'
],
[
'and a link <a href="https://www.google.com">link</a>
<a href="http://localhost:8080/play/09b9d154-c849-429d-adea-3df4f76429b6">look, a video!</a>'
,
'and a link <a href="https://www.google.com">link</a>
<oc-video episode="09b9d154-c849-429d-adea-3df4f76429b6"/>'
],
[
'and now two <a
href="http://localhost:8080/play/64b085e9-0142-4a10-a08e-3dbce055e740">look, a video!</a>
<video src="http://localhost:8080/play/329885fe-d18e-4c6b-a896-dbc66463a6b2"></video>.'
,
'and now two <oc-video episode="64b085e9-0142-4a10-a08e-3dbce055e740"/>
<oc-video episode="329885fe-d18e-4c6b-a896-dbc66463a6b2"/>.'
],
];
}
}
This diff is collapsed.
Click to expand it.
tests/testable_filter.php
0 → 100644
+
55
−
0
View file @
e09b654c
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Testable opencast filter.
*
* @package filter_opencast
* @copyright 2024 Justus Dieckmann, University of Münster.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace
filter_opencast
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
global
$CFG
;
require_once
(
$CFG
->
dirroot
.
'/filter/opencast/filter.php'
);
/**
* Testable opencast filter.
*
* @package filter_opencast
* @copyright 2024 Justus Dieckmann, University of Münster.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class
testable_filter
extends
\filter_opencast
{
/**
* Render a simple
* @param int $ocinstanceid Id of ocinstance.
* @param string $episodeid Id opencast episode.
* @param int $playerid Unique id to assign to player element.
* @param int|null $width Optionally width for player.
* @param int|null $height Optionally height for player.
* @return string|null
*/
protected
function
render_player
(
int
$ocinstanceid
,
string
$episodeid
,
int
$playerid
,
$width
=
null
,
$height
=
null
):
string
|
null
{
return
'<oc-video episode="'
.
$episodeid
.
'"/>'
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment