class ChartsTypeInfoTest in Charts 8.3
Tests the ChartsTypeInfo class.
@coversDefaultClass \Drupal\charts\Settings\ChartsTypeInfo @group charts
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\charts\Unit\Settings\ChartsTypeInfoTest
Expanded class hierarchy of ChartsTypeInfoTest
File
- tests/
src/ Unit/ Settings/ ChartsTypeInfoTest.php, line 15
Namespace
Drupal\Tests\charts\Unit\SettingsView source
class ChartsTypeInfoTest extends UnitTestCase {
/**
* @var \Drupal\charts\Settings\ChartsTypeInfo
*/
private $chartsTypeInfo;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$container = new ContainerBuilder();
$container
->set('string_translation', $this
->getStringTranslationStub());
\Drupal::setContainer($container);
$this->chartsTypeInfo = new ChartsTypeInfo();
}
/**
* {@inheritdoc}
*/
public function tearDown() {
parent::tearDown();
$this->chartsTypeInfo = NULL;
$container = new ContainerBuilder();
\Drupal::setContainer($container);
}
/**
* Data provider for testChartsChartsTypeInfo(), testGetChartTypes and testGetChartType().
*/
public function chartsChartsTypeInfo() {
(yield [
'area',
]);
(yield [
'bar',
]);
(yield [
'column',
]);
(yield [
'donut',
]);
(yield [
'gauge',
]);
(yield [
'line',
]);
(yield [
'pie',
]);
(yield [
'scatter',
]);
(yield [
'spline',
]);
}
/**
* Tests chartsChartsTypeInfo().
*
* @param string $chartType
* The chart type.
*
* @dataProvider chartsChartsTypeInfo
*/
public function testChartsChartsTypeInfo(string $chartType) {
$chartsTypeInfo = $this->chartsTypeInfo
->chartsChartsTypeInfo();
$this
->assertArrayHasKey($chartType, $chartsTypeInfo);
$this
->assertArrayHasKey('label', $chartsTypeInfo[$chartType]);
$this
->assertArrayHasKey('axis', $chartsTypeInfo[$chartType]);
}
/**
* Tests getChartTypes().
*
* @param string $chartType
* The chart type.
*
* @dataProvider chartsChartsTypeInfo
*/
public function testGetChartTypes(string $chartType) {
$chartTypes = $this->chartsTypeInfo
->getChartTypes();
$this
->assertArrayHasKey($chartType, $chartTypes);
$this
->assertInternalType('string', $chartTypes[$chartType]
->render());
}
/**
* Tests getChartType().
*
* @param string $chartType
* The chart type.
*
* @dataProvider chartsChartsTypeInfo
*/
public function testGetChartType(string $chartType) {
$chartTypeInfo = $this->chartsTypeInfo
->getChartType($chartType);
$this
->assertInternalType('array', $chartTypeInfo);
$this
->assertArrayHasKey('label', $chartTypeInfo);
$this
->assertArrayHasKey('axis', $chartTypeInfo);
}
/**
* Tests getChartType() with a nonexistent chart type.
*/
public function testGetChartTypeWithNonExistentChartType() {
$chartTypeInfo = $this->chartsTypeInfo
->getChartType('some_type');
$this
->assertFalse($chartTypeInfo);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ChartsTypeInfoTest:: |
private | property | ||
ChartsTypeInfoTest:: |
public | function | Data provider for testChartsChartsTypeInfo(), testGetChartTypes and testGetChartType(). | |
ChartsTypeInfoTest:: |
public | function |
Overrides UnitTestCase:: |
|
ChartsTypeInfoTest:: |
public | function | ||
ChartsTypeInfoTest:: |
public | function | Tests chartsChartsTypeInfo(). | |
ChartsTypeInfoTest:: |
public | function | Tests getChartType(). | |
ChartsTypeInfoTest:: |
public | function | Tests getChartTypes(). | |
ChartsTypeInfoTest:: |
public | function | Tests getChartType() with a nonexistent chart type. | |
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. |