-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* apply patch * Review fixes. * fix typo * fix typo * review fixes
- Loading branch information
1 parent
33ed3b0
commit 89eee94
Showing
7 changed files
with
327 additions
and
34 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
57 changes: 57 additions & 0 deletions
57
src/Gzero/Cms/Http/Controllers/Api/PublicContentController.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,57 @@ | ||
<?php namespace Gzero\Cms\Http\Controllers\Api; | ||
|
||
use Gzero\Cms\Http\Resources\ContentCollection; | ||
use Gzero\Cms\Repositories\ContentReadRepository; | ||
use Gzero\Core\Http\Controllers\ApiController; | ||
use Gzero\Core\Query\QueryBuilder; | ||
use Illuminate\Http\Request; | ||
|
||
/** | ||
* Class PublicContentController | ||
*/ | ||
class PublicContentController extends ApiController { | ||
|
||
/** @var ContentReadRepository */ | ||
protected $repository; | ||
|
||
/** @var Request */ | ||
protected $request; | ||
|
||
/** | ||
* ContentController constructor. | ||
* | ||
* @param ContentReadRepository $repository Content repository | ||
* @param Request $request Request object | ||
*/ | ||
public function __construct(ContentReadRepository $repository, Request $request) | ||
{ | ||
$this->repository = $repository; | ||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* Display list of public contents | ||
* | ||
* @SWG\Get( | ||
* path="/public-contents", | ||
* tags={"content, public"}, | ||
* summary="List of public contents", | ||
* description="List of all publicly accessible contents", | ||
* produces={"application/json"}, | ||
* @SWG\Response( | ||
* response=200, | ||
* description="Successful operation", | ||
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Content")), | ||
* ), | ||
* ) | ||
* | ||
* @return ContentCollection | ||
*/ | ||
public function index() | ||
{ | ||
$results = $this->repository->getManyPublished(new QueryBuilder()); | ||
$results->setPath(apiUrl('public-contents')); | ||
|
||
return new ContentCollection($results); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php namespace Cms\api; | ||
|
||
use Carbon\Carbon; | ||
use Cms\FunctionalTester; | ||
use Gzero\Cms\Jobs\CreateContent; | ||
use Gzero\Core\Models\Language; | ||
use Gzero\Core\Models\User; | ||
|
||
class PublicContentCest { | ||
|
||
public function shouldGetListOfPublicContents(FunctionalTester $I) | ||
{ | ||
$user = factory(User::class)->create(); | ||
$language = new Language(['code' => 'en']); | ||
|
||
dispatch_now(CreateContent::content( | ||
'Content Title published one day ago', | ||
$language, | ||
$user, | ||
[ | ||
'is_active' => true, | ||
'published_at' => Carbon::now()->subDay() | ||
] | ||
)); | ||
|
||
dispatch_now(CreateContent::content( | ||
'Content Title published now', | ||
$language, | ||
$user, | ||
[ | ||
'is_active' => true, | ||
'published_at' => Carbon::now() | ||
] | ||
)); | ||
|
||
dispatch_now(CreateContent::content( | ||
'Content Title published tomorrow', | ||
$language, | ||
$user, | ||
[ | ||
'is_active' => true, | ||
'published_at' => Carbon::tomorrow() | ||
] | ||
)); | ||
|
||
$I->sendGET(apiUrl('public-contents')); | ||
|
||
$I->seeResponseCodeIs(200); | ||
$I->seeResponseIsJson(); | ||
$I->seeResponseJsonMatchesJsonPath('data[*]'); | ||
$I->dontSeeResponseContainsJson( | ||
[ | ||
[ | ||
'type' => 'content', | ||
'translations' => [ | ||
[ | ||
'language_code' => 'en', | ||
'title' => 'Content Title published tomorrow', | ||
'is_active' => true, | ||
] | ||
] | ||
] | ||
] | ||
); | ||
$I->seeResponseContainsJson( | ||
[ | ||
[ | ||
'type' => 'content', | ||
'translations' => [ | ||
[ | ||
'language_code' => 'en', | ||
'title' => 'Content Title published one day ago', | ||
'is_active' => true, | ||
] | ||
] | ||
], | ||
[ | ||
'type' => 'content', | ||
'translations' => [ | ||
[ | ||
'language_code' => 'en', | ||
'title' => 'Content Title published now', | ||
'is_active' => true, | ||
] | ||
] | ||
] | ||
] | ||
); | ||
} | ||
} |
Oops, something went wrong.