You are here

class ChartsTypeInfoTest in Charts 8.3

Tests the ChartsTypeInfo class.

@coversDefaultClass \Drupal\charts\Settings\ChartsTypeInfo @group charts

Hierarchy

Expanded class hierarchy of ChartsTypeInfoTest

File

tests/src/Unit/Settings/ChartsTypeInfoTest.php, line 15

Namespace

Drupal\Tests\charts\Unit\Settings
View 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

Namesort descending Modifiers Type Description Overrides
ChartsTypeInfoTest::$chartsTypeInfo private property
ChartsTypeInfoTest::chartsChartsTypeInfo public function Data provider for testChartsChartsTypeInfo(), testGetChartTypes and testGetChartType().
ChartsTypeInfoTest::setUp public function Overrides UnitTestCase::setUp
ChartsTypeInfoTest::tearDown public function
ChartsTypeInfoTest::testChartsChartsTypeInfo public function Tests chartsChartsTypeInfo().
ChartsTypeInfoTest::testGetChartType public function Tests getChartType().
ChartsTypeInfoTest::testGetChartTypes public function Tests getChartTypes().
ChartsTypeInfoTest::testGetChartTypeWithNonExistentChartType public function Tests getChartType() with a nonexistent chart type.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.