public function LinkcheckerLinkCheckerServiceTest::setUp in Link checker 8
Overrides KernelTestBase::setUp
File
- tests/
src/ Kernel/ LinkcheckerLinkCheckerServiceTest.php, line 60
Class
- LinkcheckerLinkCheckerServiceTest
- Test for LinkCheckerService.
Namespace
Drupal\Tests\linkchecker\KernelCode
public function setUp() {
parent::setUp();
$this
->installSchema('system', 'sequences');
$this
->installEntitySchema('linkcheckerlink');
$this
->installConfig('linkchecker');
// Create a mock and queue the responses.
$mock = new MockHandler([
new Response(200, []),
new Response(200, [
'Content-Type' => 'text/html',
'Link' => [
'bar',
'foo',
],
], '<div id="foo"></div>'),
new Response(200, [
'Content-Type' => 'text/html',
'Link' => [
'foo',
'baz',
],
], '<div id="foo"></div>'),
new Response(200, [
'Content-type' => 'text/html',
'Link' => '<https://drupal.org>; rel="my-rel", <https://drupal.org>; rel=shortlink',
], '<div id="bar">This is bar</div>'),
new Response(301, []),
new Response(404, []),
new Response(405, []),
new Response(500, []),
new Response(100, []),
]);
$handler = HandlerStack::create($mock);
$client = new Client([
'handler' => $handler,
]);
// Second client for comparing results.
// @see http://docs.guzzlephp.org/en/stable/testing.html
$handler2 = HandlerStack::create(clone $mock);
$client2 = new Client([
'handler' => $handler2,
]);
$this->container
->set('http_client', $client);
$this->checkerService = $this->container
->get('linkchecker.checker');
$this->httpClient = $client2;
$this->time = $this->container
->get('datetime.time');
$this->linkcheckerSetting = $this->container
->get('config.factory')
->getEditable('linkchecker.settings');
}