Skip to content

Test Coverage & Refactor #23

@ShawnConn

Description

@ShawnConn

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 :
      • 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
    • Write test cases for static methods.
  • 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)
        • getLiltDocument($document_id)
        • getLiltProject($project_id)
        • `getTranslationMemories($trglang = '')``
        • `getServiceRoot()
        • 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)
    • Refactor LiltTranslator & LiltTranslatorUi accordingly
    • Write tests for new methods.
  • Add more FunctionalJS Testing (not comprehensive):
    • Update ./tests.sh in https://github.com/lilt/lilt_drupal_env to accept optional Lilt API key
    • Test Settings Form API Connection
    • Test Settings Change Settings
    • Test Translation Lilt Provider Exists In New Job
    • Test Lilt Provider Job Checkout Options (Due Date/TM/Etc)
    • Test Lilt Provider Job Submission
    • Test Lilt Provider Job Workflow (Approval/Deletion/Abort/Etc)

PS: This should probably be broken up into more bite-sized chunks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions