class FrxCrosstabTest in Forena Reports 8
@group Forena @require module forena @coversDefaultClass \Drupal\forena\FrxPlugin\Renderer\FrxXML
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\forena\Unit\FrxTestCase uses FrxAPI
- class \Drupal\Tests\forena\Unit\Renderer\FrxRendererTestCase
- class \Drupal\Tests\forena\Unit\Renderer\FrxCrosstabTest
- class \Drupal\Tests\forena\Unit\Renderer\FrxRendererTestCase
- class \Drupal\Tests\forena\Unit\FrxTestCase uses FrxAPI
Expanded class hierarchy of FrxCrosstabTest
File
- tests/
src/ Unit/ Renderer/ FrxCrosstabTest.php, line 19
Namespace
Drupal\Tests\forena\Unit\RendererView source
class FrxCrosstabTest extends FrxRendererTestCase {
// 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:fields>
</frx:fields>
</head>
<body>
<table frx:renderer="FrxCrosstab" frx:group="{state}" frx:dim="{gender}">
<thead>
<tr><th>State</th><td>users</td></tr>
</thead>
<tbody>
<tr><th>{state}</th><td>{users}</td></tr>
</tbody>
</table>
</body>
</html>';
/**
* @param array $array
* @return array
* Helper function
*/
public function arrayData(array $array) {
$new_array = [];
foreach ($array as $r => $row) {
$new_row = [];
foreach ($row as $key => $value) {
$new_row[$key] = $value['data'];
}
$new_array[] = $new_row;
}
return $new_array;
}
/**
* Test Crosstab Renderer
*/
public function testFrxCrosstab() {
// Generate the crosstab
$data = $this
->dataManager()
->data('test/crosstab_data');
$this
->pushData($data);
$elements = $this
->render('\\Drupal\\forena\\FrxPlugin\\Renderer\\FrxCrosstab', $this->doc, 'table');
$this
->popData();
// Assertions
$this
->assertGreaterThan(0, count($elements), $elements);
$element = $elements[0];
$this
->assertEquals('table', $element['#type']);
$rows = $element['#rows'];
$this
->assertEquals(2, count($rows), "Correct row grouping count returned");
$data_rows = $this
->arrayData($rows);
$AL = $data_rows[0];
$CA = $data_rows[1];
$header_data[] = $element['#header'];
$headers = $this
->arrayData($header_data);
$h = $headers[0];
$this
->assertEquals(4, count($h));
$this
->assertEquals(4, count($AL), "Correct Number of columns AL");
$this
->assertEquals(4, count($CA), "Correct number of columns CA");
$this
->assertEquals('State', $h[0]);
$this
->assertEquals('Male', $h[1]);
$this
->assertEquals('Female', $h[2]);
$this
->assertEquals('Unknown', $h[3]);
}
}
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. | |
FrxCrosstabTest:: |
private | property | ||
FrxCrosstabTest:: |
public | function | ||
FrxCrosstabTest:: |
public | function | Test Crosstab Renderer | |
FrxRendererTestCase:: |
protected | property | @var \Drupal\forena\FrxPlugin\Renderer\RendererInterface | |
FrxRendererTestCase:: |
protected | property | @var \Drupal\forena\Report | |
FrxRendererTestCase:: |
public | function | ||
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. | |
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. |