function VariantCollectionTraitTest::testGetVariants

Same name in other branches
  1. 8.x-3.x tests/src/Unit/VariantCollectionTraitTest.php \Drupal\Tests\ctools\Unit\VariantCollectionTraitTest::testGetVariants()

@covers ::getVariants

File

tests/src/Unit/VariantCollectionTraitTest.php, line 55

Class

VariantCollectionTraitTest
Tests the methods of a variant-aware class.

Namespace

Drupal\Tests\ctools\Unit

Code

public function testGetVariants() {
    $trait_object = new TestVariantCollectionTrait();
    $config = [
        'foo' => [
            'id' => 'foo_plugin',
        ],
        'bar' => [
            'id' => 'bar_plugin',
        ],
    ];
    foreach ($config as $value) {
        $plugin = $this->prophesize(VariantInterface::class);
        $this->manager
            ->createInstance($value['id'], $value)
            ->willReturn($plugin->reveal());
    }
    $trait_object->setVariantConfig($config);
    $variants = $trait_object->getVariants();
    $this->assertInstanceOf(VariantPluginCollection::class, $variants);
    $this->assertSame(2, count($variants));
    return $variants;
}