You are here

protected function ContentHubEntitiesTrackingTest::getContentHubEntitiesTrackingService in Acquia Content Hub 8

Loads a ContentHubEntitiesTracking object.

Parameters

array|null $database_entity: An entity array, that would come as result of a query to the database.

string|null $site_origin: The site origin.

Return value

\Drupal\acquia_contenthub\ContentHubEntitiesTracking The loaded object.

4 calls to ContentHubEntitiesTrackingTest::getContentHubEntitiesTrackingService()
ContentHubEntitiesTrackingTest::testImportedDependentEntity in tests/src/Unit/ContentHubEntitiesTrackingTest.php
Test for Imported Dependent Entity.
ContentHubEntitiesTrackingTest::testServiceLevelCaching in tests/src/Unit/ContentHubEntitiesTrackingTest.php
Test for service-level caching.
ContentHubEntitiesTrackingTest::testSetExportedEntity in tests/src/Unit/ContentHubEntitiesTrackingTest.php
Test for Exported Entities.
ContentHubEntitiesTrackingTest::testSetImportedEntity in tests/src/Unit/ContentHubEntitiesTrackingTest.php
Test for Imported Entities.

File

tests/src/Unit/ContentHubEntitiesTrackingTest.php, line 43

Class

ContentHubEntitiesTrackingTest
PHPUnit tests for the ContentHubEntitiesTracking class.

Namespace

Drupal\Tests\acquia_contenthub\Unit

Code

protected function getContentHubEntitiesTrackingService($database_entity = NULL, $site_origin = NULL) {

  // If Site Origin is not set, use default.
  $site_origin = isset($site_origin) ? $site_origin : $this->siteOrigin;
  $database = $this
    ->getMockBuilder('\\Drupal\\Core\\Database\\Connection')
    ->disableOriginalConstructor()
    ->getMock();

  // If we do not provide a database entity, do not use database.
  if (isset($database_entity)) {
    $select = $this
      ->createMock('\\Drupal\\Core\\Database\\Query\\SelectInterface');
    $select
      ->expects($this
      ->any())
      ->method('fields')
      ->with('ci')
      ->will($this
      ->returnSelf());
    $execute = $this
      ->createMock('\\Drupal\\Core\\Executable\\ExecutableInterface');
    $select
      ->expects($this
      ->any())
      ->method('condition')
      ->with('entity_uuid', $database_entity['entity_uuid'])
      ->will($this
      ->returnValue($execute));
    $statement = $this
      ->createMock('\\Drupal\\Core\\Database\\StatementInterface');
    $statement
      ->expects($this
      ->any())
      ->method('fetchAssoc')
      ->willReturn($database_entity);
    $execute
      ->expects($this
      ->any())
      ->method('execute')
      ->will($this
      ->returnValue($statement));
    $database
      ->expects($this
      ->any())
      ->method('select')
      ->withAnyParameters()
      ->will($this
      ->returnValue($select));
  }
  $admin_config = $this
    ->getMockBuilder('\\Drupal\\Core\\Config\\ImmutableConfig')
    ->disableOriginalConstructor()
    ->getMock();
  $admin_config
    ->method('get')
    ->with('origin')
    ->willReturn($site_origin);
  $config_factory = $this
    ->getMockBuilder('Drupal\\Core\\Config\\ConfigFactoryInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $config_factory
    ->method('get')
    ->with('acquia_contenthub.admin_settings')
    ->willReturn($admin_config);
  return new ContentHubEntitiesTracking($database, $config_factory);
}