class ReportTest in Forena Reports 8
@group Forena @require module forena @coversDefaultClass \Drupal\forena\Report
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\forena\Unit\FrxTestCase uses FrxAPI
- class \Drupal\Tests\forena\Unit\ReportTest
- class \Drupal\Tests\forena\Unit\FrxTestCase uses FrxAPI
Expanded class hierarchy of ReportTest
File
- tests/
src/ Unit/ ReportTest.php, line 16 - Implements ReportTest
Namespace
Drupal\Tests\forena\UnitView source
class ReportTest extends FrxTestCase {
// Test report.
private $doc = '<?xml version="1.0"?>
<!DOCTYPE root [
<!ENTITY nbsp " ">
]>
<html xmlns:frx="urn:FrxReports">
<head>
<title>Report Title</title>
<frx:category>Category</frx:category>
<frx:options></frx:options>
<frx:fields>
<frx:field id="test_field" link="link" class="class">Default Value</frx:field>
</frx:fields>
<frx:commands>
<frx:ajax command="invoke" method="attr" selector="input#myinput">
["checked", "1"]
</frx:ajax>
</frx:commands>
</head>
<body>
Report Body
<div>
<frx:ajax command="invoke" />
</div>
This & That
</body>
</html>';
private $r;
/**
* Ensure that report object can be created.
*/
public function testReportParse() {
// Sample Report To parse.
$r = new Report($this->doc);
// Title Check
$this
->assertObjectHasAttribute('title', $r);
$this
->assertEquals("Report Title", $r->title, "Correct Title");
// Category Check.
$this
->assertObjectHasAttribute('category', $r);
$this
->assertEquals("Category", $r->category);
// Check to make sure fields are parsed.
$this
->assertArrayHasKey('test_field', $r->replacer->fields);
$this
->assertEquals(1, count($r->commands), 'Commands parsed');
}
/**
* Simple Render Test
*/
public function testSimpleRender() {
$this
->documentManager()
->setDocument('drupal');
$this
->documentManager()
->getDocument()
->clear();
$r = new Report($this->doc);
$r
->render('drupal', FALSE);
$content = $this
->getDocument()
->flush();
// Make sure we have a report.
$this
->assertArrayHasKey('report', $content);
$this
->assertContains('Report Body', $content['report']['#template']);
// Make sure we don't have a parameters form.
$this
->assertArrayNotHasKey('parameters', $content);
// Make sure that we don't have the the ajax command
$this
->assertNotContains('ajax', $content['report']['#template']);
//echo $content['report']['#template'];
$this
->assertContains('This & That', $content['report']['#template']);
}
/**
* Test a simple report.
*/
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 & 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");
}
public function testParameterTypes() {
$content = $this
->report('parameter_test');
// Verfiy that a parameters form has been build
$this
->assertArrayHasKey('parameters', $content);
$form = $content['parameters'];
$this
->assertArrayHasKey('parms', $form);
//@TODO: Extend testing to cover all parameter control types.
$parms = $form['parms'];
$this
->assertArrayHasKey('textfield', $parms);
$this
->assertArrayHasKey('select', $parms);
}
public function testIncludedReport() {
$content = $this
->report('include');
$report = $content['report']['#template'];
$this
->assertContains('Header', $report, 'Header in tact');
$this
->assertContains('col1', $report, 'Embedded report.');
$this
->assertContains('Footer', $report, 'Footer in tact');
$this
->assertContains('<a href', $report, 'Link got generated');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FrxAPI:: |
public | function | Returns containing application service | |
FrxAPI:: |
public | function | Get the current data context. | |
FrxAPI:: |
public | function | ||
FrxAPI:: |
public | function | Returns the data manager service | |
FrxAPI:: |
public | function | Return Data Service | |
FrxAPI:: |
public | function | Returns the fornea document manager | |
FrxAPI:: |
public | function | Report an error | |
FrxAPI:: |
public | function | Get the context of a specific id. | |
FrxAPI:: |
public | function | Get the current document | |
FrxAPI:: |
public | function | Load the contents of a file in the report file system. | |
FrxAPI:: |
function | Enter description here... | 1 | |
FrxAPI:: |
public | function | Pop data off of the stack. | |
FrxAPI:: |
public | function | Push data onto the Stack | |
FrxAPI:: |
public | function | Run a report with a particular format. | 1 |
FrxAPI:: |
public | function | Get the current report file system. | |
FrxAPI:: |
public | function | Set Data context by id. | |
FrxAPI:: |
public | function | Change to a specific document type. | |
FrxAPI:: |
public | function | Get list of skins. | |
FrxTestCase:: |
public | function | ||
FrxTestCase:: |
public | function |
Mock object instantiation. Overrides UnitTestCase:: |
2 |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
ReportTest:: |
private | property | ||
ReportTest:: |
private | property | ||
ReportTest:: |
public | function | ||
ReportTest:: |
public | function | ||
ReportTest:: |
public | function | Ensure that report object can be created. | |
ReportTest:: |
public | function | Simple Render Test | |
ReportTest:: |
public | function | Test a simple report. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |