Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-11497

Unit tests for extensions broken (due to invalid domain_id FK)

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.3.0
    • Fix Version/s: 4.4.0
    • Component/s: Test suite
    • Labels:
      None

      Description

      Since unit-testing is such a great thing, extension authors need to be able to write tests for extensions. See CRM-10922 for previous work on this.

      There's a basic difficulty in testing extensions because they are configurable and come with a bit of automated setup – and because our unit-tests run on a separate database/site. One approach (taken by Drupal) is to require the developer to first install the extension on his site (which will create tables, etc) – and then run the tests against that database. That approach doesn't work for us because we run unit-tests in a separate, isolated database – and the content of that database is frequently dropped/created.

      The approach taken in CRM-10922 is to automatically install the extension before executing any unit-tests. So, if a developer a runs "civix test CRM_Myextension_MyTest", then it uses the API (Extension.install) to automatically setup the extension in the test database and then runs the tests. (Another way to think of what's going on: civix scans the real CiviCRM database for a list of active extensions, and it then installs them cleanly on the test database.)

      At some point, running Extension.install before tests regressed. The problem is that Extension.install winds up calling CRM_Core_Menu::store() which builds the menu and includes these lines:

      $menu->domain_id = CRM_Core_Config::domainID();
      ...
      $menu->save();

      Apparently, that produces $menu items with an invalid domain_id. I don't understand how domains/tests interact well enough to think of a fix.

      One should be able to replicate by performing the following steps:
      1. Install CiviCRM from trunk and setup unit-testing
      2. Install civix, link it to the CiviCRM instance (per README), create a module-extension, and install it.
      3. cd /path/to/my/module/extension
      4. civix generate:test CRM_Myextension_MyTest
      5. civix test CRM_Myextension_MyTest

        Attachments

          Activity

            People

            • Assignee:
              timotten Tim Otten
              Reporter:
              timotten Tim Otten
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: