Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Coverage & Refactor #23

Open
5 tasks
ShawnConn opened this issue Nov 17, 2020 · 0 comments
Open
5 tasks

Test Coverage & Refactor #23

ShawnConn opened this issue Nov 17, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@ShawnConn
Copy link
Collaborator

ShawnConn commented Nov 17, 2020

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.

@ShawnConn ShawnConn added the enhancement New feature or request label Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant