You are here

public function ReportTest::testSimpleReport in Forena Reports 8

Test a simple report.

File

tests/src/Unit/ReportTest.php, line 93
Implements ReportTest

Class

ReportTest
@group Forena @require module forena @coversDefaultClass \Drupal\forena\Report

Namespace

Drupal\Tests\forena\Unit

Code

public function testSimpleReport() {
  $this
    ->initParametersForm();
  $content = $this
    ->report('sample', [
    'specified_parameter' => 'specified',
  ]);
  $this
    ->assertArrayHasKey('report', $content);
  $this
    ->assertContains('<table>', $content['report']['#template']);

  // Make sure we have a title
  $this
    ->assertArrayHasKey('#title', $content);
  $this
    ->assertEquals('Sample Report', $content['#title'], 'Content has title');

  // Check to make sure our default parameter was set
  $parms = $this
    ->getDataContext('parm');
  $this
    ->assertArrayHasKey('default_parameter', $parms);
  $this
    ->assertEquals('test', $parms['default_parameter']);

  // Make sure passed parameters survive.
  $this
    ->assertArrayHasKey('specified_parameter', $parms);
  $this
    ->assertEquals('specified', $parms['specified_parameter']);

  // Check to make sure we have content.
  $this
    ->assertArrayHasKey('report', $content);
  $this
    ->assertArrayHasKey('#template', $content['report']);
  $this
    ->assertContains('<table>', $content['report']['#template']);
  $this
    ->assertContains('this &amp; that', $content['report']['#template']);

  // Verify that a parameters form has been build
  $this
    ->assertArrayHasKey('parameters', $content);
  $form = $content['parameters'];
  $this
    ->assertArrayHasKey('parms', $form);
  $this
    ->assertArrayHasKey('default_parameter', $form['parms']);

  // Verify that the css js library has been loaded
  $this
    ->assertArrayHasKey('#attached', $content);
  $this
    ->assertArrayHasKey('library', $content['#attached']);
  $library = $content['#attached']['library'];
  $this
    ->assertContains('forena/skin.default', $library, "Skin Library Loaded");
  $this
    ->assertContains('core/drupal.ajax', $library, "Core library added");
  $this
    ->assertContains('core/drupal.dialog.ajax', $library, "Report Specific Library added");
}