Commit 58381716 authored by Nia Kathoni's avatar Nia Kathoni Committed by Daniel Cothran
Browse files

Issue #3276524 by nikathone: Remove the ChartsDefaultColorsTest and ChartsDefaultSettingsTest tests

parent ee4b9eb0
Loading
Loading
Loading
Loading
+0 −68
Changes for tests/src/Unit/Settings/ChartsDefaultColorsTest.php: 0 added lines, 68 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\charts\Unit\Settings;

use Drupal\charts\Settings\ChartsDefaultColors;
use Drupal\Tests\UnitTestCase;

/**
 * Tests the ChartDefaultColors class.
 *
 * @coversDefaultClass \Drupal\charts\Settings\ChartsDefaultColors
 * @group charts
 */
class ChartsDefaultColorsTest extends UnitTestCase {

  /**
   * The chart default color.
   *
   * @var \Drupal\charts\Settings\ChartsDefaultColors
   */
  private $chartsDefaultColors;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    $this->chartsDefaultColors = new ChartsDefaultColors();
  }

  /**
   * {@inheritdoc}
   */
  public function tearDown() {
    parent::tearDown();
    $this->chartsDefaultColors = NULL;
  }

  /**
   * Tests the number of default colors.
   */
  public function testNumberOfDefaultColors() {
    $this->assertCount(10, $this->chartsDefaultColors->getDefaultColors());
  }

  /**
   * Tests getter and setter for default colors.
   *
   * @param array $color
   *   An array of color codes.
   *
   * @dataProvider colorProvider
   */
  public function testDefaultColors(array $color) {
    $this->chartsDefaultColors->setDefaultColors($color);
    $this->assertArrayEquals($color, $this->chartsDefaultColors->getDefaultColors());
  }

  /**
   * Data provider for setDefaultColors().
   */
  public function colorProvider() {
    yield [
      ['#2f7ed8'],
    ];
  }

}
+0 −96
Changes for tests/src/Unit/Settings/ChartsDefaultSettingsTest.php: 0 added lines, 96 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\charts\Unit\Settings;

use Drupal\charts\Settings\ChartsDefaultSettings;
use Drupal\Tests\UnitTestCase;
use Drupal\charts\Settings\ChartsDefaultColors;

/**
 * @coversDefaultClass \Drupal\charts\Settings\ChartsDefaultSettings
 * @group charts
 */
class ChartsDefaultSettingsTest extends UnitTestCase {

  /**
   * The chart default settings.
   *
   * @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 number of defaults settings.
   */
  public function testNumberOfDefaultSettings() {
    $this->assertCount(39, $this->chartsDefaultSettings->getDefaults());
    $this->assertCount(7, $this->chartsDefaultSettings->getDefaults(TRUE));
  }

  /**
   * Tests getter and setter for defaults.
   *
   * @param array $defaults
   *   Array of default settings.
   *
   * @dataProvider defaultSettingsProvider
   */
  public function testDefaults(array $defaults) {
    // Legacy config.
    $this->chartsDefaultSettings->setDefaults($defaults);
    $this->assertArrayEquals($defaults, $this->chartsDefaultSettings->getDefaults());
    // New format config. This also allow us to test the transform to new;
    // Format.
    $keys_mapping = ChartsDefaultSettings::getLegacySettingsMappingKeys();
    $keys_mapping['colors'] = 'display_colors';
    $new_format = ChartsDefaultSettings::transformLegacySettingsToNew($defaults, $keys_mapping);
    $this->assertArrayEquals($new_format, $this->chartsDefaultSettings->getDefaults(TRUE));
  }

  /**
   * Data provider for setDefaults.
   */
  public function defaultSettingsProvider() {
    yield
    [
      [
        'width' => 400,
        'width_units' => 'px',
        'height' => 300,
        'height_units' => 'px',
        'colors' => ['#2f7ed8'],
      ],
    ];
  }

}