mockCatalogue(new JsonMockResponse(['bibs' => [[ 'title' => 'Trzynaście zagadek / Thirteen problems, Seria z Gawronem.', 'author' => 'Christie, Agatha (1890-1976) Weiss, Maria Wydawnictwo Dolnośląskie', 'publisher' => 'Da Capo Da Capo,', 'placeOfPublication' => 'Wrocław : Polska', 'publicationYear' => '1994', 'language' => 'polski', 'isbnIssn' => '83-7023-382-1', ]]])); $crawler = $this->client->request('GET', '/add/lookup', ['id' => '5', 'isn' => '8370233821']); self::assertResponseIsSuccessful(); $crawler = $this->client->click($crawler->selectLink('Use')->link()); $form = $crawler->selectButton('Save')->form(); self::assertSame('5', $form['book[id]']->getValue()); self::assertSame('Trzynaście zagadek / Thirteen problems, Seria z Gawronem', $form['book[title]']->getValue()); self::assertSame('Agatha Christie', $form['book[author]']->getValue()); self::assertSame('Da Capo', $form['book[publisher]']->getValue()); self::assertSame('Wrocław', $form['book[publicationLoc]']->getValue()); self::assertSame('1994', $form['book[publicationYear]']->getValue()); self::assertSame('9788370233822', $form['book[isbn]']->getValue()); } public function testNoResultsOffersManualEntry(): void { $this->mockCatalogue(new JsonMockResponse(['bibs' => []])); $this->client->request('GET', '/add/lookup', ['title' => 'Nothing']); self::assertResponseIsSuccessful(); self::assertSelectorTextContains('.page_content', 'no matching books'); } public function testCatalogueFailureFallsBackToTheAddPage(): void { $this->mockCatalogue(new MockResponse('', ['http_code' => 503])); $this->client->request('GET', '/add/lookup', ['isn' => '8370233821']); self::assertResponseRedirects('/add'); $this->client->followRedirect(); self::assertSelectorTextContains('.flash', 'catalogue is unavailable'); } private function mockCatalogue(MockResponse $response): void { static::getContainer()->set('bn.client', new MockHttpClient($response, 'https://data.bn.org.pl')); } }