Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-73669

Allow to create multiple behat_*_deprecated files, one in each component or plugin

XMLWordPrintable

    • MOODLE_400_STABLE
    • MOODLE_400_STABLE
    • MDL-73669-master
    • Hide
      1. Modify file lib/tests/behat/behat_deprecated.php and add a function:

            /**
             * @When /^I like apples$/
             */
            public function i_like_apples() {
                $this->deprecated_message('Try oranges instead');
            }
        

      2. Take any existing scenario (in the *.feature) file and add a line "When I like apples"
      3. Run this scenario in behat, make sure the test failed and you see deprecation message
      4. Add $CFG->behat_usedeprecated=1; to your config.php
      5. Run the same scenario and make sure it passes now
      6. As admin go to Site administration>Development>Acceptance testing
      7. Make sure the "I like apples" step is not listed there
      8. Don't forget to remove behat_usedeprecated from config.php

      Test 2 plugins

      1. Create a file mod/forum/tests/behat/behat_mod_forum_deprecated.php with the contents:

        <?php
        require_once(__DIR__ . '/../../../../lib/behat/behat_deprecated_base.php');
        class behat_mod_forum_deprecated extends behat_deprecated_base {
            /**
             * @When /^I see stars$/
             */
            public function i_see_stars() {
                $this->deprecated_message('Go to sleep');
            }
        }
        

      2. Take any existing scenario (in the *.feature) file and add a line "When I see stars"
      3. Run this scenario in behat, make sure the test failed and you see deprecation message
      4. Add $CFG->behat_usedeprecated=1; to your config.php
      5. Run the same scenario and make sure it passes now
      6. As admin go to Site administration>Development>Acceptance testing
      7. Make sure the "I see stars" step is not listed there
      8. Don't forget to remove behat_usedeprecated from config.php
      Show
      Modify file lib/tests/behat/behat_deprecated.php and add a function: /** * @When /^I like apples$/ */ public function i_like_apples() { $this->deprecated_message('Try oranges instead'); } Take any existing scenario (in the *.feature) file and add a line "When I like apples" Run this scenario in behat, make sure the test failed and you see deprecation message Add $CFG->behat_usedeprecated=1; to your config.php Run the same scenario and make sure it passes now As admin go to Site administration>Development>Acceptance testing Make sure the "I like apples" step is not listed there Don't forget to remove behat_usedeprecated from config.php Test 2 plugins Create a file mod/forum/tests/behat/behat_mod_forum_deprecated.php with the contents: <?php require_once(__DIR__ . '/../../../../lib/behat/behat_deprecated_base.php'); class behat_mod_forum_deprecated extends behat_deprecated_base { /** * @When /^I see stars$/ */ public function i_see_stars() { $this->deprecated_message('Go to sleep'); } } Take any existing scenario (in the *.feature) file and add a line "When I see stars" Run this scenario in behat, make sure the test failed and you see deprecation message Add $CFG->behat_usedeprecated=1; to your config.php Run the same scenario and make sure it passes now As admin go to Site administration>Development>Acceptance testing Make sure the "I see stars" step is not listed there Don't forget to remove behat_usedeprecated from config.php

      In 3.11 we deprecated some behat steps in our plugins by creating files:

      admin/tool/wp/tests/behat/behat_tool_wp_deprecated.php

      class behat_tool_wp_deprecated extends behat_deprecated {
          /**
           * Click on the form button in the modal form.
           *
           * @When /^I press "(?P<button_string>(?:[^"]|\\")*)" in the modal form dialogue$/
           * @param string $buttontext
           *
           * @deprecated Since 3.11. Please use {@see behat_general::i_click_on_in_the}
           */
          public function i_press_in_the_modal_form_dialogue($buttontext) {
              $this->deprecated_message(
                  'Use instead: And I click on "BUTTONNAME "button" in the "DIALOGUENAME" "dialogue"');
       
              // I click on "Save changes" "button" in the ".modal.show .modal-footer" "css_element" .
              $this->execute('behat_general::i_click_on_in_the', [$this->escape($buttontext), 'button',
                  '.modal.show .modal-footer', 'css_element']);
          }
       
      }
      

      The similar deprecation would be in other plugins, for example

      admin/tool/certification/tests/behat/behat_tool_certification_deprecated.php

      class behat_tool_certification_deprecated extends behat_deprecated {
          // ...
      }
      

      This worked fine until we upgraded to 4.0

      Now every step throws an exception:

      005 Scenario: Testing workplace launcher in list format # /var/www/html/theme/workplace/tests/behat/steps.feature:13
            And I log out                                     # /var/www/html/theme/workplace/tests/behat/steps.feature:19
              Step "/^I select "(?P<link_string>(?:[^"]|\\")*)" from flat navigation drawer$/" is already defined in behat_tool_certification_deprecated::i_select_from_flat_navigation_drawer()
              
              behat_tool_certification_deprecated::i_select_from_flat_navigation_drawer()
              behat_tool_wp_deprecated::i_select_from_flat_navigation_drawer()
      

      Neither behat_tool_certification_deprecated nor behat_tool_wp_deprecated contain this step, it is defined in behat_deprecated.

      I am not sure what changed in 4.0 so it no longer works. These classes can not extend behat_base because the function

      $this->deprecated_message(...);
      

      will not be available there.

      Edit: this is not a new problem in 4.0, we only hit it now because there were no deprecated steps in behat_deprecated.php (in core) in 3.11 . So we were probably doing it incorrect anyway but the question remains - what is the recommended way to deprecate steps in PLUGINS

        1. MDL-73669_test 2_1.png
          159 kB
          Angelia Dela Cruz
        2. MDL-73669_test 2_2.png
          141 kB
          Angelia Dela Cruz
        3. MDL-73669_testing_1.png
          154 kB
          Angelia Dela Cruz
        4. MDL-73669_testing_2.png
          134 kB
          Angelia Dela Cruz

            marina Marina Glancy
            marina Marina Glancy
            Paul Holden Paul Holden
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Angelia Dela Cruz Angelia Dela Cruz
            Votes:
            2 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours, 40 minutes
                4h 40m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.