public function ContentEntityPathTest::testNoPathauto

Tests the path integration.

File

sources/content/tests/src/Kernel/ContentEntityPathTest.php, line 53

Class

ContentEntityPathTest
Tests for the path/pathauto integration.

Namespace

Drupal\Tests\tmgmt_content\Kernel

Code

public function testNoPathauto() {

  // Create a node with a path.
  $values = [
    'langcode' => 'en',
    'type' => 'page',
    'uid' => 1,
    'title' => 'Test node',
    'path' => [
      'alias' => '/en-example-path',
    ],
  ];
  $node = Node::create($values);
  $node
    ->save();
  $this
    ->assertPathAliasExists('/en-example-path', 'en', NULL, '');
  $job = tmgmt_job_create('en', 'de');
  $job->translator = 'test_translator';
  $job
    ->save();
  $job_item = tmgmt_job_item_create('content', $this->entityTypeId, $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);

  // Test the expected structure of the metatags field.
  $expected_field_data = [
    '#label' => 'URL alias',
    0 => [
      'alias' => [
        '#label' => 'Path alias',
        '#text' => '/en-example-path',
        '#translate' => TRUE,
      ],
      'pid' => [
        '#label' => 'Path id',
        '#text' => '1',
        '#translate' => FALSE,
      ],
      'langcode' => [
        '#label' => 'Language Code',
        '#text' => 'en',
        '#translate' => FALSE,
      ],
    ],
  ];
  $this
    ->assertEquals($expected_field_data, $data['path']);

  // Now request a translation and save it back.
  $job
    ->requestTranslation();
  $items = $job
    ->getItems();
  $item = reset($items);
  $item
    ->acceptTranslation();

  // Check that the translations were saved correctly.
  $node = Node::load($node
    ->id());
  $translation = $node
    ->getTranslation('de');
  $this
    ->assertEquals('/de-example-path', $translation
    ->get('path')->alias);
  $this
    ->assertEquals('de', $translation
    ->get('path')->langcode);
  $this
    ->assertNotEquals($node
    ->get('path')->pid, $translation
    ->get('path')->pid);
  $this
    ->assertPathAliasExists('/de-example-path', 'de', NULL, '');
}