You are here

public function ContentHubStatusDetailsTest::testContentHubStatusReportDetails in Acquia Content Hub 8.2

Tests status report details build.

@dataProvider providerTestContentHubStatusReportDetails

Parameters

string $client_uuid: UUID of the client passed to controller.

string $webhook_uuid: Webhook uuid that corresponds to client, see MockDataProvider.

array $details: Details that display on details controller.

array $publisher_status: Attached drupalSettings for publisher statuses.

array $publisher_color: Attached drupalSettings for publisher colors.

array $subscriber_status: Attached drupalSettings for subscriber statuses.

array $subscriber_color: Attached drupalSettings for subscriber colors.

Throws

\Exception

File

tests/src/Kernel/ContentHubStatusDetailsTest.php, line 87

Class

ContentHubStatusDetailsTest
Tests the Content Hub settings form.

Namespace

Drupal\Tests\acquia_contenthub\Kernel

Code

public function testContentHubStatusReportDetails($client_uuid, $webhook_uuid, array $details, array $publisher_status, array $publisher_color, array $subscriber_status, array $subscriber_color) {
  $settings = $this
    ->prophesize(Settings::class);
  $settings
    ->getUuid()
    ->willReturn('3a89ff1b-8869-419d-b931-f2282aca3e88');
  $settings
    ->getName()
    ->willReturn('foo');
  $settings
    ->getUrl()
    ->willReturn('http://www.example.com');
  $settings
    ->getApiKey()
    ->willReturn('apikey');
  $settings
    ->getSecretKey()
    ->willReturn('apisecret');
  $client = $this
    ->prophesize(ContentHubClient::class);
  $clientFactory = $this
    ->prophesize(ClientFactory::class);
  $clientFactory
    ->getSettings()
    ->willReturn($settings
    ->reveal());
  $client
    ->getSettings()
    ->willReturn($settings
    ->reveal());
  $client
    ->getEntity($client_uuid)
    ->willReturn(MockDataProvider::getClient($client_uuid));
  $client
    ->getInterestsByWebhook($webhook_uuid)
    ->willReturn([
    $client_uuid,
  ]);
  $clientFactory
    ->getClient()
    ->willReturn($client
    ->reveal());
  $controller = new StatusReportDetailsController($clientFactory
    ->reveal());
  $build = $controller
    ->getWebhookDetails($client_uuid);

  // Check if graph ids are set.
  if (!empty($build['single_details_page']['publisher_graph'])) {
    $this
      ->assertTrue($this
      ->getMarkupValue($build['single_details_page']['publisher_graph']['#attributes']['id']) === 'publisher_chart', 'Publisher chart id is correct.');
  }
  if (!empty($build['single_details_page']['subscriber_graph'])) {
    $this
      ->assertTrue($this
      ->getMarkupValue($build['single_details_page']['subscriber_graph']['#attributes']['id']) === 'subscriber_chart', 'Subscriber chart id is correct.');
  }

  // Check the important data details.
  foreach ($details as $key => $value) {
    $this
      ->assertTrue($this
      ->getMarkupValue($build['single_details_page']['details'][$key]['#value']) === $value);
  }
  foreach ($publisher_status as $status => $number) {
    $this
      ->assertTrue($this
      ->getMarkupValue($build['#attached']['drupalSettings']['acquia_contenthub_publisher_status'][$status]) === $number);
  }
  foreach ($publisher_color as $status => $color) {
    $this
      ->assertTrue($this
      ->getMarkupValue($build['#attached']['drupalSettings']['acquia_contenthub_publisher_color'][$status]) === $color);
  }
  foreach ($subscriber_status as $status => $number) {
    $this
      ->assertTrue($this
      ->getMarkupValue($build['#attached']['drupalSettings']['acquia_contenthub_subscriber_status'][$status]) === $number);
  }
  foreach ($subscriber_color as $status => $color) {
    $this
      ->assertTrue($this
      ->getMarkupValue($build['#attached']['drupalSettings']['acquia_contenthub_subscriber_color'][$status]) === $color);
  }
}