2017-06-04 19:06:22 +01:00
|
|
|
|
<?php
|
|
|
|
|
|
2021-03-17 18:38:18 +00:00
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-06-04 19:06:22 +01:00
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
2021-08-31 12:48:43 +01:00
|
|
|
|
use App\Models\Article;
|
|
|
|
|
use App\Models\Note;
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
2017-06-04 19:06:22 +01:00
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
|
|
class FeedsTest extends TestCase
|
|
|
|
|
{
|
2021-08-31 12:48:43 +01:00
|
|
|
|
use RefreshDatabase;
|
|
|
|
|
|
2017-06-04 19:06:22 +01:00
|
|
|
|
/**
|
|
|
|
|
* Test the blog RSS feed.
|
|
|
|
|
*
|
2021-03-17 18:38:18 +00:00
|
|
|
|
* @test
|
2017-06-04 19:06:22 +01:00
|
|
|
|
*/
|
2021-03-17 18:38:18 +00:00
|
|
|
|
public function blogRssFeedIsPresent(): void
|
2017-06-04 19:06:22 +01:00
|
|
|
|
{
|
2021-08-31 12:48:43 +01:00
|
|
|
|
Article::factory()->count(3)->create();
|
2017-06-04 19:06:22 +01:00
|
|
|
|
$response = $this->get('/blog/feed.rss');
|
|
|
|
|
$response->assertHeader('Content-Type', 'application/rss+xml; charset=utf-8');
|
2021-03-17 18:38:18 +00:00
|
|
|
|
$response->assertOk();
|
2017-06-04 19:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test the notes RSS feed.
|
|
|
|
|
*
|
2021-03-17 18:38:18 +00:00
|
|
|
|
* @test
|
2017-06-04 19:06:22 +01:00
|
|
|
|
*/
|
2021-03-17 18:38:18 +00:00
|
|
|
|
public function notesRssFeedIsPresent(): void
|
2017-06-04 19:06:22 +01:00
|
|
|
|
{
|
2021-08-31 12:48:43 +01:00
|
|
|
|
Note::factory()->count(3)->create();
|
2017-06-04 19:06:22 +01:00
|
|
|
|
$response = $this->get('/notes/feed.rss');
|
|
|
|
|
$response->assertHeader('Content-Type', 'application/rss+xml; charset=utf-8');
|
2021-03-17 18:38:18 +00:00
|
|
|
|
$response->assertOk();
|
2017-06-04 19:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test the blog RSS feed.
|
|
|
|
|
*
|
2021-03-17 18:38:18 +00:00
|
|
|
|
* @test
|
2017-06-04 19:06:22 +01:00
|
|
|
|
*/
|
2021-03-17 18:38:18 +00:00
|
|
|
|
public function blogAtomFeedIsPresent(): void
|
2017-06-04 19:06:22 +01:00
|
|
|
|
{
|
2021-08-31 12:48:43 +01:00
|
|
|
|
Article::factory()->count(3)->create();
|
2017-06-04 19:06:22 +01:00
|
|
|
|
$response = $this->get('/blog/feed.atom');
|
|
|
|
|
$response->assertHeader('Content-Type', 'application/atom+xml; charset=utf-8');
|
2021-03-17 18:38:18 +00:00
|
|
|
|
$response->assertOk();
|
2017-06-04 19:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-20 16:47:39 +01:00
|
|
|
|
/** @test */
|
2021-03-17 18:38:18 +00:00
|
|
|
|
public function blogJf2FeedIsPresent(): void
|
2020-06-20 16:47:39 +01:00
|
|
|
|
{
|
2021-08-31 12:48:43 +01:00
|
|
|
|
Article::factory()->count(3)->create();
|
2020-06-20 16:47:39 +01:00
|
|
|
|
$response = $this->get('/blog/feed.jf2');
|
|
|
|
|
$response->assertHeader('Content-Type', 'application/jf2feed+json');
|
|
|
|
|
$response->assertJson([
|
|
|
|
|
'type' => 'feed',
|
|
|
|
|
'name' => 'Blog feed for ' . config('app.name'),
|
|
|
|
|
'url' => url('/blog'),
|
|
|
|
|
'author' => [
|
|
|
|
|
'type' => 'card',
|
2023-06-11 16:52:37 +01:00
|
|
|
|
'name' => config('user.display_name'),
|
2023-06-09 18:31:53 +01:00
|
|
|
|
'url' => config('url.longurl'),
|
2020-06-20 16:47:39 +01:00
|
|
|
|
],
|
|
|
|
|
'children' => [[
|
|
|
|
|
'type' => 'entry',
|
|
|
|
|
'post-type' => 'article',
|
2022-07-09 10:08:26 +01:00
|
|
|
|
]],
|
2020-06-20 16:47:39 +01:00
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-04 19:06:22 +01:00
|
|
|
|
/**
|
|
|
|
|
* Test the notes RSS feed.
|
|
|
|
|
*
|
2021-03-17 18:38:18 +00:00
|
|
|
|
* @test
|
2017-06-04 19:06:22 +01:00
|
|
|
|
*/
|
2021-03-17 18:38:18 +00:00
|
|
|
|
public function notesAtomFeedIsPresent(): void
|
2017-06-04 19:06:22 +01:00
|
|
|
|
{
|
2021-08-31 12:48:43 +01:00
|
|
|
|
Note::factory()->count(3)->create();
|
2017-06-04 19:06:22 +01:00
|
|
|
|
$response = $this->get('/notes/feed.atom');
|
|
|
|
|
$response->assertHeader('Content-Type', 'application/atom+xml; charset=utf-8');
|
2021-03-17 18:38:18 +00:00
|
|
|
|
$response->assertOk();
|
2017-06-04 19:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test the blog JSON feed.
|
|
|
|
|
*
|
2021-03-17 18:38:18 +00:00
|
|
|
|
* @test
|
2017-06-04 19:06:22 +01:00
|
|
|
|
*/
|
2021-03-17 18:38:18 +00:00
|
|
|
|
public function blogJsonFeedIsPresent(): void
|
2017-06-04 19:06:22 +01:00
|
|
|
|
{
|
2021-08-31 12:48:43 +01:00
|
|
|
|
Article::factory()->count(3)->create();
|
2017-06-04 19:06:22 +01:00
|
|
|
|
$response = $this->get('/blog/feed.json');
|
|
|
|
|
$response->assertHeader('Content-Type', 'application/json');
|
2021-03-17 18:38:18 +00:00
|
|
|
|
$response->assertOk();
|
2017-06-04 19:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test the notes JSON feed.
|
|
|
|
|
*
|
2021-03-17 18:38:18 +00:00
|
|
|
|
* @test
|
2017-06-04 19:06:22 +01:00
|
|
|
|
*/
|
2021-03-17 18:38:18 +00:00
|
|
|
|
public function notesJsonFeedIsPresent(): void
|
2017-06-04 19:06:22 +01:00
|
|
|
|
{
|
2021-08-31 12:48:43 +01:00
|
|
|
|
Note::factory()->count(3)->create();
|
2017-06-04 19:06:22 +01:00
|
|
|
|
$response = $this->get('/notes/feed.json');
|
|
|
|
|
$response->assertHeader('Content-Type', 'application/json');
|
2021-03-17 18:38:18 +00:00
|
|
|
|
$response->assertOk();
|
2017-06-04 19:06:22 +01:00
|
|
|
|
}
|
2018-04-12 18:15:42 +01:00
|
|
|
|
|
2020-06-20 16:47:39 +01:00
|
|
|
|
/** @test */
|
2021-03-17 18:38:18 +00:00
|
|
|
|
public function notesJf2FeedIsPresent(): void
|
2020-06-20 16:47:39 +01:00
|
|
|
|
{
|
2021-08-31 12:48:43 +01:00
|
|
|
|
Note::factory()->count(3)->create();
|
2020-06-20 16:47:39 +01:00
|
|
|
|
$response = $this->get('/notes/feed.jf2');
|
|
|
|
|
$response->assertHeader('Content-Type', 'application/jf2feed+json');
|
|
|
|
|
$response->assertJson([
|
|
|
|
|
'type' => 'feed',
|
|
|
|
|
'name' => 'Notes feed for ' . config('app.name'),
|
|
|
|
|
'url' => url('/notes'),
|
|
|
|
|
'author' => [
|
|
|
|
|
'type' => 'card',
|
2023-06-11 16:52:37 +01:00
|
|
|
|
'name' => config('user.display_name'),
|
2023-06-09 18:31:53 +01:00
|
|
|
|
'url' => config('url.longurl'),
|
2020-06-20 16:47:39 +01:00
|
|
|
|
],
|
|
|
|
|
'children' => [[
|
|
|
|
|
'type' => 'entry',
|
|
|
|
|
'post-type' => 'note',
|
2022-07-09 10:08:26 +01:00
|
|
|
|
]],
|
2020-06-20 16:47:39 +01:00
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-12 18:15:42 +01:00
|
|
|
|
/**
|
|
|
|
|
* Each JSON feed item must have one of `content_text` or `content_html`,
|
|
|
|
|
* and whichever one they have can’t be `null`.
|
|
|
|
|
*
|
2021-03-17 18:38:18 +00:00
|
|
|
|
* @test
|
2018-04-12 18:15:42 +01:00
|
|
|
|
*/
|
2021-03-17 18:38:18 +00:00
|
|
|
|
public function jsonFeedsHaveRequiredAttributes(): void
|
2018-04-12 18:15:42 +01:00
|
|
|
|
{
|
2021-08-31 12:48:43 +01:00
|
|
|
|
Note::factory()->count(3)->create();
|
2018-04-12 18:15:42 +01:00
|
|
|
|
$response = $this->get('/notes/feed.json');
|
|
|
|
|
$data = json_decode($response->content());
|
|
|
|
|
foreach ($data->items as $item) {
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
property_exists($item, 'content_text') ||
|
|
|
|
|
property_exists($item, 'content_html')
|
|
|
|
|
);
|
|
|
|
|
if (property_exists($item, 'content_text')) {
|
|
|
|
|
$this->assertNotNull($item->content_text);
|
|
|
|
|
}
|
|
|
|
|
if (property_exists($item, 'content_html')) {
|
|
|
|
|
$this->assertNotNull($item->content_html);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-04 19:06:22 +01:00
|
|
|
|
}
|