You are here

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

Data provider for testGetAvailableContentTypesSummarized().

Return value

array An array of arrays, each containing:

  • 'expected' - Expected return from getAvailableContentTypesSummarized().
  • 'configured' - The configured content types.
  • 'content_types' - Returned content types from the the database query.
  • 'multilingual' - Whether the site is multilingual or not.
  • 'language_map' - The language map for the getLanguageLabel method.

See also

testGetAvailableContentTypesSummarized()

File

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

Class

OnlyOneTest
Tests the OnlyOne class methods.

Namespace

Drupal\Tests\onlyone\Unit

Code

public function providerGetAvailableContentTypesSummarized() {

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

  // Content types configured to have onlyone node.
  $configured = [
    [
      'page',
      'blog',
    ],
    [
      'blog',
    ],
    [
      'car',
      'page',
    ],
  ];
  $content_types = [
    [
      // Test 1.
      'page' => [
        (object) [
          'language' => 'en',
          'total' => 1,
        ],
        (object) [
          'language' => 'es',
          'total' => 1,
        ],
      ],
      'blog' => [
        (object) [
          'language' => '',
          'total' => 0,
        ],
      ],
      'car' => [
        (object) [
          'language' => 'und',
          'total' => 1,
        ],
        (object) [
          'language' => 'xzz',
          'total' => 2,
        ],
        (object) [
          'language' => 'en',
          'total' => 1,
        ],
      ],
      'article' => [
        (object) [
          'language' => 'und',
          'total' => 1,
        ],
        (object) [
          'language' => 'en',
          'total' => 2,
        ],
        (object) [
          'language' => 'es',
          'total' => 1,
        ],
      ],
    ],
    // Test 2.
    [
      'blog' => [
        (object) [
          'language' => 'en',
          'total' => 1,
        ],
      ],
      'car' => [
        (object) [
          'language' => '',
          'total' => 0,
        ],
      ],
    ],
    // Test 3.
    [
      'page' => [
        (object) [
          'language' => 'en',
          'total' => 1,
        ],
        (object) [
          'language' => 'es',
          'total' => 1,
        ],
      ],
      'car' => [
        (object) [
          'language' => '',
          'total' => 0,
        ],
      ],
      'article' => [
        (object) [
          'language' => 'es',
          'total' => 3,
        ],
      ],
    ],
    // Test 4.
    [
      'page' => [
        (object) [
          'total' => 1,
        ],
      ],
      'blog' => [
        (object) [
          'total' => 2,
        ],
      ],
      'car' => [
        (object) [
          'total' => 0,
        ],
      ],
      'article' => [
        (object) [
          'total' => 5,
        ],
      ],
    ],
    // Test 5.
    [
      'blog' => [
        (object) [
          'total' => 0,
        ],
      ],
      'car' => [
        (object) [
          'total' => 1,
        ],
      ],
    ],
    // Test 6.
    [
      'page' => [
        (object) [
          'total' => 1,
        ],
      ],
      'car' => [
        (object) [
          'total' => 5,
        ],
      ],
      'article' => [
        (object) [
          'total' => 3,
        ],
      ],
    ],
  ];

  // Multilingual tests.
  $tests['multi 1'] = [
    $expected[0],
    $configured[0],
    $content_types[0],
    TRUE,
  ];
  $tests['multi 2'] = [
    $expected[1],
    $configured[1],
    $content_types[1],
    TRUE,
  ];
  $tests['multi 3'] = [
    $expected[2],
    $configured[2],
    $content_types[2],
    TRUE,
  ];

  // Not-multilingual tests.
  $tests['not 1'] = [
    $expected[3],
    $configured[0],
    $content_types[3],
    FALSE,
  ];
  $tests['not 2'] = [
    $expected[4],
    $configured[1],
    $content_types[4],
    FALSE,
  ];
  $tests['not 3'] = [
    $expected[5],
    $configured[2],
    $content_types[5],
    FALSE,
  ];
  return $tests;
}