Created TranslateTextTest class.
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:
-
Test Case:
testTranslateTextInputCreation-
Purpose: This test verifies that an instance of
TranslateTextInputis 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'.
- The
-
Additional Test: The test also checks that the source and target languages can be updated using the
setSourceLanguageandsetTargetLanguagemethods.
-
Purpose: This test verifies that an instance of
-
Test Case:
testTranslateTextOutputCreation-
Purpose: This test verifies that an instance of
TranslateTextOutputis created correctly. -
Input:
- A normalized string
'¡Hola, mundo!', a raw output array containing the translated text, and metadata with a confidence level.
- A normalized string
-
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.
- The
-
Additional Test: The test also checks that the output can be converted to an associative array using the
toArraymethod.
-
Purpose: This test verifies that an instance of
Summary
- The tests ensure that both
TranslateTextInputandTranslateTextOutputclasses 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.