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

Impossible to test externallibs (still occurs in phpunit tests)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Minor Minor
    • None
    • 2.0.3
    • Web Services
    • MOODLE_20_STABLE
    • Hide

      Write a simpletest for any external method that needs a $context->contextlevel >= CONTEXT_COURSE and execute it.

      Show
      Write a simpletest for any external method that needs a $context->contextlevel >= CONTEXT_COURSE and execute it.

      I was trying to write some simpletests to verify the correctness of our Moodbile Web Services when I realised that it was impossible.

      External_api::validate_context method calls require_login function, which modifies $PAGE when "Unit Testing" page printing has already started. So I get this error:

      Exception: local/moodbileserver/mod/forum/simpletest/testforumexternal.php / ▶ forumexternal_test / ▶ test_get_forum_by_id
      Unexpected exception of type [coding_exception] with message [Coding error detected, it must be fixed by a programmer: The theme has already been set up for this page ready for output. Therefore, you can no longer change the theme, or anything that might affect what the current theme is, for example, the course.] in [/Users/jpiguillem/DFWikiLABS/projectes/Moodbile20/lib/pagelib.php line 1508]
       
      Debug info:
       
      Stack trace when the theme was set up: 
       
          line 1244 of /lib/setuplib.php: call to moodle_page->initialise_theme_and_output()
          line ? of unknownfile: call to bootstrap_renderer->__call()
          line 5664 of /lib/adminlib.php: call to bootstrap_renderer->single_button()
          line 30 of /admin/report/unittest/index.php: call to admin_externalpage_setup()
       
          line 727 of /lib/pagelib.php: call to moodle_page->ensure_theme_not_set()
          line 799 of /lib/pagelib.php: call to moodle_page->set_course()
          line 2347 of /lib/moodlelib.php: call to moodle_page->set_cm()
          line 314 of /lib/externallib.php: call to require_login()
          line 52 of /local/moodbileserver/mod/forum/externallib.php: call to external_api::validate_context()
          line 74 of /local/moodbileserver/mod/forum/simpletest/testforumexternal.php: call to moodbileserver_forum_external::get_forum_by_id()
          line ... of ...
       

      Can it be considered a bug? An specific require_login function for Web Services might be implemented? I've seen that you haven't write any simpletest for externals, but you have written tests for SOAP, XML-RPC, etc.

            Unassigned Unassigned
            pigui Jordi Piguillem Poch (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

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