You are here

public function ParserTest::testParsing in Google Search Appliance 8

Tests parsing.

File

tests/src/Unit/ParserTest.php, line 25

Class

ParserTest
Tests parsing of result set.

Namespace

Drupal\Tests\google_appliance\Unit

Code

public function testParsing() {
  $response = file_get_contents(__DIR__ . '/../../fixtures/response.xml');
  $parser = new Parser($this
    ->createMock(ModuleHandlerInterface::class));
  $results = $parser
    ->parseResponse($response);
  $this
    ->assertEquals(7040, $results
    ->getTotal());
  $searchResults = $results
    ->getResults();
  $this
    ->assertCount(20, $searchResults);
  $result = reset($searchResults);
  $this
    ->assertEquals('http://www.uts.edu.au/research-and-teaching/future-researchers', $result
    ->getAbsoluteUrl());
  $this
    ->assertStringContainsString('Future researchers', strip_tags((string) $result
    ->getTitle()));
  $this
    ->assertStringContainsString('UTS is home to world-leading', (string) $result
    ->getSnippet());
}