-
-
Notifications
You must be signed in to change notification settings - Fork 836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preloaded API document Improvements #2754
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
84f5892
Fix getting handler for the default route
askvortsov1 3f2bc3f
Invalidate preloadedApiDocument if URL has changed
askvortsov1 fe61e66
Apply fixes from StyleCI
askvortsov1 4754e5d
Revert to using `getRouteData()[0]`
askvortsov1 c84f5da
Apply fixes from StyleCI
askvortsov1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,99 @@ | ||
<?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\Tests\integration\forum; | ||
|
||
use Carbon\Carbon; | ||
use Flarum\Extend; | ||
use Flarum\Foundation\AbstractServiceProvider; | ||
use Flarum\Settings\SettingsRepositoryInterface; | ||
use Flarum\Testing\integration\TestCase; | ||
|
||
class DefaultRouteTest extends TestCase | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->prepareDatabase([ | ||
'discussions' => [ | ||
['id' => 1, 'title' => 'foo bar', 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'last_posted_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1], | ||
], | ||
'posts' => [ | ||
['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::createFromDate(1975, 5, 21)->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '<t><p>foo bar</p></t>'] | ||
] | ||
]); | ||
} | ||
|
||
/** | ||
* This is necessary as we need to add the setting to the DB before the app boots. | ||
*/ | ||
protected function setDefaultRoute($defaultRoute) | ||
{ | ||
OverrideDefaultRouteServiceProvider::$defaultRoute = $defaultRoute; | ||
$this->extend( | ||
(new Extend\ServiceProvider())->register(OverrideDefaultRouteServiceProvider::class) | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function default_route_payload_includes_discussions() | ||
{ | ||
$response = $this->send( | ||
$this->request('GET', '/') | ||
); | ||
|
||
$this->assertStringContainsString('apiDocument', $response->getBody()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function nonexistent_custom_homepage_uses_default_payload() | ||
{ | ||
$this->setDefaultRoute('/nonexistent'); | ||
|
||
$response = $this->send( | ||
$this->request('GET', '/') | ||
); | ||
|
||
$this->assertStringContainsString('apiDocument', $response->getBody()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function existent_custom_homepage_doesnt_use_default_payload() | ||
{ | ||
$this->setDefaultRoute('/settings'); | ||
|
||
$response = $this->send( | ||
$this->request('GET', '/') | ||
); | ||
|
||
$this->assertStringNotContainsString('apiDocument', $response->getBody()); | ||
} | ||
} | ||
|
||
class OverrideDefaultRouteServiceProvider extends AbstractServiceProvider | ||
{ | ||
public static $defaultRoute; | ||
|
||
public function register() | ||
{ | ||
$settings = $this->container->make(SettingsRepositoryInterface::class); | ||
|
||
$settings->set('default_route', static::$defaultRoute); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$toDefaultController = $routes->getRoutes()['GET'][$defaultRoute]['handler'];
$toDefaultController = $routes->getRouteData()[0]['GET'][$defaultRoute]['handler'];
Does it need to be modified ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @xiaowu771086986,
Yea we hadn't noticed it at the time and tests didn't catch it, but we did actually fix it not long after here: 1cca4e8
Is this what you meant ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes ,thank you !