How to write phpUnit tests for hook_form_alter?

by Sugandh Khanna   Last Updated November 14, 2017 08:07 AM

I have 1 function that is returning cancel form button. This function is in my .module file.

function _cancel_button(array &$form, FormStateInterface &$form_state) {
  // Adding buttons to cancel form.
  $form['actions']['cancel'] = [
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#access' => TRUE,
    '#submit' => ['redirectcallback'],
    '#limit_validation_errors' => [],
  ];
  return $form;
}

How to write PHPUnit test for this function? Is is possible to write a test for a function which is not enclosed in any class or don't have any namespace?

Tags : 8 testing


Related Questions


Unit testing on windows

Updated July 09, 2015 13:03 PM

Functional testing without using simpletest

Updated June 19, 2015 01:03 AM


How to tell travis that test is failed?

Updated July 31, 2015 14:56 PM