You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The initial 1.x release was written without scope for comprehensive automated testing. If we wanted to fully add coverage for this module, here's how to go about completing that story:
Create 8.x-2.x branch for development.
Refactor references to \Drupal::messenger() & $_SESSION to class properties that can be easily mocked during test setup.
Wrap module functions in Service Class
The functions for .module aren't easily PHPUnit testable since they lean on Drupal's old hook design. We can wrap these functions with method calls to a service class where they can be tested.
Define tmgmt_lilt.hooks(Drupal\tmgmt_lilt\Hooks) in tmgmt_lilt.services.yml
Create static methods that have the same signature as the .module functions then :
Break Lilt API client methods out of LiltTranslator
LiltTranslator is taking on 2 responsibilities of calling Lilt APIs & servicing the TMGMT ops. Break them apart and unit test each chunk of functionality in its own test class.
Define tmgmt_lilt.lilt_api(Drupal\tmgmt_lilt\LiltApi) in tmgmt_lilt.services.yml
Add @config.factory dependency & config property so $this->config->get('tmgmt.translator.lilt')->get('settings'); can be used to retrieve API creds.
Move 17 methods to LiltApi:
archiveLiltProject($project_id)
checkLiltAuth()
createLiltProject(JobInterface $job)
createLiltRemoteFile($xliff, $name, $project_id)
deleteLiltProject($project_id)
getLanguages()
function getLiltAppUrl(TranslatorInterface $translator)
The initial 1.x release was written without scope for comprehensive automated testing. If we wanted to fully add coverage for this module, here's how to go about completing that story:
8.x-2.x
branch for development.\Drupal::messenger()
&$_SESSION
to class properties that can be easily mocked during test setup..module
aren't easily PHPUnit testable since they lean on Drupal's old hook design. We can wrap these functions with method calls to a service class where they can be tested.tmgmt_lilt.hooks
(Drupal\tmgmt_lilt\Hooks
) intmgmt_lilt.services.yml
.module
functions then :tmgmt_lilt_entity_operation(EntityInterface $entity)
->entityOperation
tmgmt_lilt_form_tmgmt_job_abort_form_alter(&$form, $form_state)
->formAlterJobAbort
tmgmt_lilt_form_tmgmt_job_delete_form_alter(&$form, $form_state)
->formAlterJobDelete
tmgmt_lilt_form_tmgmt_job_item_edit_form_alter(&$form, $form_state)
->formAlterJobItemEdit
tmgmt_lilt_form_tmgmt_job_edit_form_alter(&$form, $form_state)
->formAlterJobEdit
tmgmt_lilt_form_views_exposed_form_alter(&$form, $form_state)
->formAlterViewsExposed
tmgmt_lilt_form_tmgmt_job_delete_form_delete_submit(array $form, FormStateInterface $form_state)
->formSubmitJobDelete
tmgmt_lilt_form_tmgmt_job_item_edit_form_accept_submit(array $form, FormStateInterface $form_state)
->formSubmitJobItemEdit
LiltTranslator
LiltTranslator
is taking on 2 responsibilities of calling Lilt APIs & servicing the TMGMT ops. Break them apart and unit test each chunk of functionality in its own test class.tmgmt_lilt.lilt_api
(Drupal\tmgmt_lilt\LiltApi
) intmgmt_lilt.services.yml
@config.factory
dependency &config
property so$this->config->get('tmgmt.translator.lilt')->get('settings');
can be used to retrieve API creds.LiltApi
:archiveLiltProject($project_id)
checkLiltAuth()
createLiltProject(JobInterface $job)
createLiltRemoteFile($xliff, $name, $project_id)
deleteLiltProject($project_id)
getLanguages()
function getLiltAppUrl(TranslatorInterface $translator)
getLiltDocument($document_id)
getLiltProject($project_id)
logApiRequest($method, $url, $request, $response)
request($path, $method = 'GET', array $params = [], $download = FALSE, $code = FALSE, $body = NULL)
sendApiRequest($path, $method = 'GET', array $params = [], $download = FALSE, $code = FALSE, $body = NULL)
sendFiles(JobItemInterface $job_item, $project_id)
setTranslator(TranslatorInterface $translator)
LiltTranslator
&LiltTranslatorUi
accordingly./tests.sh
in https://github.com/lilt/lilt_drupal_env to accept optional Lilt API keyPS: This should probably be broken up into more bite-sized chunks.
The text was updated successfully, but these errors were encountered: