You are here

class OnlyOnePrintDrushTest in Allow a content type only once (Only One) 8

Tests the OnlyOnePrintAdminPage class methods.

@group onlyone @coversDefaultClass \Drupal\onlyone\OnlyOnePrintDrush

Hierarchy

Expanded class hierarchy of OnlyOnePrintDrushTest

File

tests/src/Unit/OnlyOnePrintDrushTest.php, line 15

Namespace

Drupal\Tests\onlyone\Unit
View source
class OnlyOnePrintDrushTest extends UnitTestCase {
  use OnlyOneUnitTestTrait;

  /**
   * Tests the content type list for printing for the Admin Page.
   *
   * @param array $expected
   *   The expected result from calling the function.
   * @param array $content_types
   *   A list with content types objects.
   *
   * @covers ::getContentTypesListForPrint
   * @dataProvider providerGetContentTypesListForPrint
   */
  public function testGetContentTypesListForPrint(array $expected, array $content_types) {

    // Creating the object.
    $onlyOnePrintDrush = new OnlyOnePrintDrush();
    $onlyOnePrintDrush
      ->setStringTranslation($this
      ->getStringTranslationStub());

    // Testing the function.
    $this
      ->assertEquals($expected, $onlyOnePrintDrush
      ->getContentTypesListForPrint($content_types));
  }

  /**
   * Data provider for testGetContentTypesListForPrint().
   *
   * @return array
   *   An array of arrays, each containing:
   *   - 'expected' - Expected return from getContentTypesListForPrint().
   *   - 'content_types' - A list with content types objects.
   *
   * @see getContentTypesListForPrint()
   */
  public function providerGetContentTypesListForPrint() {

    // Getting the list of content types.
    $content_types = $this
      ->getContentTypesObjectList();

    // Adding format to the Configured string.
    $configured = sprintf(OnlyOnePrintDrush::GREEN_OUTPUT, 'Configured');
    $expected = [
      // Test 1.
      [
        'page' => 'Basic Page (En: 1 Node, Es: 1 Node) ' . $configured,
        'blog' => 'Blog Post (0 Nodes) ' . $configured,
        'car' => 'Car (Not specified: 1 Node, Not applicable: 2 Nodes, En: 1 Node)',
        'article' => 'Article (Not specified: 1 Node, En: 2 Nodes, Es: 1 Node)',
      ],
      // Test 2.
      [
        'blog' => 'Blog Post (En: 1 Node) ' . $configured,
        'car' => 'Car (0 Nodes)',
      ],
      // Test 3.
      [
        'page' => 'Basic Page (En: 1 Node, Es: 1 Node) ' . $configured,
        'car' => 'Car (0 Nodes) ' . $configured,
        'article' => 'Article (Es: 3 Nodes)',
      ],
      // Test 4.
      [
        'page' => 'Basic Page (1 Node) ' . $configured,
        'blog' => 'Blog Post (2 Nodes) ' . $configured,
        'car' => 'Car (0 Nodes)',
        'article' => 'Article (5 Nodes)',
      ],
      // Test 5.
      [
        'blog' => 'Blog Post (0 Nodes) ' . $configured,
        'car' => 'Car (1 Node)',
      ],
      // Test 6.
      [
        'page' => 'Basic Page (1 Node) ' . $configured,
        'car' => 'Car (5 Nodes) ' . $configured,
        'article' => 'Article (3 Nodes)',
      ],
    ];
    $tests['multilingual 1'] = [
      $expected[0],
      $content_types[0],
    ];
    $tests['multilingual 2'] = [
      $expected[1],
      $content_types[1],
    ];
    $tests['multilingual 3'] = [
      $expected[2],
      $content_types[2],
    ];
    $tests['non-multilingual 1'] = [
      $expected[3],
      $content_types[3],
    ];
    $tests['non-multilingual 2'] = [
      $expected[4],
      $content_types[4],
    ];
    $tests['non-multilingual 3'] = [
      $expected[5],
      $content_types[5],
    ];
    return $tests;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OnlyOnePrintDrushTest::providerGetContentTypesListForPrint public function Data provider for testGetContentTypesListForPrint().
OnlyOnePrintDrushTest::testGetContentTypesListForPrint public function Tests the content type list for printing for the Admin Page.
OnlyOneUnitTestTrait::getContentTypesList public function Returns a content type label list.
OnlyOneUnitTestTrait::getContentTypesObjectList public function Returns an array of content types objects.
OnlyOneUnitTestTrait::getLanguageMap public function Returns an array of language labels.
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.
UnitTestCase::setUp protected function 340