You are here

public function GeocodeTest::setUp in Search API Location 8

Overrides KernelTestBase::setUp

File

modules/search_api_location_geocoder/tests/src/Kernel/GeocodeTest.php, line 39

Class

GeocodeTest
Test for the geocode plugin.

Namespace

Drupal\Tests\search_api_location_geocoder\Kernel

Code

public function setUp() {
  parent::setUp();
  $ghent = new AddressCollection([
    new Address(new Coordinates(51.037455, 3.7192784)),
  ]);

  // Mock the Geocoder service.
  $geocoder = $this
    ->getMockBuilder('\\Drupal\\geocoder\\Geocoder')
    ->disableOriginalConstructor()
    ->getMock();
  $geocoder
    ->expects($this
    ->any())
    ->method('geocode')
    ->with('Ghent')
    ->willReturn($ghent);

  // Replace the geocoder service.
  $this->container
    ->set('geocoder', $geocoder);
  \Drupal::setContainer($this->container);
  $configuration = [
    'plugins' => [
      'openstreetmap' => [
        'checked' => TRUE,
        'weight' => '-3',
      ],
      'llama' => [
        'checked' => FALSE,
        'weight' => '-3',
      ],
    ],
  ];
  $this->sut = $this->container
    ->get('plugin.manager.search_api_location.location_input')
    ->createInstance('geocode', $configuration);
}