FieldFormatterTest.php in Forena Reports 8
File
tests/src/Unit/FieldFormatterTest.php
View source
<?php
namespace Drupal\Tests\forena\Unit;
use Drupal\Core\Field\Annotation\FieldFormatter;
use Drupal\forena\FrxPlugin\FieldFormatter\Formatter;
use Drupal\forena\Token\ReportReplacer;
class FieldFormatterTest extends FrxTestCase {
protected $formatter;
public function __construct() {
parent::__construct();
$this->formatter = new Formatter();
}
public function testFormatters() {
$formatters = $this->formatter
->formats();
$this
->assertArrayHasKey('iso_date', $formatters);
}
public function testISODateFormatter() {
$vars = [
'date' => '2016-01-13',
'time' => '2016-01-13 15:30',
];
$this
->pushData($vars, 'vars');
$r = new ReportReplacer();
$field = [
'format' => 'iso_date',
'format-string' => 'm-d-Y',
];
$r
->defineField('date', $field);
$text = $r
->replace('{date}');
$this
->popData();
$this
->assertEquals('01-13-2016', $text);
}
}