class ChartsDefaultSettingsTest in Charts 8.3
Same name and namespace in other branches
- 8.4 tests/src/Unit/Settings/ChartsDefaultSettingsTest.php \Drupal\Tests\charts\Unit\Settings\ChartsDefaultSettingsTest
- 5.0.x tests/src/Unit/Settings/ChartsDefaultSettingsTest.php \Drupal\Tests\charts\Unit\Settings\ChartsDefaultSettingsTest
@coversDefaultClass \Drupal\charts\Settings\ChartsDefaultSettings @group charts
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\charts\Unit\Settings\ChartsDefaultSettingsTest
Expanded class hierarchy of ChartsDefaultSettingsTest
File
- tests/
src/ Unit/ Settings/ ChartsDefaultSettingsTest.php, line 13
Namespace
Drupal\Tests\charts\Unit\SettingsView source
class ChartsDefaultSettingsTest extends UnitTestCase {
/**
* @var \Drupal\charts\Settings\ChartsDefaultSettings
*/
private $chartsDefaultSettings;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$chartsDefaultColorsMock = $this
->getDefaultColorsMock();
$this->chartsDefaultSettings = new ChartsDefaultSettings();
$colorsProperty = new \ReflectionProperty(ChartsDefaultSettings::class, 'colors');
$colorsProperty
->setAccessible(TRUE);
$colorsProperty
->setValue($this->chartsDefaultSettings, $chartsDefaultColorsMock);
}
/**
* Get a default colors mock.
*/
private function getDefaultColorsMock() {
$chartsDefaultColors = $this
->prophesize(ChartsDefaultColors::class);
$chartsDefaultColors
->getDefaultColors()
->willReturn([
'#2f7ed8',
]);
return $chartsDefaultColors
->reveal();
}
/**
* {@inheritdoc}
*/
public function tearDown() {
parent::tearDown();
$this->chartsDefaultSettings = NULL;
}
/**
* Tests the numver of defaults settings.
*/
public function testNumberOfDefaultSettings() {
$this
->assertCount(39, $this->chartsDefaultSettings
->getDefaults());
}
/**
* Tests getter and setter for defaults.
*
* @param array $defaults
* Array of default settings.
*
* @dataProvider defaultSettingsProvider
*/
public function testDefaults(array $defaults) {
$this->chartsDefaultSettings
->setDefaults($defaults);
$this
->assertArrayEquals($defaults, $this->chartsDefaultSettings
->getDefaults());
}
/**
* Data provider for setDefaults.
*/
public function defaultSettingsProvider() {
(yield [
[
'width' => 400,
'width_units' => 'px',
'height' => 300,
'height_units' => 'px',
'colors' => [
'#2f7ed8',
],
],
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ChartsDefaultSettingsTest:: |
private | property | ||
ChartsDefaultSettingsTest:: |
public | function | Data provider for setDefaults. | |
ChartsDefaultSettingsTest:: |
private | function | Get a default colors mock. | |
ChartsDefaultSettingsTest:: |
public | function |
Overrides UnitTestCase:: |
|
ChartsDefaultSettingsTest:: |
public | function | ||
ChartsDefaultSettingsTest:: |
public | function | Tests getter and setter for defaults. | |
ChartsDefaultSettingsTest:: |
public | function | Tests the numver of defaults settings. | |
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. |