-
-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: frontend content flexible order priorities (#3765)
* Fix frontend factory so it includes controller content * chore: more readable parameter passing * feat: add priorities to frontend content
- Loading branch information
Showing
7 changed files
with
123 additions
and
22 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
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
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
89 changes: 89 additions & 0 deletions
89
framework/core/tests/integration/extenders/FrontendContentTest.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,89 @@ | ||
<?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\extenders; | ||
|
||
use Flarum\Extend\Frontend; | ||
use Flarum\Frontend\Document; | ||
use Flarum\Testing\integration\RetrievesAuthorizedUsers; | ||
use Flarum\Testing\integration\TestCase; | ||
|
||
class FrontendContentTest extends TestCase | ||
{ | ||
use RetrievesAuthorizedUsers; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function content_added_with_low_priority_by_default() | ||
{ | ||
$title = null; | ||
|
||
$this->extend( | ||
(new Frontend('forum')) | ||
->content(function (Document $document) use (&$title) { | ||
$title = $document->title; | ||
}), | ||
); | ||
|
||
$body = $this->send( | ||
$this->request('GET', '/') | ||
)->getBody()->getContents(); | ||
|
||
$this->assertNotNull($title, $body); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function content_can_be_added_with_high_priority() | ||
{ | ||
$title = 1; | ||
|
||
$this->extend( | ||
(new Frontend('forum')) | ||
->content(function (Document $document) use (&$title) { | ||
$title = $document->title; | ||
}, 110), | ||
); | ||
|
||
$body = $this->send( | ||
$this->request('GET', '/') | ||
)->getBody()->getContents(); | ||
|
||
$this->assertNull($title, $body); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function contents_can_be_added_with_different_priorities() | ||
{ | ||
$test = []; | ||
|
||
$this->extend( | ||
(new Frontend('forum')) | ||
->content(function (Document $document) use (&$test) { | ||
$test[] = 1; | ||
}, 110) | ||
->content(function (Document $document) use (&$test) { | ||
$test[] = 3; | ||
}, 90) | ||
->content(function (Document $document) use (&$test) { | ||
$test[] = 2; | ||
}, 100), | ||
); | ||
|
||
$body = $this->send( | ||
$this->request('GET', '/') | ||
)->getBody()->getContents(); | ||
|
||
$this->assertEquals([1, 2, 3], $test, $body); | ||
} | ||
} |