-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7339 from ProcessMaker/task/FOUR-18756
FOUR-18756: Create tests for the current screen translations
- Loading branch information
Showing
2 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Api; | ||
|
||
use Illuminate\Http\UploadedFile; | ||
use Illuminate\Support\Facades\Storage; | ||
use ProcessMaker\Facades\WorkflowManager; | ||
use ProcessMaker\Jobs\ImportV2; | ||
use ProcessMaker\Models\Process; | ||
use ProcessMaker\Models\ProcessRequestToken; | ||
use ProcessMaker\Models\User; | ||
use Tests\Feature\Shared\RequestHelper; | ||
use Tests\TestCase; | ||
|
||
|
||
class TranslationTest extends TestCase | ||
{ | ||
use RequestHelper; | ||
|
||
public function testTranslationWithDefaultLanguage() | ||
{ | ||
$defaultAdminUser = User::factory()->create(['is_administrator' => true]); | ||
$portugueseUser = User::factory()->create(['is_administrator' => true, 'language' => 'pt']); | ||
$spanishUser = User::factory()->create(['is_administrator' => true, 'language' => 'es']); | ||
|
||
$this->user = $defaultAdminUser; | ||
|
||
$fileName = __DIR__ . '/../../Fixtures/translation_test.json'; | ||
$file = new UploadedFile($fileName, 'translation_test.json', null, null, true); | ||
Storage::putFileAs('import', $file, 'payload.json'); | ||
Storage::put('import/options.json', '{}'); | ||
$hash = md5_file(Storage::path(ImportV2::FILE_PATH)); | ||
ImportV2::dispatchSync($this->user->id, null, $hash, false); | ||
|
||
$process = Process::orderBy('id', 'desc')->first(); | ||
|
||
WorkflowManager::triggerStartEvent( | ||
$process, | ||
$process->getDefinitions()->getEvent('node_1'), | ||
[] | ||
); | ||
|
||
$task = ProcessRequestToken::orderBy('id', 'desc')->first(); | ||
|
||
// The first task should be created | ||
$this->assertNotEmpty($task); | ||
|
||
$url = route('api.tasks.show', [$task->id]); | ||
$response = $this->apiCall('GET', "$url?include=screen"); | ||
$response->assertStatus(200); | ||
|
||
$responseData = $response->json(); | ||
$items = collect($responseData['screen']['config'][0]['items']); | ||
$firstNameItem = $items->firstWhere('config.name', 'first_name'); | ||
$lastNameItem = $items->firstWhere('config.name', 'last_name'); | ||
$ageItem = $items->firstWhere('config.name', 'age'); | ||
|
||
$this->assertEquals('First Name', $firstNameItem['config']['label']); | ||
$this->assertEquals('Last Name', $lastNameItem['config']['label']); | ||
$this->assertEquals('Age', $ageItem['config']['label']); | ||
|
||
|
||
// As portuguese is not translated, english must be used | ||
$this->user = $portugueseUser; | ||
$response = $this->apiCall('GET', "$url?include=screen"); | ||
$responseData = $response->json(); | ||
$items = collect($responseData['screen']['config'][0]['items']); | ||
$firstNameItem = $items->firstWhere('config.name', 'first_name'); | ||
$lastNameItem = $items->firstWhere('config.name', 'last_name'); | ||
$ageItem = $items->firstWhere('config.name', 'age'); | ||
|
||
$this->assertEquals('First Name', $firstNameItem['config']['label']); | ||
$this->assertEquals('Last Name', $lastNameItem['config']['label']); | ||
$this->assertEquals('Age', $ageItem['config']['label']); | ||
|
||
|
||
// Spanish has translation, so it should be used for the screen: | ||
$this->user = $spanishUser; | ||
$response = $this->apiCall('GET', "$url?include=screen"); | ||
$responseData = $response->json(); | ||
$items = collect($responseData['screen']['config'][0]['items']); | ||
$firstNameItem = $items->firstWhere('config.name', 'first_name'); | ||
$lastNameItem = $items->firstWhere('config.name', 'last_name'); | ||
$ageItem = $items->firstWhere('config.name', 'age'); | ||
|
||
$this->assertEquals('Nombre', $firstNameItem['config']['label']); | ||
$this->assertEquals('Apellido', $lastNameItem['config']['label']); | ||
$this->assertEquals('Edad', $ageItem['config']['label']); | ||
} | ||
|
||
|
||
public function testTranslationWithLanguageThatDoesNotHaveTranslation() | ||
{ | ||
$defaultAdminUser = User::factory()->create(['is_administrator' => true]); | ||
$portugueseUser = User::factory()->create(['is_administrator' => true, 'language' => 'pt']); | ||
|
||
$this->user = $defaultAdminUser; | ||
|
||
$fileName = __DIR__ . '/../../Fixtures/translation_test.json'; | ||
$file = new UploadedFile($fileName, 'translation_test.json', null, null, true); | ||
Storage::putFileAs('import', $file, 'payload.json'); | ||
Storage::put('import/options.json', '{}'); | ||
$hash = md5_file(Storage::path(ImportV2::FILE_PATH)); | ||
ImportV2::dispatchSync($this->user->id, null, $hash, false); | ||
|
||
$process = Process::orderBy('id', 'desc')->first(); | ||
|
||
WorkflowManager::triggerStartEvent( | ||
$process, | ||
$process->getDefinitions()->getEvent('node_1'), | ||
[] | ||
); | ||
|
||
$task = ProcessRequestToken::orderBy('id', 'desc')->first(); | ||
|
||
$this->user = $portugueseUser; | ||
$url = route('api.tasks.show', [$task->id]); | ||
$response = $this->apiCall('GET', "$url?include=screen"); | ||
$response->assertStatus(200); | ||
|
||
// As portuguese is not translated, english must be used | ||
$response = $this->apiCall('GET', "$url?include=screen"); | ||
$responseData = $response->json(); | ||
$items = collect($responseData['screen']['config'][0]['items']); | ||
$firstNameItem = $items->firstWhere('config.name', 'first_name'); | ||
$lastNameItem = $items->firstWhere('config.name', 'last_name'); | ||
$ageItem = $items->firstWhere('config.name', 'age'); | ||
|
||
$this->assertEquals('First Name', $firstNameItem['config']['label']); | ||
$this->assertEquals('Last Name', $lastNameItem['config']['label']); | ||
$this->assertEquals('Age', $ageItem['config']['label']); | ||
} | ||
|
||
public function testTranslationWithLanguageThatHasTranslation() | ||
{ | ||
|
||
$spanishUser = User::factory()->create(['is_administrator' => true, 'language' => 'es']); | ||
$this->user = User::factory()->create(['is_administrator' => true]); | ||
|
||
$fileName = __DIR__ . '/../../Fixtures/translation_test.json'; | ||
$file = new UploadedFile($fileName, 'translation_test.json', null, null, true); | ||
Storage::putFileAs('import', $file, 'payload.json'); | ||
Storage::put('import/options.json', '{}'); | ||
$hash = md5_file(Storage::path(ImportV2::FILE_PATH)); | ||
ImportV2::dispatchSync($this->user->id, null, $hash, false); | ||
|
||
$process = Process::orderBy('id', 'desc')->first(); | ||
|
||
WorkflowManager::triggerStartEvent( | ||
$process, | ||
$process->getDefinitions()->getEvent('node_1'), | ||
[] | ||
); | ||
|
||
$newTask = ProcessRequestToken::orderBy('id', 'desc')->first(); | ||
$url = route('api.tasks.show', [$newTask->id]); | ||
$response = $this->apiCall('GET', "$url?include=screen"); | ||
|
||
// Spanish has translation, so it should be used for the screen: | ||
$this->user = $spanishUser; | ||
$response = $this->apiCall('GET', "$url?include=screen"); | ||
$responseData = $response->json(); | ||
$items = collect($responseData['screen']['config'][0]['items']); | ||
$firstNameItem = $items->firstWhere('config.name', 'first_name'); | ||
$lastNameItem = $items->firstWhere('config.name', 'last_name'); | ||
$ageItem = $items->firstWhere('config.name', 'age'); | ||
|
||
$this->assertEquals('Nombre', $firstNameItem['config']['label']); | ||
$this->assertEquals('Apellido', $lastNameItem['config']['label']); | ||
$this->assertEquals('Edad', $ageItem['config']['label']); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.