SimpleTest is Drupal's custom testing framework and allows module's code, functionalities and features to be tested automatically from code.

Adding Test Cases to the module would also allow preparing for an upcoming stable version by testing automatically from code as many features of the module as possible.

In terms of code organization, as it is suggested at Organizing your test cases, it seems to be recommended to group in a base/utility Test Case class commonly used properties, setup or methods, and other test case classes could extend this common base class.
This would allow breaking into separate test cases the tests.

Test Cases:

  • Test Page Visibility, 403/404 and DNT configuration settings.
  • Test Baidu Analytics Tracker Code (BATC) generation and page inclusion in different scopes.
  • Test Baidu Analytics Custom Variables configuration and implemented tokens replacements.
  • Test Baidu Analytics configuration for different Roles.

Although we would be adding more tests, none of these changes or updates would add any new feature or functionnality to the module, however, it would certainly improve its code organization, readability, maintainability as well as its possibility to be further extended in the future.

Please let me know if you would have any questions, objections, comments, suggestions, recommendations or concerns on any aspects of feature request, I would be glad to provide more information or explain in more details.

Any questions, feedback, testing, changes, ideas or recommendations would be highly appreciated.
Thanks to all in advance.

Comments

dydave’s picture

Status: Active » Fixed

Quick follow-up on this feature request:

Added an initial round of Test Cases with the file baidu_analytics.test:

  • Added a common base/utility class called BaiduAnalyticsTestCase (extending DrupalWebTestCase) which now groups the setup method with module inclusion and the $baCode property to store the Baidu Analytics Web Property ID used for the tests.
  • Added Test Case BaiduAnalyticsBasicTest which performs two major series of tests:
    • testBaiduAnalyticsPageVisibility to test Page Visibility, 403/404 and DNT configuration settings: The admin page and sub-pages are excluded path, vibility of the code on a 403/404 page and DNT headers set or unset.
    • testBaiduAnalyticsTrackingCode to test Baidu Analytics Tracker Code (BATC) generation and page inclusion in different scopes: Check the correct JavaScript code with the configured Web Property ID is found in the right location of the page whether the scope is set to default, header or footer
  • Added Test Case BaiduAnalyticsCustomVariablesTest to test Baidu Analytics Custom Variables configuration and implemented tokens replacements: Check the generated JavaScript code contains configured Custom Variables, empty values should not display and tokens implemented by the Baidu Analytics module current-user:baidu_analytics:role-names and current-user:baidu_analytics:role-ids should be property replaced.
  • Added Test Case BaiduAnalyticsRolesTest to test Baidu Analytics configuration for different Roles: Check the option to selectively include or exclude certain roles, in particular check for the Anonymous and Authenticated roles if the tracking JavaScript code would display in different configurations.
  • All test case classes now extend common BaiduAnalyticsTestCase base class.
  • Added initial round of Doc comment blocks and inline comments.

Modified the baidu_analytics.info file to declare test file and a Test Dependency required by the Drupal.org Testbots to include the Token module, included by the test case BaiduAnalyticsCustomVariablesTest for checking tokens replacements in Custom Variables.
The getInfo method was also modified to add the dependencies property key to declare inclusion of the Token module (external contributed module required by the Test Case).

I went ahead and committed the changes against the 7.x-1.x branch at 6357889.

I allowed myself to mark this issue as fixed for now, but feel free to re-open it, or post a new ticket, at any time if you have any further objections with this issue or related commit 6357889 (we would surely be happy to hear your feedback).

Please let me know if you would have any further comments, feedback, questions, issues, objections, suggestions or concerns on the commit or this feature request in general, I would be glad to provide more information or explain in more details.

Thanks in advance to everyone for your testing, reviews, feedback and comments on this issue.
Cheers!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.