class ContentEntitySourceUntranslatableTargetsUnitTest in Translation Management Tool 8
Content entity Source with untranslatable target types unit tests.
@group tmgmt
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses AssertContentTrait, AssertLegacyTrait, AssertHelperTrait, ConfigTestTrait, PhpunitCompatibilityTrait, RandomGeneratorTrait, TestRequirementsTrait
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses DeprecatedServicePropertyTrait, UserCreationTrait
- class \Drupal\Tests\tmgmt_content\Kernel\ContentEntityTestBase
- class \Drupal\Tests\tmgmt_content\Kernel\ContentEntitySourceUntranslatableTargetsUnitTest uses EntityReferenceTestTrait, ContentTypeCreationTrait
- class \Drupal\Tests\tmgmt_content\Kernel\ContentEntityTestBase
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses DeprecatedServicePropertyTrait, UserCreationTrait
Expanded class hierarchy of ContentEntitySourceUntranslatableTargetsUnitTest
File
- sources/
content/ tests/ src/ Kernel/ ContentEntitySourceUntranslatableTargetsUnitTest.php, line 17
Namespace
Drupal\Tests\tmgmt_content\KernelView source
class ContentEntitySourceUntranslatableTargetsUnitTest extends ContentEntityTestBase {
use EntityReferenceTestTrait;
use ContentTypeCreationTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'node',
'tmgmt_composite_test',
'entity_test',
];
/**
* {@inheritdoc}
*/
public function setUp() : void {
parent::setUp();
$this
->installEntitySchema('entity_test_composite');
$this
->installSchema('node', [
'node_access',
]);
$this->container
->get('content_translation.manager')
->setEnabled('entity_test_composite', 'entity_test_composite', FALSE);
}
/**
* Test extraction and saving translation for embedded references.
*/
public function testEmbeddedReferencesUntranslatableTargets() {
$type = NodeType::create([
'type' => 'test',
'name' => 'test',
]);
$type
->save();
$this->container
->get('content_translation.manager')
->setEnabled('node', $type
->id(), TRUE);
// Create a translatable composite entity reference fields.
$this
->createEntityReferenceField('node', $type
->id(), 't_composite', 't_composite', 'entity_test_composite', 'default', [], 2);
$this
->createEntityReferenceField('node', $type
->id(), 't_composite_no_embed', 't_composite_no_embed', 'entity_test_composite');
FieldConfig::loadByName('node', $type
->id(), 't_composite')
->setTranslatable(TRUE)
->save();
FieldConfig::loadByName('node', $type
->id(), 't_composite_no_embed')
->setTranslatable(TRUE)
->save();
// Create a nested untranslatable composite entity reference field.
$this
->createEntityReferenceField('entity_test_composite', 'entity_test_composite', 't_nested', 't_nested', 'entity_test_composite');
// Enable "t_composite" to be embedded.
$this
->config('tmgmt_content.settings')
->set('embedded_fields.node.t_composite', TRUE)
->save();
// Create three test entities that can be referenced.
$referenced_entities = [];
for ($i = 0; $i < 3; $i++) {
$referenced_values = [
'langcode' => 'en',
'name' => 'Referenced entity #' . $i,
];
$referenced_entities[$i] = EntityTestComposite::create($referenced_values);
$referenced_entities[$i]
->save();
}
$referenced_entities[2]
->set('t_nested', $referenced_entities[1]);
$referenced_entities[2]
->save();
// Create a main entity.
$node = Node::create([
'type' => $type
->id(),
'title' => 'Example',
't_composite' => $referenced_entities[2],
't_composite_no_embed' => $referenced_entities[0],
]);
$node
->save();
$job = tmgmt_job_create('en', 'de');
$job->translator = 'test_translator';
$job
->save();
$job_item = tmgmt_job_item_create('content', 'node', $node
->id(), [
'tjid' => $job
->id(),
]);
$job_item
->save();
$source_plugin = $this->container
->get('plugin.manager.tmgmt.source')
->createInstance('content');
$data = $source_plugin
->getData($job_item);
// Ensure that composite non-embedded field is not in the extracted data.
$this
->assertFalse(isset($data['t_composite_no_embed'][0]['entity']));
// Ensure some labels and structure for field 1.
$this
->assertEquals('t_composite', $data['t_composite']['#label']);
// $this->assertEquals('Delta #0', $data['t_composite'][0]['#label']);
$this
->assertEquals('Name', $data['t_composite'][0]['entity']['name']['#label'], 'Name');
$this
->assertEquals('Referenced entity #2', $data['t_composite'][0]['entity']['name'][0]['value']['#text']);
$this
->assertEquals('t_nested', $data['t_composite'][0]['entity']['t_nested']['#label']);
// Data from the composite reference of the untranslated composite target
// is embedded too.
$this
->assertEquals('Referenced entity #1', $data['t_composite'][0]['entity']['t_nested'][0]['entity']['name'][0]['value']['#text']);
// Now request a translation.
$job
->requestTranslation();
$items = $job
->getItems();
$item = reset($items);
$item
->acceptTranslation();
\Drupal::entityTypeManager()
->getStorage('entity_test_composite')
->resetCache();
// Check that the translations of the composite references were duplicated
// correctly.
/** @var \Drupal\node\NodeInterface $node */
$node = Node::load($node
->id());
$node_translation = $node
->getTranslation('de');
$composite_en = $node
->get('t_composite')->entity;
$composite_de = $node_translation
->get('t_composite')->entity;
$this
->assertNotEquals($composite_en
->id(), $composite_de
->id());
$this
->assertEquals('de(de-ch): Referenced entity #2', $composite_de
->getName());
$this
->assertEquals('de', $composite_de
->language()
->getId());
$this
->assertEquals(1, count($composite_de
->getTranslationLanguages()));
$nested_en = $composite_en
->get('t_nested')->entity;
$nested_de = $composite_de
->get('t_nested')->entity;
$this
->assertNotEquals($nested_en
->id(), $nested_de
->id());
$this
->assertEquals('de(de-ch): Referenced entity #1', $nested_de
->getName());
$this
->assertEquals('de', $nested_de
->language()
->getId());
$this
->assertEquals(1, count($nested_de
->getTranslationLanguages()));
// Add a new composite reference and translate the entity again.
$node = $node
->getTranslation('en');
$node
->setTitle('English (update)');
$referenced_entities[3] = EntityTestComposite::create([
'langcode' => 'en',
'name' => 'Referenced entity #3',
]);
$node
->get('t_composite')
->appendItem($referenced_entities[3]);
$node
->save();
// Create a job and accept the translation.
$job = tmgmt_job_create('en', 'de');
$job->translator = 'test_translator';
$job
->save();
$job_item = tmgmt_job_item_create('content', 'node', $node
->id(), [
'tjid' => $job
->id(),
]);
$job_item
->save();
$job
->requestTranslation();
$items = $job
->getItems();
$item = reset($items);
// Revert the translation of the first composite to the original value.
$name_data = $item
->getData([
't_composite',
0,
'entity',
'name',
0,
'value',
]);
$name_data_translation = $name_data['#translation'];
$name_data_translation['#text'] = $name_data['#text'];
$item
->addTranslatedData($name_data_translation, [
't_composite',
0,
'entity',
'name',
0,
'value',
]);
$item
->acceptTranslation();
$node = Node::load($node
->id());
\Drupal::entityTypeManager()
->getStorage('entity_test_composite')
->resetCache();
\Drupal::entityTypeManager()
->getStorage('node')
->resetCache();
$this
->assertEquals('de(de-ch): English (update)', $node
->getTranslation('de')
->label());
$this
->assertEquals(2, $node
->getTranslation('de')
->get('t_composite')
->count());
$this
->assertEquals('de(de-ch): Referenced entity #3', $node
->getTranslation('de')
->get('t_composite')
->get(1)->entity
->getName());
// The ID of the unchanged field item has been changed, while the actual
// content matches the original value.
$this
->assertNotEquals($referenced_entities[2]
->id(), $node
->getTranslation('de')
->get('t_composite')
->get(0)->target_id);
$this
->assertEquals('Referenced entity #2', $node
->getTranslation('de')
->get('t_composite')
->get(0)->entity
->getName());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssertContentTrait:: |
protected | property | The current raw content. | |
AssertContentTrait:: |
protected | property | The drupalSettings value from the current raw $content. | |
AssertContentTrait:: |
protected | property | The XML structure parsed from the current raw $content. | 1 |
AssertContentTrait:: |
protected | property | The plain-text content of raw $content (text nodes). | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS found escaped on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given name or ID. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given ID and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given name and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists in the current page by the given XPath. | |
AssertContentTrait:: |
protected | function | Asserts that a checkbox field in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists in the current page with a given Xpath result. | |
AssertContentTrait:: |
protected | function | Passes if a link with the specified label is found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href (part) is found. | |
AssertContentTrait:: |
protected | function | Asserts that each HTML ID is used for just a single element. | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS NOT found escaped on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given name or ID. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given ID and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given name and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist or its value does not match, by XPath. | |
AssertContentTrait:: |
protected | function | Asserts that a checkbox field in the current page is not checked. | |
AssertContentTrait:: |
protected | function | Passes if a link with the specified label is not found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href (part) is not found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href is not found in the main region. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page does not exist. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is not checked. | |
AssertContentTrait:: |
protected | function | Triggers a pass if the perl regex pattern is not found in raw content. | |
AssertContentTrait:: |
protected | function | Passes if the raw text is NOT found on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Passes if the page (with HTML stripped) does not contains the text. | |
AssertContentTrait:: |
protected | function | Pass if the page title is not the given string. | |
AssertContentTrait:: |
protected | function | Passes if the text is found MORE THAN ONCE on the text version of the page. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page exists. | |
AssertContentTrait:: |
protected | function | Asserts that a select option with the visible text exists. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page exists. | |
AssertContentTrait:: |
protected | function | Triggers a pass if the Perl regex pattern is found in the raw content. | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS found on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Passes if the page (with HTML stripped) contains the text. | |
AssertContentTrait:: |
protected | function | Helper for assertText and assertNoText. | |
AssertContentTrait:: |
protected | function | Asserts that a Perl regex pattern is found in the plain-text content. | |
AssertContentTrait:: |
protected | function | Asserts themed output. | |
AssertContentTrait:: |
protected | function | Pass if the page title is the given string. | |
AssertContentTrait:: |
protected | function | Passes if the text is found ONLY ONCE on the text version of the page. | |
AssertContentTrait:: |
protected | function | Helper for assertUniqueText and assertNoUniqueText. | |
AssertContentTrait:: |
protected | function | Builds an XPath query. | |
AssertContentTrait:: |
protected | function | Helper: Constructs an XPath for the given set of attributes and value. | |
AssertContentTrait:: |
protected | function | Searches elements using a CSS selector in the raw content. | |
AssertContentTrait:: |
protected | function | Get all option elements, including nested options, in a select. | |
AssertContentTrait:: |
protected | function | Gets the value of drupalSettings for the currently-loaded page. | |
AssertContentTrait:: |
protected | function | Gets the current raw content. | |
AssertContentTrait:: |
protected | function | Get the selected value from a select field. | |
AssertContentTrait:: |
protected | function | Retrieves the plain-text content from the current raw content. | |
AssertContentTrait:: |
protected | function | Get the current URL from the cURL handler. | 1 |
AssertContentTrait:: |
protected | function | Parse content returned from curlExec using DOM and SimpleXML. | |
AssertContentTrait:: |
protected | function | Removes all white-space between HTML tags from the raw content. | |
AssertContentTrait:: |
protected | function | Sets the value of drupalSettings for the currently-loaded page. | |
AssertContentTrait:: |
protected | function | Sets the raw content (e.g. HTML). | |
AssertContentTrait:: |
protected | function | Performs an xpath search on the contents of the internal browser. | |
AssertHelperTrait:: |
protected static | function | Casts MarkupInterface objects into strings. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead. | |
AssertLegacyTrait:: |
protected | function | ||
ConfigTestTrait:: |
protected | function | Returns a ConfigImporter object to import test configuration. | |
ConfigTestTrait:: |
protected | function | Copies configuration objects from source storage to target storage. | |
ContentEntitySourceUntranslatableTargetsUnitTest:: |
public static | property |
Modules to enable. Overrides ContentEntityTestBase:: |
|
ContentEntitySourceUntranslatableTargetsUnitTest:: |
public | function |
Overrides ContentEntityTestBase:: |
|
ContentEntitySourceUntranslatableTargetsUnitTest:: |
public | function | Test extraction and saving translation for embedded references. | |
ContentEntityTestBase:: |
protected | property | 3 | |
ContentTypeCreationTrait:: |
protected | function | Creates a custom content type based on default settings. | 1 |
DeprecatedServicePropertyTrait:: |
public | function | Allows to access deprecated/removed properties. | |
EntityKernelTestBase:: |
protected | property | The list of deprecated services. | |
EntityKernelTestBase:: |
protected | property | The entity type manager service. | 1 |
EntityKernelTestBase:: |
protected | property | A list of generated identifiers. | |
EntityKernelTestBase:: |
protected | property | The state service. | |
EntityKernelTestBase:: |
protected | function | Creates a user. | |
EntityKernelTestBase:: |
protected | function | Generates a random ID avoiding collisions. | |
EntityKernelTestBase:: |
protected | function | Returns the entity_test hook invocation info. | |
EntityKernelTestBase:: |
protected | function | Installs a module and refreshes services. | |
EntityKernelTestBase:: |
protected | function | Refresh services. | 1 |
EntityKernelTestBase:: |
protected | function | Reloads the given entity from the storage and returns it. | |
EntityKernelTestBase:: |
protected | function | Uninstalls a module and refreshes services. | |
EntityReferenceTestTrait:: |
protected | function | Creates a field of an entity reference field storage on the specified bundle. | |
KernelTestBase:: |
protected | property | Back up and restore any global variables that may be changed by tests. | |
KernelTestBase:: |
protected | property | Back up and restore static class properties that may be changed by tests. | |
KernelTestBase:: |
protected | property | Contains a few static class properties for performance. | |
KernelTestBase:: |
protected | property | ||
KernelTestBase:: |
protected | property | @todo Move into Config test base class. | 7 |
KernelTestBase:: |
protected static | property | An array of config object names that are excluded from schema checking. | |
KernelTestBase:: |
protected | property | ||
KernelTestBase:: |
protected | property | ||
KernelTestBase:: |
protected | property | Do not forward any global state from the parent process to the processes that run the actual tests. | |
KernelTestBase:: |
protected | property | The app root. | |
KernelTestBase:: |
protected | property | Kernel tests are run in separate processes because they allow autoloading of code from extensions. Running the test in a separate process isolates this behavior from other tests. Subclasses should not override this property. | |
KernelTestBase:: |
protected | property | ||
KernelTestBase:: |
protected | property | Set to TRUE to strict check all configuration saved. | 6 |
KernelTestBase:: |
protected | property | The virtual filesystem root directory. | |
KernelTestBase:: |
protected | function | 1 | |
KernelTestBase:: |
protected | function | Bootstraps a basic test environment. | |
KernelTestBase:: |
private | function | Bootstraps a kernel for a test. | |
KernelTestBase:: |
protected | function | Configuration accessor for tests. Returns non-overridden configuration. | |
KernelTestBase:: |
protected | function | Disables modules for this test. | |
KernelTestBase:: |
protected | function | Enables modules for this test. | |
KernelTestBase:: |
protected | function | Gets the config schema exclusions for this test. | |
KernelTestBase:: |
protected | function | Returns the Database connection info to be used for this test. | 1 |
KernelTestBase:: |
public | function | ||
KernelTestBase:: |
private | function | Returns Extension objects for $modules to enable. | |
KernelTestBase:: |
private static | function | Returns the modules to enable for this test. | |
KernelTestBase:: |
protected | function | Initializes the FileCache component. | |
KernelTestBase:: |
protected | function | Installs default configuration for a given list of modules. | |
KernelTestBase:: |
protected | function | Installs the storage schema for a specific entity type. | |
KernelTestBase:: |
protected | function | Installs database tables from a module schema definition. | |
KernelTestBase:: |
protected | function | Returns whether the current test method is running in a separate process. | |
KernelTestBase:: |
protected | function | ||
KernelTestBase:: |
public | function |
Registers test-specific services. Overrides ServiceProviderInterface:: |
26 |
KernelTestBase:: |
protected | function | Renders a render array. | 1 |
KernelTestBase:: |
protected | function | Sets the install profile and rebuilds the container to update it. | |
KernelTestBase:: |
protected | function | Sets an in-memory Settings variable. | |
KernelTestBase:: |
public static | function | 1 | |
KernelTestBase:: |
protected | function | Sets up the filesystem, so things like the file directory. | 2 |
KernelTestBase:: |
protected | function | Stops test execution. | |
KernelTestBase:: |
protected | function | 6 | |
KernelTestBase:: |
public | function | @after | |
KernelTestBase:: |
protected | function | Dumps the current state of the virtual filesystem to STDOUT. | |
KernelTestBase:: |
public | function | Prevents serializing any properties. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RandomGeneratorTrait:: |
protected | property | The random generator. | |
RandomGeneratorTrait:: |
protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait:: |
protected | function | Generates a unique random string containing letters and numbers. | 1 |
RandomGeneratorTrait:: |
public | function | Generates a random PHP object. | |
RandomGeneratorTrait:: |
public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
RandomGeneratorTrait:: |
public | function | Callback for random string validation. | |
StorageCopyTrait:: |
protected static | function | Copy the configuration from one storage to another and remove stale items. | |
TestRequirementsTrait:: |
private | function | Checks missing module requirements. | |
TestRequirementsTrait:: |
protected | function | Check module requirements for the Drupal use case. | 1 |
TestRequirementsTrait:: |
protected static | function | Returns the Drupal root directory. | |
UserCreationTrait:: |
protected | function | Checks whether a given list of permission names is valid. Aliased as: drupalCheckPermissions | |
UserCreationTrait:: |
protected | function | Creates an administrative role. Aliased as: drupalCreateAdminRole | |
UserCreationTrait:: |
protected | function | Creates a role with specified permissions. Aliased as: drupalCreateRole | |
UserCreationTrait:: |
protected | function | Create a user with a given set of permissions. Aliased as: drupalCreateUser | |
UserCreationTrait:: |
protected | function | Grant permissions to a user role. Aliased as: drupalGrantPermissions | |
UserCreationTrait:: |
protected | function | Switch the current logged in user. Aliased as: drupalSetCurrentUser | |
UserCreationTrait:: |
protected | function | Creates a random user account and sets it as current user. Aliased as: drupalSetUpCurrentUser |