You are here

public function TermSelectionTest::getReferenceableEntitiesProvider in Taxonomy container 8

Data provider for testGetReferenceableEntities().

Return value

array Array of test data. Each array consists of an indexed array with two items: 1. An array representing a two dimensional taxonomy tree, keyed by vocabulary name. Each tree consists of an associative array of root level taxonomy terms, keyed by term ID, with two values:

  • 'label': the term label of the root level taxonomy term.
  • 'children': an associative array of child terms, keyed by term ID.

2. The expected select box options array as returned by the term selection plugin.

File

tests/src/Unit/TermSelectionTest.php, line 221

Class

TermSelectionTest
Tests selection of taxonomy terms by the Taxonomy Container module.

Namespace

Drupal\Tests\taxonomy_container\Unit

Code

public function getReferenceableEntitiesProvider() {
  return [
    // Test case using numeric IDs and custom list item prefix.
    [
      // Configuration.
      [
        'prefix' => '+',
      ],
      // Two vocabularies, 'insults' and 'exclamations'.
      [
        'insults' => [
          1 => [
            'label' => 'Dunderheaded coconuts!',
            'children' => [
              2 => 'Gibbering anthropoids!',
              3 => 'Great flat-footed grizzly bear!',
            ],
          ],
          4 => [
            'label' => 'Livery-livered landlubbers!',
            'children' => [
              5 => 'Macrocephalic baboon!',
              6 => 'Purple profiteering jellyfish!',
            ],
          ],
        ],
        'exclamations' => [
          7 => [
            'label' => 'Billions of blue blistering boiled and barbecued barnacles!',
            'children' => [
              8 => 'Misguided missiles!',
            ],
          ],
        ],
      ],
      // Expected result.
      [
        'insults' => [
          'Dunderheaded coconuts!' => [
            2 => '+Gibbering anthropoids!',
            3 => '+Great flat-footed grizzly bear!',
          ],
          'Livery-livered landlubbers!' => [
            5 => '+Macrocephalic baboon!',
            6 => '+Purple profiteering jellyfish!',
          ],
          'Billions of blue blistering boiled and barbecued barnacles!' => [
            8 => '+Misguided missiles!',
          ],
        ],
      ],
    ],
    // Test case using string based numeric IDs, as provided by default by the
    // core Taxonomy module.
    [
      // Configuration.
      [],
      // Two vocabularies, 'insults' and 'exclamations'.
      [
        'insults' => [
          '1' => [
            'label' => 'Dunderheaded coconuts!',
            'children' => [
              '2' => 'Gibbering anthropoids!',
              '3' => 'Great flat-footed grizzly bear!',
            ],
          ],
          '4' => [
            'label' => 'Livery-livered landlubbers!',
            'children' => [
              '5' => 'Macrocephalic baboon!',
              '6' => 'Purple profiteering jellyfish!',
            ],
          ],
        ],
        'exclamations' => [
          '7' => [
            'label' => 'Billions of blue blistering boiled and barbecued barnacles!',
            'children' => [
              '8' => 'Misguided missiles!',
            ],
          ],
        ],
      ],
      // Expected result.
      [
        'insults' => [
          'Dunderheaded coconuts!' => [
            '2' => '-Gibbering anthropoids!',
            '3' => '-Great flat-footed grizzly bear!',
          ],
          'Livery-livered landlubbers!' => [
            '5' => '-Macrocephalic baboon!',
            '6' => '-Purple profiteering jellyfish!',
          ],
          'Billions of blue blistering boiled and barbecued barnacles!' => [
            '8' => '-Misguided missiles!',
          ],
        ],
      ],
    ],
    // Test case using string IDs, as can be provided by custom taxonomy
    // implementations (such as for example the RDF Taxonomy module).
    [
      // Configuration.
      [],
      // Two vocabularies, 'insults' and 'exclamations'.
      [
        'insults' => [
          'bldsckrs' => [
            'label' => 'Bloodsuckers!',
            'children' => [
              'cshnftdqdrpds' => 'Cushion-footed quadrupeds!',
              'hdrcrbn' => 'Hydrocarbon!',
            ],
          ],
          'lthsmbrt' => [
            'label' => 'Loathsome brute!',
            'children' => [
              'msrblrthwrms' => 'Miserable earth worms!',
              'sctrmp' => 'Saucy tramp!',
            ],
          ],
        ],
        'exclamations' => [
          'tnthsndthnderngtphns' => [
            'label' => 'Ten thousand thundering typhoons!',
            'children' => [
              'blblstrngbllbttmdbldrdsh' => 'Blue Blistering Bell-Bottomed Balderdash!',
            ],
          ],
        ],
      ],
      // Expected result.
      [
        'insults' => [
          'Bloodsuckers!' => [
            'cshnftdqdrpds' => '-Cushion-footed quadrupeds!',
            'hdrcrbn' => '-Hydrocarbon!',
          ],
          'Loathsome brute!' => [
            'msrblrthwrms' => '-Miserable earth worms!',
            'sctrmp' => '-Saucy tramp!',
          ],
          'Ten thousand thundering typhoons!' => [
            'blblstrngbllbttmdbldrdsh' => '-Blue Blistering Bell-Bottomed Balderdash!',
          ],
        ],
      ],
    ],
  ];
}