You are here

class RptMapProcessorTest in Search API Location 8

Unit test for processor.

@group search_api_location @coversDefaultClass \Drupal\facets_map_widget\Plugin\facets\processor\RptMapProcessor

Hierarchy

Expanded class hierarchy of RptMapProcessorTest

File

modules/facets_map_widget/tests/src/Unit/Plugin/processor/RptMapProcessorTest.php, line 22

Namespace

Drupal\Tests\facets_map_widget\Unit\Plugin\processor
View source
class RptMapProcessorTest extends UnitTestCase {

  /**
   * Contains RptMapProcessor object.
   *
   * @var \Drupal\facets_map_widget\Plugin\facets\processor\RptMapProcessor
   */
  protected $processor;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    $this->processor = new RptMapProcessor([], 'rpt', []);
    $url_generator = $this
      ->prophesize(UrlGeneratorInterface::class);
    $container = new ContainerBuilder();
    $container
      ->set('url_generator', $url_generator
      ->reveal());
    \Drupal::setContainer($container);
  }

  /**
   * Tests the build method.
   *
   * @covers ::build
   */
  public function testBuild() {

    // Create the Url processor.
    $queryString = $this
      ->prophesize(QueryString::class);
    $queryString
      ->getFilterKey()
      ->willReturn('f');
    $queryString
      ->getSeparator()
      ->willReturn('::');
    $urlHandler = $this
      ->prophesize(UrlProcessorHandler::class);
    $urlHandler
      ->getProcessor()
      ->willReturn($queryString
      ->reveal());
    $facet = $this
      ->prophesize(FacetInterface::class);
    $facet
      ->getProcessors()
      ->willReturn([
      'url_processor_handler' => $urlHandler
        ->reveal(),
    ]);
    $facet
      ->getUrlAlias()
      ->willReturn('animals');

    /** @var \Drupal\facets\Result\ResultInterface[] $results */
    $results = [
      new Result($facet
        ->reveal(), [
        "gridLevel",
        2,
        "columns",
        32,
        "rows",
        32,
        "minX",
        -180,
        "maxX",
        180,
        "minY",
        -90,
        "maxY",
        90,
        "counts_ints2D",
      ], 'heatmap', 1),
      new Result($facet
        ->reveal(), [
        "gridLevel",
        2,
        "columns",
        32,
        "rows",
        32,
        "minX",
        -180,
        "maxX",
        180,
        "minY",
        -90,
        "maxY",
        90,
        "counts_ints2D",
      ], 'heatmap', 1),
    ];
    $results[0]
      ->setUrl(new Url('test'));
    $results[1]
      ->setUrl(new Url('test'));
    $new_results = $this->processor
      ->build($facet
      ->reveal(), $results);
    $this
      ->assertCount(2, $new_results);
    $params = UrlHelper::buildQuery([
      'f' => [
        'animals::(geom:__GEOM__)',
      ],
    ]);
    $expected_route = 'route:test?' . $params;
    $this
      ->assertEquals($expected_route, $new_results[0]
      ->getUrl()
      ->toUriString());
    $this
      ->assertEquals($expected_route, $new_results[1]
      ->getUrl()
      ->toUriString());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
RptMapProcessorTest::$processor protected property Contains RptMapProcessor object.
RptMapProcessorTest::setUp public function Overrides UnitTestCase::setUp
RptMapProcessorTest::testBuild public function Tests the build method.
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.