Skip to content

Commit

Permalink
VID-672: Fix VideoJS force settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dthies committed May 8, 2023
1 parent d76d19a commit 79e06d2
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 10 deletions.
8 changes: 4 additions & 4 deletions classes/plugininfo/videotimeplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public function available_updates() {
case 'pro':
$info = array(
'maturity' => MATURITY_STABLE,
'release' => '1.7',
'version' => 2023011201,
'release' => '1.7.1',
'version' => 2023011202,
);
break;
case 'repository':
$info = array(
'maturity' => MATURITY_STABLE,
'release' => '1.7',
'version' => 2023011200,
'release' => '1.7.1',
'version' => 2023011202,
);
break;
}
Expand Down
11 changes: 10 additions & 1 deletion plugin/videojs/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ function videotimeplugin_videojs_load_settings($instance) {
}

$instance = (array) $instance;
if (get_config('videotimeplugin_videojs', 'forced')) {
$forced = array_intersect_key(
(array) get_config('videotimeplugin_videojs'),
array_fill_keys(explode(',', get_config('videotimeplugin_videojs', 'forced')), true)
);
} else {
$forced = [];
}

if (
!mod_videotime_get_vimeo_id_from_link($instance['vimeo_url'])
&& $record = $DB->get_record('videotimeplugin_videojs', array('videotime' => $instance['id']))
Expand Down Expand Up @@ -148,7 +157,7 @@ function videotimeplugin_videojs_load_settings($instance) {
}
}

return ((array) $record) + ((array) $instance);
return $forced + (array) $record + (array) $instance;
}

return (array) get_config('videotimeplugin_videojs') + (array) $instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@mod @mod_videotime @videotimeplugin_videojs
Feature: Configure videojs settings
In use a video assignment I need to control settings
As an admin
I need to adjust player options

Background:
Given the following "courses" exist:
| shortname | fullname |
| C1 | Course 1 |
And the following "users" exist:
| username | firstname |
| teacher | Teacher |
| student | Student |
And the following "course enrolments" exist:
| user | course | role |
| teacher | C1 | editingteacher |
| student | C1 | student |
And the following "activities" exist:
| activity | name | course | vimeo_url | label_mode | section | controls |
| videotime | Video Time with controls | C1 | https://www.youtube.com/watch?v=dQw4w9WgXcQ | 0 | 1 | 1 |
| videotime | Video Time with no controls | C1 | https://www.youtube.com/watch?v=dQw4w9WgXcQ | 0 | 1 | 0 |

@javascript
Scenario: Force control setting on
Given the following config values are set as admin:
| forced | controls | videotimeplugin_videojs |
| controls | 1 | videotimeplugin_videojs |
When I am on the "Video Time with no controls" "mod_videotime > Embed options" page logged in as "teacher"
Then I should see "Controls is globally forced to: Yes"

@javascript
Scenario: Force control setting off on embed settings page
Given the following config values are set as admin:
| forced | controls | videotimeplugin_videojs |
| controls | 0 | videotimeplugin_videojs |
When I am on the "Video Time with no controls" "mod_videotime > Embed options" page logged in as "teacher"
Then I should see "Controls is globally forced to: No"

@javascript
Scenario: Force control setting off on activity page
Given the following config values are set as admin:
| forced | controls | videotimeplugin_videojs |
| controls | 0 | videotimeplugin_videojs |
When I am on the "Video Time with controls" "videotime activity" page logged in as "teacher"
And I wait "3" seconds
And I switch to "" class iframe
Then "Play" "button" should not be visible
129 changes: 129 additions & 0 deletions plugin/videojs/tests/force_settings_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?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/>.

/**
* Video Time Vimeo force settings test
*
* @package videotimeplugin_videojs
* @copyright 2023 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace videotimeplugin_videojs;

use advanced_testcase;
use mod_videotime\videotime_instance;

/**
* Class force_settings_test
*
* @group videotimeplugin_videojs
* @covers \mod_videotime\videotime_instance
*/
class force_settings_test extends advanced_testcase {

/**
* @var stdClass $course
*/
private $course;
/**
* @var stdClass $instancerecord
*/
private $instancerecord;

/**
* @var videotime_instance
*/
private $videotimeinstance;

/**
* Set up
*/
public function setUp() : void {
$this->resetAfterTest();

$this->course = $this->getDataGenerator()->create_course();
$this->instancerecord = $this->getDataGenerator()->create_module('videotime', [
'course' => $this->course->id,
'controls' => 0,
'vimeo_url' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
]);
$this->videotimeinstance = videotime_instance::instance_by_id($this->instancerecord->id);
}

/**
* Tear down data
*/
public function tearDown() : void {
$this->course = null;
$this->instancerecord = null;
$this->videotimeinstance = null;
}

/**
* Force setting test
*/
public function test_disable_options() {
$this->assertIsArray($this->videotimeinstance->get_force_settings());
$this->assertFalse(in_array(1, $this->videotimeinstance->get_force_settings()));

set_config('enabled', 1, 'videotimeplugin_videojs');
foreach ($this->get_options() as $option) {
set_config($option, 0, 'videotimeplugin_videojs');
set_config('forced', $option, 'videotimeplugin_videojs');

$this->videotimeinstance = videotime_instance::instance_by_id($this->instancerecord->id);

$this->assertNotEmpty($this->videotimeinstance->to_record());
$this->assertEquals(0, $this->videotimeinstance->to_record()->$option);
}
}

/**
* Force setting test
*/
public function test_enable_controls() {
$this->assertIsArray($this->videotimeinstance->get_force_settings());
$this->assertFalse(in_array(1, $this->videotimeinstance->get_force_settings()));

set_config('enabled', 1, 'videotimeplugin_videojs');
foreach ($this->get_options() as $option) {
set_config($option, 1, 'videotimeplugin_videojs');
set_config('forced', $option, 'videotimeplugin_videojs');

$this->videotimeinstance = videotime_instance::instance_by_id($this->instancerecord->id);

$this->assertNotEmpty($this->videotimeinstance->to_record());
$this->assertEquals(1, $this->videotimeinstance->to_record()->$option);
}
}

/**
* Get supported options
*
* @return array
*/
public function get_options() {
return [
'autoplay',
'controls',
'muted',
'option_loop',
'playsinline',
'responsive',
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Feature: Configure vimeo settings
Then "Play" "button" should be visible

@javascript
Scenario: Controls are available
Scenario: Controls are unavailable
When I am on the "Video Time with no controls" "mod_videotime > Embed options" page logged in as "teacher"
And I set the following fields to these values:
| controls | 0 |
Expand Down
4 changes: 2 additions & 2 deletions plugin/vimeo/tests/force_settings_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use mod_videotime\videotime_instance;

/**
* Class videotime_instance_test
* Class fore_settings_test
*
* @group videotimeplugin_vimeo
* @covers \mod_videotime\videotime_instance
Expand Down Expand Up @@ -95,7 +95,7 @@ public function test_disable_options() {
/**
* Force setting test
*/
public function test_enable_controls() {
public function test_enable_options() {
$this->assertIsArray($this->videotimeinstance->get_force_settings());
$this->assertFalse(in_array(1, $this->videotimeinstance->get_force_settings()));

Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'mod_videotime';
$plugin->release = '1.7.1';
$plugin->version = 2023011205;
$plugin->release = '1.7.2';
$plugin->version = 2023011206;
$plugin->incompatible = 402;
$plugin->requires = 2015111610;
$plugin->maturity = MATURITY_STABLE;

0 comments on commit 79e06d2

Please sign in to comment.