You are here

class ArrayWidgetTest in Facets 8

Unit test for widget.

@group facets

Hierarchy

Expanded class hierarchy of ArrayWidgetTest

File

tests/src/Unit/Plugin/widget/ArrayWidgetTest.php, line 13

Namespace

Drupal\Tests\facets\Unit\Plugin\widget
View source
class ArrayWidgetTest extends WidgetTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->widget = new ArrayWidget([
      'show_numbers' => 1,
    ], 'array_widget', []);
  }

  /**
   * Tests widget without filters.
   */
  public function testNoFilterResults() {
    $facet = new Facet([], 'facets_facet');
    $facet
      ->setResults($this->originalResults);
    $facet
      ->setFieldIdentifier('tag');
    $output = $this->widget
      ->build($facet);
    $this
      ->assertSame('array', gettype($output));
    $this
      ->assertCount(4, $output['tag']);
    $expected_links = [
      [
        'url' => NULL,
        'values' => [
          'value' => 'Llama',
          'count' => 10,
        ],
      ],
      [
        'url' => NULL,
        'values' => [
          'value' => 'Badger',
          'count' => 20,
        ],
      ],
      [
        'url' => NULL,
        'values' => [
          'value' => 'Duck',
          'count' => 15,
        ],
      ],
      [
        'url' => NULL,
        'values' => [
          'value' => 'Alpaca',
          'count' => 9,
        ],
      ],
    ];
    foreach ($expected_links as $index => $value) {
      $this
        ->assertSame('array', gettype($output['tag'][$index]));
      $this
        ->assertEquals($value['values']['value'], $output['tag'][$index]['values']['value']);
      $this
        ->assertEquals($value['values']['count'], $output['tag'][$index]['values']['count']);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function testDefaultConfiguration() {
    $default_config = $this->widget
      ->defaultConfiguration();
    $expected = [
      'show_numbers' => FALSE,
    ];
    $this
      ->assertEquals($expected, $default_config);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ArrayWidgetTest::setUp protected function Sets up the container and other variables used in all the tests. Overrides WidgetTestBase::setUp
ArrayWidgetTest::testDefaultConfiguration public function Tests default configuration. Overrides WidgetTestBase::testDefaultConfiguration
ArrayWidgetTest::testNoFilterResults public function Tests widget without filters.
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.
WidgetTestBase::$facet protected property The facet used for the widget test.
WidgetTestBase::$originalResults protected property An array containing the results for the widget.
WidgetTestBase::$queryTypes protected property An array of possible query types.
WidgetTestBase::$widget protected property The widget to be tested.
WidgetTestBase::buildLinkAssertion protected function Build a formattable markup object to use as assertion.
WidgetTestBase::testGetQueryType public function Tests get query type. 1
WidgetTestBase::testIsPropertyRequired public function Tests default for required properties. 1