Skip to content

Commit

Permalink
tec: Handle feeds served as text/html
Browse files Browse the repository at this point in the history
  • Loading branch information
marienfressinaud committed Mar 18, 2024
1 parent 441053a commit 7497ef2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/SpiderBits/src/feeds/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public static function isFeedContentType(string $content_type): bool
str_contains($content_type, 'application/json') ||
str_contains($content_type, 'application/rdf+xml') ||
str_contains($content_type, 'application/xml') ||
str_contains($content_type, 'text/html') ||
str_contains($content_type, 'text/rss+xml') ||
str_contains($content_type, 'text/xml') ||
str_contains($content_type, 'text/plain')
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/FeedsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testAddCreatesCollectionButFailsIfNotAFeed(): void
]);

$this->assertResponseCode($response, 400);
$this->assertResponseContains($response, 'Invalid content type: text/html');
$this->assertResponseContains($response, 'Can’t parse the given string');
$this->assertSame(1, models\Collection::count());
$this->assertSame(0, models\Link::count());
$collection = models\Collection::take();
Expand All @@ -129,7 +129,7 @@ public function testAddCreatesCollectionButFailsIfNotAFeed(): void
$this->assertSame('https://flus.fr/carnet/', $collection->feed_url);
$this->assertSame(200, $collection->feed_fetched_code);
$this->assertNotNull($collection->feed_fetched_error);
$this->assertStringContainsString('Invalid content type: text/html', $collection->feed_fetched_error);
$this->assertStringContainsString('Can’t parse the given string', $collection->feed_fetched_error);
}

public function testAddCreatesCollectionButFailsIfUrlIsNotSuccessful(): void
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/SpiderBits/feeds/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ public static function validContentType(): array
['application/json'],
['application/rdf+xml'],
['application/xml'],
['text/html'],
['text/rss+xml'],
['text/xml'],
['text/plain'],
Expand All @@ -471,7 +472,7 @@ public static function invalidContentType(): array
return [
[''],
['some text'],
['text/html'],
['text/csv'],
];
}
}

0 comments on commit 7497ef2

Please sign in to comment.