private function RestfulViewEntityMultiLingualTestCase::assertExpectedResult in RESTful 7.2
Same name and namespace in other branches
- 7 tests/RestfulViewEntityMultiLingualTestCase.test \RestfulViewEntityMultiLingualTestCase::assertExpectedResult()
Helper to test viewing an entity (GET method) in a certain language.
Parameters
string $langcode: The language to view the entity in.
int $id: The ID of the entity to test.
string $text1: The first expected string (text_single and text_multiple[0]).
string $text2: The second expected string (text_multiple[2]).
1 call to RestfulViewEntityMultiLingualTestCase::assertExpectedResult()
- RestfulViewEntityMultiLingualTestCase::testViewMultiLangualEntity in tests/
RestfulViewEntityMultiLingualTestCase.test - Test viewing an entity with translatable fields.
File
- tests/
RestfulViewEntityMultiLingualTestCase.test, line 145 - Contains RestfulViewEntityMultiLingualTestCase
Class
Code
private function assertExpectedResult($langcode, $id, $text1, $text2) {
$resource_manager = restful()
->getResourceManager();
$handler = $resource_manager
->getPlugin('restful_test_translatable_entity:1.0');
// Explicitly set the langcode.
$handler
->getDataProvider()
->setLangCode($langcode);
$handler
->setRequest(Request::create('api/restful_test_translatable_entity/' . $id));
$handler
->setPath($id);
$response = drupal_json_decode(restful()
->getFormatterManager()
->format($handler
->process(), 'json'));
$response = $response['data'];
$result = $response[0];
$this
->assertEqual(trim(strip_tags($result['text_single'])), $text1, 'Entity view has correct result for "text_single" in language "' . $langcode . '".');
$this
->assertEqual(trim(strip_tags($result['text_multiple'][0])), $text1, 'Entity view has correct result for the first value of "text_multiple" in language "' . $langcode . '".');
$this
->assertEqual(trim(strip_tags($result['text_multiple'][1])), $text2, 'Entity view has correct result for the second value of "text_multiple" in language "' . $langcode . '".');
}