-
-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(sticky): list discussions works as expected with stickies (#3507)
Signed-off-by: Sami Mazouz <ilyasmazouz@gmail.com>
- Loading branch information
Showing
8 changed files
with
215 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
120 changes: 120 additions & 0 deletions
120
extensions/sticky/tests/integration/api/ListDiscussionsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Sticky\tests\integration\api; | ||
|
||
use Carbon\Carbon; | ||
use Flarum\Testing\integration\RetrievesAuthorizedUsers; | ||
use Flarum\Testing\integration\TestCase; | ||
use Illuminate\Support\Arr; | ||
|
||
class ListDiscussionsTest extends TestCase | ||
{ | ||
use RetrievesAuthorizedUsers; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->extension('flarum-tags', 'flarum-sticky'); | ||
|
||
$this->prepareDatabase([ | ||
'users' => [ | ||
['id' => 1, 'username' => 'Muralf', 'email' => 'muralf@machine.local', 'is_email_confirmed' => 1], | ||
$this->normalUser(), | ||
['id' => 3, 'username' => 'Muralf_', 'email' => 'muralf_@machine.local', 'is_email_confirmed' => 1], | ||
], | ||
'discussions' => [ | ||
['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now(), 'last_posted_at' => Carbon::now(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1, 'is_sticky' => true, 'last_post_number' => 1], | ||
['id' => 2, 'title' => __CLASS__, 'created_at' => Carbon::now()->addMinutes(2), 'last_posted_at' => Carbon::now()->addMinutes(5), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1, 'is_sticky' => false, 'last_post_number' => 1], | ||
['id' => 3, 'title' => __CLASS__, 'created_at' => Carbon::now()->addMinutes(3), 'last_posted_at' => Carbon::now()->addMinute(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1, 'is_sticky' => true, 'last_post_number' => 1], | ||
['id' => 4, 'title' => __CLASS__, 'created_at' => Carbon::now()->addMinutes(4), 'last_posted_at' => Carbon::now()->addMinutes(2), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1, 'is_sticky' => false, 'last_post_number' => 1], | ||
], | ||
'discussion_user' => [ | ||
['discussion_id' => 1, 'user_id' => 3, 'last_read_post_number' => 1], | ||
['discussion_id' => 3, 'user_id' => 3, 'last_read_post_number' => 1], | ||
], | ||
'tags' => [ | ||
['id' => 1, 'slug' => 'general', 'position' => 0, 'parent_id' => null] | ||
], | ||
'discussion_tag' => [ | ||
['discussion_id' => 1, 'tag_id' => 1], | ||
['discussion_id' => 2, 'tag_id' => 1], | ||
['discussion_id' => 3, 'tag_id' => 1], | ||
['discussion_id' => 4, 'tag_id' => 1], | ||
] | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function list_discussions_shows_sticky_first_as_guest() | ||
{ | ||
$response = $this->send( | ||
$this->request('GET', '/api/discussions') | ||
); | ||
|
||
$this->assertEquals(200, $response->getStatusCode()); | ||
|
||
$data = json_decode($response->getBody()->getContents(), true); | ||
|
||
$this->assertEquals([3, 1, 2, 4], Arr::pluck($data['data'], 'id')); | ||
} | ||
|
||
/** @test */ | ||
public function list_discussions_shows_sticky_unread_first_as_user() | ||
{ | ||
$response = $this->send( | ||
$this->request('GET', '/api/discussions', [ | ||
'authenticatedAs' => 2 | ||
]) | ||
); | ||
|
||
$this->assertEquals(200, $response->getStatusCode()); | ||
|
||
$data = json_decode($response->getBody()->getContents(), true); | ||
|
||
$this->assertEquals([3, 1, 2, 4], Arr::pluck($data['data'], 'id')); | ||
} | ||
|
||
/** @test */ | ||
public function list_discussions_shows_normal_order_when_all_read_as_user() | ||
{ | ||
$response = $this->send( | ||
$this->request('GET', '/api/discussions', [ | ||
'authenticatedAs' => 3 | ||
]) | ||
); | ||
|
||
$this->assertEquals(200, $response->getStatusCode()); | ||
|
||
$data = json_decode($response->getBody()->getContents(), true); | ||
|
||
$this->assertEquals([2, 4, 3, 1], Arr::pluck($data['data'], 'id')); | ||
} | ||
|
||
/** @test */ | ||
public function list_discussions_shows_stick_first_on_a_tag() | ||
{ | ||
$response = $this->send( | ||
$this->request('GET', '/api/discussions', [ | ||
'authenticatedAs' => 3 | ||
])->withQueryParams([ | ||
'filter' => [ | ||
'tag' => 'general' | ||
] | ||
]) | ||
); | ||
|
||
$this->assertEquals(200, $response->getStatusCode()); | ||
|
||
$data = json_decode($response->getBody()->getContents(), true); | ||
|
||
$this->assertEquals([3, 1, 2, 4], Arr::pluck($data['data'], 'id')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
use Flarum\Testing\integration\Setup\SetupScript; | ||
|
||
require __DIR__.'/../../vendor/autoload.php'; | ||
|
||
$setup = new SetupScript(); | ||
|
||
$setup->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="true" | ||
stopOnFailure="false" | ||
> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">../src/</directory> | ||
</include> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Flarum Integration Tests"> | ||
<directory suffix="Test.php">./integration</directory> | ||
<exclude>./integration/tmp</exclude> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">../src/</directory> | ||
</include> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Flarum Unit Tests"> | ||
<directory suffix="Test.php">./unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
<listeners> | ||
<listener class="\Mockery\Adapter\Phpunit\TestListener" /> | ||
</listeners> | ||
</phpunit> |
Empty file.