ChartsDefaultSettingsTest.php in Charts 8.4
File
tests/src/Unit/Settings/ChartsDefaultSettingsTest.php
View source
<?php
namespace Drupal\Tests\charts\Unit\Settings;
use Drupal\charts\Settings\ChartsDefaultSettings;
use Drupal\Tests\UnitTestCase;
use Drupal\charts\Settings\ChartsDefaultColors;
class ChartsDefaultSettingsTest extends UnitTestCase {
private $chartsDefaultSettings;
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);
}
private function getDefaultColorsMock() {
$chartsDefaultColors = $this
->prophesize(ChartsDefaultColors::class);
$chartsDefaultColors
->getDefaultColors()
->willReturn([
'#2f7ed8',
]);
return $chartsDefaultColors
->reveal();
}
public function tearDown() {
parent::tearDown();
$this->chartsDefaultSettings = NULL;
}
public function testNumberOfDefaultSettings() {
$this
->assertCount(39, $this->chartsDefaultSettings
->getDefaults());
$this
->assertCount(7, $this->chartsDefaultSettings
->getDefaults(TRUE));
}
public function testDefaults(array $defaults) {
$this->chartsDefaultSettings
->setDefaults($defaults);
$this
->assertArrayEquals($defaults, $this->chartsDefaultSettings
->getDefaults());
$keys_mapping = ChartsDefaultSettings::getLegacySettingsMappingKeys();
$keys_mapping['colors'] = 'display_colors';
$new_format = ChartsDefaultSettings::transformLegacySettingsToNew($defaults, $keys_mapping);
$this
->assertArrayEquals($new_format, $this->chartsDefaultSettings
->getDefaults(TRUE));
}
public function defaultSettingsProvider() {
(yield [
[
'width' => 400,
'width_units' => 'px',
'height' => 300,
'height_units' => 'px',
'colors' => [
'#2f7ed8',
],
],
]);
}
}