Knowledge Base / The Appnel Group 

Last Modified
9 January 2007 @ 3pm

MT::Test

NAME

MT::Test - a framework for testing Movable Type plugins.

VERSION

0.11

DESCRIPTION

MT::Test is a framework for testing Movable Type plugins. It is a subclass of Test::Builder::Module from Test::More that adds additional MT specific tests and functionality.

Those familiar with Test::More will be right at home. The one major addition is the ability to test template tag output using one method and half a dozen testing specific template tags.

The framework includes a command tool for running the tests with specific configuration or even with a fresh default database. See the manpage for mtt.

METHODS

  • ok
  • is
  • isnt
  • like
  • unlike
  • cmp_ok
  • diag

    These methods are inherited from Test::More. See the Test::More manpages for more.

  • use_ok
  • require_ok

    These methods are essentially the same found in Test::More however the MT system libraries such as extlib are also considered.

  • run_test_tmpl( $tmpl, [&begin, &end]);

    This method takes a template and performs the embedded tests on its output. These tests are represented using one of the special test operation tags providing by this framework. (See TAGS).

    A string parameter containing the template markup for the test is required. You can optionally pass references a reference to code to run before and after the template test. These methods are useful for initializing the context of doing follow-up test on the final context after a template run.

  • has_plugin($plugin_sig)

    This method will test the MT system for the existence of a specific plugin and will fail if it is not found. A plugin signature string such as 'plugins/feeds/mt-feeds.pl' is required.

  • has_plugin_enabled($plugin_sig)

    This method will test if a specific plugin is enabled in the system. It will fail if it is disabled or not found. A plugin signature string such as 'plugins/feeds/mt-feeds.pl' is required.

TAGS

  • MTTestIs var= stash= val= test_name= blank=1

    This tag tests if the output of its contents matches a specific value. The value to test for can come from a template variable using the var attribute, the stash using the stash attribute or from the tag's val attribute. In order to test if the contents is blank (an empty string) pass a true value to the blank attribute. One and only one of these attributes must be passed.

    Optionally the test_name attribute can be used to pass a string identify the test when run.

  • MTTestIsNot var= stash= val= test_name= blank=1

    This tag tests if the output of its contents does NOT match a specific value. It is the opposite of MTTestIs and takes the same attributes.

  • MTTestCompareOK var= stash= val= test_name= blank=1 op=

    This tag tests if the output of its contents does NOT match a specific value.

    The op attribute is required attribute of and must equal one of Perl's standard string comparison operators:

        eq      equals
        ne      not equal
        lt      less than 
        gt      greater than
        le      less than equal
        ge      greater then or equal

    Using op='eq' is the equivalent of MTTestIs and op='ne' is the equivalent of .

    Optionally the test_name attribute can be used to pass a string identify the test when run.

  • MTTestLike pattern= test_name=

    This tag will test if the contained output matches the regular expression passed in using the required pattern attribute. test_name is optional, but recommend for better feedback.

  • MTTestUnlike pattern= test_name=

    This tag will test if the contained output does not match the regular expression passed in using the required pattern attribute. test_name is optional, but recommend for better feedback.

REQUIREMENTS

MT::Test requires at least Movable Type 3.3 or Movable Type Enterprise 1.02. MT::Test also requires MT::Tool and Test::Simple.

KNOWN ISSUE

I'm not entire statisfied with one common occurance when using run_test_tmpl.

The test count is not incremented properly if a test template has errors or in some cases when a condition causes a test not to run at all. Need to devise a means of skipping X tests if a template has an error or skips any tests. Perhaps run_test_tmpl should be considered a test in and of itself whose result is posted after all other processing?

AUTHOR & COPYRIGHT

MT::Test is Copyright 2006, Appnel Internet Solutions, LLC. http://appnel.com/. All rights reserved.


 

Submit Feedback on This Article

Your comments on how we can improve this article are appreciated. Please do not use the feedback form to submit support requests or question. We will not respond to or publish such queries submitted through this form.

Back to Home