You are here

public function OnlyOneTest::providerGetContentTypesList in Allow a content type only once (Only One) 8

Data provider for testGetContentTypesList().

Return value

array An array of arrays, each containing:

  • 'expected' - Expected return from getContentTypesList().
  • 'content_types_list' - A list with content types objects.

See also

getContentTypesList()

File

tests/src/Unit/OnlyOneTest.php, line 156

Class

OnlyOneTest
Tests the OnlyOne class methods.

Namespace

Drupal\Tests\onlyone\Unit

Code

public function providerGetContentTypesList() {
  $expected = [
    [
      'article' => 'Article',
      'page' => 'Basic Page',
      'test' => 'Test Content Type',
    ],
    [
      'article' => 'Article',
      'blog' => 'Blog Post',
      'house' => 'House',
      'page' => 'Basic Page',
    ],
  ];

  // Getting the number of tests.
  $number_of_tests = count($expected);
  $content_types_list = [];

  // Creating the array of objects.
  for ($i = 0; $i < $number_of_tests; $i++) {
    $j = 0;

    // Creating the array of objects.
    foreach ($expected[$i] as $id => $label) {

      // EntityInterface mock.
      $content_types_list[$i][$j] = $this
        ->createMock('Drupal\\Core\\Entity\\EntityInterface');

      // Mocking id method.
      $content_types_list[$i][$j]
        ->expects($this
        ->any())
        ->method('id')
        ->willReturn($id);

      // Mocking label method.
      $content_types_list[$i][$j]
        ->expects($this
        ->any())
        ->method('label')
        ->willReturn($label);
      $j++;
    }
  }
  $tests['content types list 1'] = [
    $expected[0],
    $content_types_list[0],
  ];
  $tests['content types list 2'] = [
    $expected[1],
    $content_types_list[1],
  ];
  return $tests;
}