ChartsTypeInfoTest.php in Charts 8.3
File
tests/src/Unit/Settings/ChartsTypeInfoTest.php
View source
<?php
namespace Drupal\Tests\charts\Unit\Settings;
use Drupal\charts\Settings\ChartsTypeInfo;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\DependencyInjection\ContainerBuilder;
class ChartsTypeInfoTest extends UnitTestCase {
private $chartsTypeInfo;
public function setUp() {
parent::setUp();
$container = new ContainerBuilder();
$container
->set('string_translation', $this
->getStringTranslationStub());
\Drupal::setContainer($container);
$this->chartsTypeInfo = new ChartsTypeInfo();
}
public function tearDown() {
parent::tearDown();
$this->chartsTypeInfo = NULL;
$container = new ContainerBuilder();
\Drupal::setContainer($container);
}
public function chartsChartsTypeInfo() {
(yield [
'area',
]);
(yield [
'bar',
]);
(yield [
'column',
]);
(yield [
'donut',
]);
(yield [
'gauge',
]);
(yield [
'line',
]);
(yield [
'pie',
]);
(yield [
'scatter',
]);
(yield [
'spline',
]);
}
public function testChartsChartsTypeInfo(string $chartType) {
$chartsTypeInfo = $this->chartsTypeInfo
->chartsChartsTypeInfo();
$this
->assertArrayHasKey($chartType, $chartsTypeInfo);
$this
->assertArrayHasKey('label', $chartsTypeInfo[$chartType]);
$this
->assertArrayHasKey('axis', $chartsTypeInfo[$chartType]);
}
public function testGetChartTypes(string $chartType) {
$chartTypes = $this->chartsTypeInfo
->getChartTypes();
$this
->assertArrayHasKey($chartType, $chartTypes);
$this
->assertInternalType('string', $chartTypes[$chartType]
->render());
}
public function testGetChartType(string $chartType) {
$chartTypeInfo = $this->chartsTypeInfo
->getChartType($chartType);
$this
->assertInternalType('array', $chartTypeInfo);
$this
->assertArrayHasKey('label', $chartTypeInfo);
$this
->assertArrayHasKey('axis', $chartTypeInfo);
}
public function testGetChartTypeWithNonExistentChartType() {
$chartTypeInfo = $this->chartsTypeInfo
->getChartType('some_type');
$this
->assertFalse($chartTypeInfo);
}
}