class AReportTokenTest in Forena Reports 8
Class AReportTokenTest @group Forena @require module forena @coversDefaultClass \Drupal\forena\Token\ReportReplacer
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\forena\Unit\FrxTestCase uses FrxAPI
- class \Drupal\Tests\forena\Unit\AReportTokenTest
- class \Drupal\Tests\forena\Unit\FrxTestCase uses FrxAPI
Expanded class hierarchy of AReportTokenTest
File
- tests/
src/ Unit/ AReportTokenTest.php, line 13
Namespace
Drupal\Tests\forena\UnitView source
class AReportTokenTest extends FrxTestCase {
private $replacer;
public function __construct() {
parent::__construct();
$this->replacer = new ReportReplacer($this
->dataService());
}
public function testReplacement() {
$data = [
'name' => 'Bob',
];
$this
->pushData($data, 'p');
$rep = new ReportReplacer($this
->dataService());
$this
->assertNotNull($rep);
// Replace the data
$text = $rep
->replace('Hello {name}');
$this
->assertEquals('Hello Bob', $text);
$this
->popData();
}
/**
* Verify that basic Context specific token replacement works.
*/
public function testContextReplacement() {
$data = [
'name' => 'Bob',
];
$this
->pushData($data, 'p');
// Replace the data
$text = $this->replacer
->replace('Hello {p.name}');
$this
->assertEquals('Hello Bob', $text);
$this
->popData();
$messages = [
'messages' => [
'deep' => [
'Hello {p.name}',
],
],
];
$this->replacer
->replaceNested($messages);
$this
->assertEquals('Hello Bob', $messages['messages']['deep'][0]);
}
/**
* Test token replacement from a custom data context.
*/
public function testCustomContext() {
$text = $this->replacer
->replace('you are {custom_security.secure} secure.');
$this
->assertEquals('you are not secure.', $text);
}
public function testReportContext() {
$text = $this->replacer
->replace('Report follows: {FrxReport.sample}');
$this
->assertContains('col1', $text);
}
/**
* basic test for field generation.
*/
public function testLinkGeneration() {
$data = [
'title' => 'Title',
];
$data['link'] = 'some/page';
$data['data-test'] = 'foo';
$this
->pushData($data);
$text = "See {title}";
$this->replacer
->defineField('title', $data);
$text = $this->replacer
->replace($text);
$this
->assertContains("<a title='Title' data-test='foo' href='some/page'>Title</a>", $text);
$this
->popData();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AReportTokenTest:: |
private | property | ||
AReportTokenTest:: |
public | function | Verify that basic Context specific token replacement works. | |
AReportTokenTest:: |
public | function | Test token replacement from a custom data context. | |
AReportTokenTest:: |
public | function | basic test for field generation. | |
AReportTokenTest:: |
public | function | ||
AReportTokenTest:: |
public | function | ||
AReportTokenTest:: |
public | function | ||
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. | |
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. |