8000 Fix producer external links dropped when a section is missing by rombat · Pull Request #672 · jikan-me/jikan · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ which changes a consumer can see.

### Fixed
- **A person's anime staff positions** (`AnimeStaffPosition::getPosition()`) started with the text of MyAnimeList's "add" (to list) button, e.g. `add Director, Storyboard`; they now hold the position alone, e.g. `Director, Storyboard`.
- **A producer's external links** (`Producer::getExternalLinks()`) were empty when its page had only one of the "Available At" and "Resources" sections; the links of the section present are now returned.

---

Expand Down
8 changes: 0 additions & 8 deletions src/Parser/Producer/ProducerParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ public function getExternalLinks(): array
$availableAtLinks = $this->crawler
->filterXPath('//*[@id="content"]/div[1]/div[contains(@class, "user-profile-sns")]/span//a');

if (!$availableAtLinks->count()) {
return [];
}

$links = array_merge($links, $availableAtLinks
->each(function (Crawler $c) {
return new UrlParser($c)->getModel();
Expand All @@ -259,10 +255,6 @@ public function getExternalLinks(): array
$resourcesLinks = $this->crawler
->filterXPath('//*[@id="content"]/div[1]/div[contains(@class, "pb16")]/span//a');

if (!$resourcesLinks->count()) {
return [];
}

$links = array_merge($links, $resourcesLinks
->each(function (Crawler $c) {
return new UrlParser($c)->getModel();
Expand Down
42 changes: 42 additions & 0 deletions test/unit/Corpus/ProducerExternalLinksTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace JikanTest\Corpus;

use Jikan\Model\Common\Url;
use Jikan\Parser\Producer\ProducerParser;
use JikanTest\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;

/**
* A producer page lists its links in two sections, "Available At" and "Resources". When one section was
* missing, getExternalLinks() returned no link at all, dropping the other section too (e.g. a studio with an
* official site but no "Resources" link). The recorded Pierrot page has both: removing one section must keep
* the other's links.
*/
class ProducerExternalLinksTest extends TestCase
{
/**
* @return iterable<string, array{string, int, string}>
*/
public static function sections(): iterable
{
yield 'without "Resources"' => ['pb16', 5, 'http://pierrot.jp/'];
yield 'without "Available At"' => ['user-profile-sns', 6, 'https://pierrot.jp/company/'];
}

#[Test]
#[DataProvider('sections')]
public function the_other_section_keeps_its_links(string $removedClass, int $count, string $firstUrl): void
{
$page = Variants::crawler('producer-1-p1');
$section = $page->filterXPath('//*[@id="content"]/div[1]/div[contains(@class, "' . $removedClass . '")]')->getNode(0);
$section->parentNode->removeChild($section);

$links = new ProducerParser($page)->getExternalLinks();

self::assertCount($count, $links);
self::assertContainsOnlyInstancesOf(Url::class, $links);
self::assertSame($firstUrl, $links[0]->getUrl());
}
}
0