Skip to content

Created TranslateTextTest class.

spec0 requested to merge issue/ai-3488374:3488374-create-unit-test into 1.0.x

Closes #3488374

The provided Drupal unit test, TranslateTextTest, focuses on testing the functionality of two classes: TranslateTextInput and TranslateTextOutput. These classes are part of a module named ai, specifically within the OperationType\TranslateText namespace. The tests ensure that these classes can be properly created with valid input data and that their methods return expected results.

Here's a summary of each test case:

  1. Test Case: testTranslateTextInputCreation

    • Purpose: This test verifies that an instance of TranslateTextInput is created correctly.
    • Input: A string 'Hello, world!', source language 'en', and target language 'es'.
    • Expected Output:
      • The toString() and (string) methods should return the original text `'Hello, world!'.
      • The getSourceLanguage() method should return the source language 'en'.
      • The getTargetLanguage() method should return the target language 'es'.
    • Additional Test: The test also checks that the source and target languages can be updated using the setSourceLanguage and setTargetLanguage methods.
  2. Test Case: testTranslateTextOutputCreation

    • Purpose: This test verifies that an instance of TranslateTextOutput is created correctly.
    • Input:
      • A normalized string '¡Hola, mundo!', a raw output array containing the translated text, and metadata with a confidence level.
    • Expected Output:
      • The getNormalized() method should return the normalized text `'¡Hola, mundo!'.
      • The getRawOutput() method should return the raw output array.
      • The getMetadata() method should return the metadata.
    • Additional Test: The test also checks that the output can be converted to an associative array using the toArray method.

Summary

  • The tests ensure that both TranslateTextInput and TranslateTextOutput classes handle their properties and methods as expected.
  • They verify the proper creation of instances with correct data.
  • Additional tests check for mutability of source/target languages in the input class and conversion to array format in the output class.

Merge request reports

Loading