You are here

ParserTest.php in Google Search Appliance 8

File

tests/src/Unit/ParserTest.php
View source
<?php

namespace Drupal\Tests\google_appliance\Unit;

use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\google_appliance\Service\Parser;
use Drupal\Tests\PhpunitCompatibilityTrait;
use Drupal\Tests\UnitTestCase;
use function file_get_contents;
use function reset;
use function strip_tags;

/**
 * Tests parsing of result set.
 *
 * @group google_appliance
 */
class ParserTest extends UnitTestCase {
  use PhpunitCompatibilityTrait;

  /**
   * Tests parsing.
   */
  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());
  }

}

Classes

Namesort descending Description
ParserTest Tests parsing of result set.