You are here

public function ImportEntityManagerTest::testImportRemoteEntitySiteLanguagesDoesNotMatchEntityLanguages in Acquia Content Hub 8

Tests the importRemoteEntity() method.

@covers ::entityPresave

File

tests/src/Unit/ImportEntityManagerTest.php, line 558

Class

ImportEntityManagerTest
PHPUnit test for the ImportEntityManager class.

Namespace

Drupal\Tests\acquia_contenthub\Unit

Code

public function testImportRemoteEntitySiteLanguagesDoesNotMatchEntityLanguages() {
  $uuid = '11111111-1111-1111-1111-111111111111';
  $site_origin = '11111111-2222-1111-1111-111111111111';
  $entity_ch = $this
    ->createMultilanguageContentHubEntity([
    'uuid' => $uuid,
  ]);
  $this->contentHubEntitiesTracking
    ->expects($this
    ->any())
    ->method('getSiteOrigin')
    ->willReturn($site_origin);
  $this->clientManager
    ->expects($this
    ->any())
    ->method('createRequest')
    ->with('readEntity', [
    $uuid,
  ])
    ->willReturn($entity_ch);
  $this->entityManager
    ->expects($this
    ->any())
    ->method('getAllowedEntityTypes')
    ->willReturn([
    'node' => [
      'article' => 'Test article content type',
    ],
  ]);
  $loggerChannelInterface = $this
    ->createMock('\\Drupal\\Core\\Logger\\LoggerChannelInterface');
  $this->loggerFactory
    ->expects($this
    ->once())
    ->method('get')
    ->with('acquia_contenthub')
    ->willReturn($loggerChannelInterface);
  $loggerChannelInterface
    ->expects($this
    ->any())
    ->method('warning');

  // Site languages are different than entity languages.
  $this->languageManager
    ->expects($this
    ->at(0))
    ->method('getLanguages')
    ->willReturn([
    'jp' => 'jp',
    'ru' => 'ru',
  ]);
  $result = $this->importEntityManager
    ->importRemoteEntity($uuid, FALSE);
  $status_code = json_decode($result
    ->getStatusCode());
  $this
    ->assertEquals($status_code, 403);
}