I created a custom step definition similar to the one suggested above for Moodle 2.6. I'll include the details below, but so as not to bury the headline, my custom step definition works nicely in 2.6 but is not working in 2.7 or 2.8. I've tried lots of variations and get a variety of errors (which I will explain) but no success.
This is the original custom step definition that works well for Moodle 2.6. It's in a file at /filter/videojs/tests/behat/behat_filter_videojs.php
<?php
class behat_filter_videojs extends behat_base {
/**
* Sets the contents of a field with multi-line input.
*
* @Given /^I set the field "(?P<field_string>(?:[^"]|\\")*)" to:$/
*/
public function i_set_the_field_to_pystring($fieldlocator, Behat\Gherkin\Node\PyStringNode $value) {
$field = behat_field_manager::get_form_field_from_label($fieldlocator, $this);
$field->set_value($value->getRaw());
}
}
I invoke that step in a feature file at /filter/videojs/tests/behat/single_video.feature that looks like this. There are other scenarios than the one here, but this shows the idea:
@filter @filter_videojs
Feature: Simple HTML5 video embed
In order to embed an HTML5 video
As a user
I need to use a videojs shortcode with an mp4 and webm (or ogv) file
Background:
Given the following "courses" exist:
| fullname | shortname |
| VideoJS | videojs |
And the following "users" exist:
| username |
| tester |
And the following "course enrolments" exist:
| user | course | role |
| tester | videojs | editingteacher |
And the following "activities" exist:
| activity | course | idnumber | name | intro |
| page | videojs | videojspage | VideoJS Page | for testing |
And I log in as "admin"
And I expand "Site administration" node
And I navigate to "Manage filters" node in "Site administration>Plugins>Filters"
And I click on "On" "option" in the "Video.js" "table_row"
And I log out
And I log in as "tester"
And I follow "VideoJS"
@javascript
Scenario: Embed a single HTML5 video on a Page resource
Given I click on "VideoJS Page" "link" in the "VideoJS Page" activity
And I navigate to "Edit settings" node in "Page module administration"
And I set the field "Page content" to:
"""
Hello!
[videojs]
mp4="../../filter/videojs/tests/fixtures/activity-and-resource-controls.mp4"
webm="../../filter/videojs/tests/fixtures/activity-and-resource-controls.webm"
[/videojs]
"""
When I click on "Save and display" "button"
And I wait until the page is ready
Then ".video-js" "css_element" should exist
In Moodle 2.6 all is well, but in Moodles 2.7 and 2.8 my pystring step returns red with this message:
unterminated string literal
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: <some system info suppressed> os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.7.0_51'
Driver info: driver.version: unknown
These Moodle installations are all running in the same local environment.
I have tried using the custom step definition offered above (removing one of two spaces after the word 'field' in the doc block @Given line, and making appropriate adjustments to my feature file). In that case I get this error:
Coding error detected, it must be fixed by a programmer: The "set_field_value" method does not exist
This is understandable because my class extends behat_base rather than behat_forms. If I try to extend behat_forms I get:
Fatal error: Class 'behat_forms' not found
And if I try to include lib/tests/behat/behat_forms.php I get redundancy errors for having identical tests.
Do you have any idea what I can do to get my pystring step to work in 2.7 and 2.8?