EckEntityTranslationTest.php in Entity Construction Kit (ECK) 8
File
tests/src/Functional/EckEntityTranslationTest.php
View source
<?php
namespace Drupal\Tests\eck\Functional;
class EckEntityTranslationTest extends FunctionalTestBase {
protected static $modules = [
'content_translation',
];
protected $entityType;
protected $bundle;
protected function getAdministratorPermissions() {
return array_merge([
'administer languages',
'administer content translation',
'translate any entity',
'create content translations',
'update content translations',
'delete content translations',
], parent::getAdministratorPermissions());
}
public function setUp() {
parent::setUp();
$this->entityType = $this
->createEntityType([], 'translatable');
$this->bundle = $this
->createEntityBundle($this->entityType['id'], 'translatable');
$this
->drupalGet('admin/config/regional/language/add');
$this
->submitForm([
'predefined_langcode' => 'uk',
], t('Add language'));
$this
->drupalGet('admin/config/regional/content-language');
$edit = [
"entity_types[{$this->entityType['id']}]" => TRUE,
"settings[{$this->entityType['id']}][{$this->bundle['type']}][translatable]" => TRUE,
];
$this
->submitForm($edit, 'Save configuration');
$this
->resetAll();
}
public function testEntityTranslation() {
$entity = $this
->createEntity($this->entityType['id'], [
'type' => $this->bundle['type'],
'title' => 'ECK Entity',
]);
$entity_type = $entity
->getEntityTypeId();
$this
->drupalGet("{$entity_type}/{$entity->id()}/translations");
$this
->assertSession()
->linkByHrefExists("{$entity_type}/{$entity->id()}/translations/add/en/uk");
$this
->getSession()
->getPage()
->clickLink('Add');
$this
->getSession()
->getPage()
->fillField('Title', 'ECK Entity translation');
$this
->getSession()
->getPage()
->pressButton('Save');
$this
->drupalGet("{$entity_type}/{$entity->id()}/translations");
$this
->assertSession()
->linkByHrefExists("{$entity_type}/{$entity->id()}");
$this
->assertSession()
->linkByHrefExists("uk/{$entity_type}/{$entity->id()}");
$this
->drupalGet("{$entity_type}/{$entity->id()}");
$this
->assertSession()
->pageTextContains('ECK Entity');
$this
->drupalGet("uk/{$entity_type}/{$entity->id()}");
$this
->assertSession()
->pageTextContains('ECK Entity translation');
}
public function testDeleteEntityTranslation() {
$entity = $this
->createEntity($this->entityType['id'], [
'type' => $this->bundle['type'],
'title' => 'ECK Entity',
]);
$entity_type = $entity
->getEntityTypeId();
$this
->drupalGet("{$entity_type}/{$entity->id()}/translations/add/en/uk");
$this
->getSession()
->getPage()
->fillField('Title', 'ECK Entity translation');
$this
->getSession()
->getPage()
->pressButton('Save');
$this
->drupalGet("uk/{$entity_type}/{$entity->id()}/edit");
$this
->getSession()
->getPage()
->pressButton('Delete translation');
$this
->assertSession()
->pageTextContains('Are you sure you want to delete the Ukrainian translation of the translatable ECK Entity translation?');
$this
->getSession()
->getPage()
->pressButton('Delete Ukrainian translation');
$this
->drupalGet("{$entity_type}/{$entity->id()}/translations");
$this
->assertSession()
->linkByHrefExists("{$entity_type}/{$entity->id()}");
$this
->assertSession()
->linkByHrefExists("uk/{$entity_type}/{$entity->id()}/translations/add/en/uk");
}
}