From 79e06d256a16c2fdc9ae5343d0c2c264136c45ca Mon Sep 17 00:00:00 2001 From: Daniel Thies Date: Mon, 8 May 2023 13:02:15 -0500 Subject: [PATCH] VID-672: Fix VideoJS force settings --- classes/plugininfo/videotimeplugin.php | 8 +- plugin/videojs/lib.php | 11 +- .../videotimeplugin_videojs_settings.feature | 48 +++++++ plugin/videojs/tests/force_settings_test.php | 129 ++++++++++++++++++ .../videotimeplugin_vimeo_settings.feature | 2 +- plugin/vimeo/tests/force_settings_test.php | 4 +- version.php | 4 +- 7 files changed, 196 insertions(+), 10 deletions(-) create mode 100644 plugin/videojs/tests/behat/videotimeplugin_videojs_settings.feature create mode 100644 plugin/videojs/tests/force_settings_test.php diff --git a/classes/plugininfo/videotimeplugin.php b/classes/plugininfo/videotimeplugin.php index c6255a47..24c4b817 100644 --- a/classes/plugininfo/videotimeplugin.php +++ b/classes/plugininfo/videotimeplugin.php @@ -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; } diff --git a/plugin/videojs/lib.php b/plugin/videojs/lib.php index f53668cf..9844be81 100644 --- a/plugin/videojs/lib.php +++ b/plugin/videojs/lib.php @@ -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'])) @@ -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; diff --git a/plugin/videojs/tests/behat/videotimeplugin_videojs_settings.feature b/plugin/videojs/tests/behat/videotimeplugin_videojs_settings.feature new file mode 100644 index 00000000..1b5184eb --- /dev/null +++ b/plugin/videojs/tests/behat/videotimeplugin_videojs_settings.feature @@ -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 diff --git a/plugin/videojs/tests/force_settings_test.php b/plugin/videojs/tests/force_settings_test.php new file mode 100644 index 00000000..4450c997 --- /dev/null +++ b/plugin/videojs/tests/force_settings_test.php @@ -0,0 +1,129 @@ +. + +/** + * Video Time Vimeo force settings test + * + * @package videotimeplugin_videojs + * @copyright 2023 bdecent gmbh + * @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', + ]; + } +} diff --git a/plugin/vimeo/tests/behat/videotimeplugin_vimeo_settings.feature b/plugin/vimeo/tests/behat/videotimeplugin_vimeo_settings.feature index ed037d0d..a15ea06f 100644 --- a/plugin/vimeo/tests/behat/videotimeplugin_vimeo_settings.feature +++ b/plugin/vimeo/tests/behat/videotimeplugin_vimeo_settings.feature @@ -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 | diff --git a/plugin/vimeo/tests/force_settings_test.php b/plugin/vimeo/tests/force_settings_test.php index 36aab99b..e951b36f 100644 --- a/plugin/vimeo/tests/force_settings_test.php +++ b/plugin/vimeo/tests/force_settings_test.php @@ -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 @@ -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())); diff --git a/version.php b/version.php index 02b1c647..c868e29b 100644 --- a/version.php +++ b/version.php @@ -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;