Views: 8057
Last Modified: 22.09.2014

The system permits test modification according to the developer’s requirements using the standard Events mechanism of Bitrix Framework.

If necessary, developers can add their own tests and sections to the Project Quality Control.

Also, the tool can be adapted according to a specific task by creating own sections and tests. For example:

  • SEO optimization tests;
  • CodeStyle test;
  • Test to check the proper operation of billing under load;
  • And others.

How to Expand the Set of Standard Tests

First, own tests and their sections must be described. To do so, we create onCheckListGet, an event handler of the Kernel module. The event is called in the creator CCheckList with the argument $arCheckList of the following type:

array(2) {
  ["CATEGORIES"]=>
  array(10) {
    ["QDESIGN"]=>
    array(0) {
    }
    ["DESIGN"]=>
    array(1) {
      ["PARENT"]=>
      string(7) "QDESIGN"
    }
    ["MODEL"]=>
    array(1) {
      ["PARENT"]=>
      string(7) "QDESIGN"
    }
    ["STANDART"]=>
    array(1) {
      ["PARENT"]=>
      string(7) "QDESIGN"
    }
  }
  ["POINTS"]=>
  array(65) {
    ["QD0010"]=>
    array(2) {
      ["PARENT"]=>
      string(6) "DESIGN"
      ["REQUIRE"]=>
      string(1) "Y"
    }
    ["QD0020"]=>
    array(5) {
      ["REQUIRE"]=>
      string(1) "Y"
      ["PARENT"]=>
      string(6) "DESIGN"
      ["AUTO"]=>
      string(1) "Y"
      ["CLASS_NAME"]=>
      string(10) "CAutoCheck"
      ["METHOD_NAME"]=>
      string(14) "CheckTemplates"
    }
)

As you might have noticed, CATEGORIES contain the list of checklist sections which may be nested, and POINTS contain the tests proper.

The key of the CATEGORIES array is the section ID, and its value is the parameter array:

  • NAME - section name;
  • LINKS;
  • PARENT - parent section.

Example of section description:

$checkList['CATEGORIES']['ITC_QC'] = array(
    'NAME' => 'Corporate Quality Test ITConstruct',
    'LINKS' => ''
);

The key of the POINTS elements is the symbol identifier of the test, and the value is an array of the following parameters:

  • NAME - name of the test;
  • DESC - short description of the test (tab Description, block Description);
  • HOWTO - a text explaining what will be checked (tab Description, block How to perform the test);
  • LINKS - the same as sections;
  • PARENT - section ID, mandatory;
  • REQUIRE - indicator whether the test is mandatory (Y/N);
  • AUTO - "Y" if it is an autotest;
  • CLASS_NAME - test class name (for autotest);
  • METHOD_NAME - test method name (for autotest);
  • FILE_PATH - connection of a test file if such file is made as a separate script (for autotest). Path – from the website root DOCUMENT_ROOT;
  • PARAMS - an array of additional parameters submitted by the first argument when calling the autotest method.
Note: Such keys as NAME, DESC and LINKS can be left undefined in the test description. They depend on language, and if you provide for their strict definition directly in the handler it will make localization impossible.

It will be enough to connect own language file similar to the following:

$MESS["CL_ITC_QC_FAVICON_NAME"] = 'Availability of favicon'; 
$MESS["CL_ITC_QC_FAVICON_DESC"] = 'Check the availability of favicon – a website icon'; 
$MESS["CL_ITC_QC_FAVICON_LINKS"] ='';
Thus these language phrases will be substituted in the test fields NAME, DESC and LINKS with the code ITC_QC_FAVICON. It will also apply to HOWTO, but for now it can be defined only in the point description array.

Example:

$checkList['POINTS']['ITC_QC_FAVICON'] = array(
    'PARENT' => 'ITC_QC',
    'REQUIRE' => 'Y',
    'AUTO' => 'Y',
    'CLASS_NAME' => __CLASS__,
    'METHOD_NAME' => 'checkFavicon',
    'NAME' => 'Availability of favicon',
    'DESC' => 'Check the availability of favicon – a website icon reflected in the tab header and search systems',
    'HOWTO' => 'Home page of the website is checked for availability of the relevant meta tag. 
                If the tag is announced, the availability of icon is checked at the indicated URL. 
                If not, the availability of favicon.ico in the website root is checked',
    'LINKS' => 'links'
);

Event handler can return both changed $arCheckList and a new array with sections and tests. If a category/test with a certain ID already exists, it will not be replaced, i.e. you will not be able to adjust system tests.

Now a method for autotest must be announced:

$check = file_exists($_SERVER['DOCUMENT_ROOT'] . '/favicon.ico')

The check must return an array. Autotest may contain one or more steps. If the test contains several steps and current iteration is not final, the following array must be returned:

$arResult = array(
    'IN_PROGRESS' => 'Y',
    'PERCENT' => '42',
);

PERCENT serves only for the visualization of progress on the page and is not saved in any place for subsequent use. You have to save intermediate data for the identification of a step progress yourself – in a session, temporary file, and base (depending on data volume and other conditions).

If the test is completed, the status shall be notified with an array containing the following keys:

  • STATUS - test result; true if the test is passed, and something other if the test is a fail. It is checked as follows in the code:

    if ($result['STATUS'] == "true")

  • MESSAGE - explanation of the result:
    • PREVIEW - summary of the result;
    • DETAIL - expanded explanation open in a pop-up window.

The ready method of the test for favicon.ico availability is as follows:

static public function checkFavicon($arParams)
{
    $arResult = array('STATUS' => 'F');
    $check = file_exists($_SERVER['DOCUMENT_ROOT'] . '/favicon.ico');

    if ($check === true) {
        $arResult = array(
            'STATUS' => true,
            'MESSAGE' => array(
                'PREVIEW' => 'Favicon is found - ' . '/favicon.ico',
            ),
        );
    } else {
        $arResult = array(
            'STATUS' => false,
            'MESSAGE' => array(
                'PREVIEW' => 'Favicon is not found',
                'DETAIL' => 'Failed to find favicon.ico',
            ),
        );
    }

    return $arResult;
}

Result

Test in the Project Quality Control:

Reference information about test:

Code

Code of the handler and entire tests:

AddEventHandler('main', 'OnCheckListGet', array('CItcCheckListTests', 'onCheckListGet'));

class CItcCheckListTests
{
    static public function onCheckListGet($arCheckList)
    {
        $checkList = array('CATEGORIES' => array(), 'POINTS' => array());

        $checkList['CATEGORIES']['ITC_QC'] = array(
            'NAME' => 'Corporate Quality Test ITConstruct',
            'LINKS' => ''
        );

        $checkList['POINTS']['ITC_QC_FAVICON'] = array(
            'PARENT' => 'ITC_QC',
            'REQUIRE' => 'Y',
            'AUTO' => 'Y',
            'CLASS_NAME' => __CLASS__,
            'METHOD_NAME' => 'checkFavicon',
            'NAME' => 'Availability of favicon',
            'DESC' => 'Check the availability of favicon – a website icon reflected in the tab header and search systems',
            'HOWTO' => 'Home page of the website is checked for availability of the relevant meta tag. 
If the tag is announced, the availability of icon is checked at the indicated URL.
If not, the availability of favicon.ico in the website root is checked', 'LINKS' => 'links' ); $checkList['POINTS']['ITC_QC_DENY_DEV'] = array( 'PARENT' => 'ITC_QC', 'REQUIRE' => 'N', 'AUTO' => 'N', 'NAME' => 'Closing external access to dev server', 'DESC' => 'Agree with the manager on closing access to internal server from the outside world', 'HOWTO' => 'Ping from telephone after DNS update', ); return $checkList; } static public function checkFavicon($arParams) { $arResult = array('STATUS' => 'F'); $check = file_exists($_SERVER['DOCUMENT_ROOT'] . '/favicon.ico'); if ($check === true) { $arResult = array( 'STATUS' => true, 'MESSAGE' => array( 'PREVIEW' => 'Favicon is found - ' . '/favicon.ico', ), ); } else { $arResult = array( 'STATUS' => false, 'MESSAGE' => array( 'PREVIEW' => 'Favicon is not found', 'DETAIL' => 'Failed to find favicon.ico', ), ); } return $arResult; } }


Courses developed by Bitrix24