diff --git a/plugins/baser-core/tests/TestCase/Service/Admin/ContentsAdminServiceTest.php b/plugins/baser-core/tests/TestCase/Service/Admin/ContentsAdminServiceTest.php index a3e7754867..35427df271 100644 --- a/plugins/baser-core/tests/TestCase/Service/Admin/ContentsAdminServiceTest.php +++ b/plugins/baser-core/tests/TestCase/Service/Admin/ContentsAdminServiceTest.php @@ -81,7 +81,8 @@ public function testGetType(): void 'ContentFolder' => 'フォルダー', 'ContentAlias' => 'エイリアス', 'Page' => '固定ページ', - 'BlogContent' => 'ブログ' + 'BlogContent' => 'ブログ', + 'ContentLink' => 'リンク' ]; $this->assertEquals($expected, $this->ContentsAdmin->getTypes()); } diff --git a/plugins/bc-blog/src/Controller/Admin/BlogPostsController.php b/plugins/bc-blog/src/Controller/Admin/BlogPostsController.php index 26d43a8538..0715cf120e 100755 --- a/plugins/bc-blog/src/Controller/Admin/BlogPostsController.php +++ b/plugins/bc-blog/src/Controller/Admin/BlogPostsController.php @@ -40,12 +40,13 @@ class BlogPostsController extends BlogAdminAppController /** * initialize - * + * * ブログ記事に関する処理の初期化を行う - * + * * @return void * @checked * @noTodo + * @unitTest */ public function initialize(): void { @@ -94,7 +95,7 @@ public function beforeFilter(EventInterface $event) /** * [ADMIN] ブログ記事一覧表示 - * + * * ブログ記事の一覧を表示する。 * ページネーションで次の記事が見つからなかった場合は、1ページ目にリダイレクトする。 * @@ -144,9 +145,9 @@ public function index(BlogPostsAdminServiceInterface $service, int $blogContentI /** * [ADMIN] ブログ記事追加処理 - * + * * 指定したブログに記事を追加して、ブログ記事編集画面へリダイレクトする。 - * + * * ###エラー * ブログ記事の追加に失敗した場合、PersistenceFailedExceptionかBcExceptionが発生する。 * @@ -198,7 +199,7 @@ public function add(BlogPostsAdminServiceInterface $service, int $blogContentId) /** * [ADMIN] ブログ記事編集処理 - * + * * 指定したブログ記事を編集する。 * 記事の保存に失敗した場合、PersistenceFailedExceptionかBcExceptionのエラーが発生する。 * @@ -248,7 +249,7 @@ public function edit(BlogPostsAdminServiceInterface $service, int $blogContentId /** * [ADMIN] ブログ記事削除処理 - * + * * 指定したブログ記事を削除し、ブログ記事一覧へリダイレクトする。 * * @param BlogPostsServiceInterface $service @@ -273,7 +274,7 @@ public function delete(BlogPostsServiceInterface $service, int $blogContentId, i /** * [ADMIN] ブログ記事を非公開状態にする - * + * * 指定したブログ記事を非公開にしてブログ記事一覧へリダイレクトする。 * * @param string $blogContentId @@ -297,7 +298,7 @@ public function unpublish(BlogPostsServiceInterface $service, $blogContentId, $i /** * [ADMIN] ブログ記事を公開状態にする - * + * * 指定したブログ記事を公開状態にしてブログ記事一覧にリダイレクトする。 * * @param string $blogContentId @@ -321,7 +322,7 @@ public function publish(BlogPostsServiceInterface $service, $blogContentId, $id) /** * [ADMIN] コピー - * + * * 指定したブログ記事をコピーする。 * HTTPメソッドがGETの場合はコピー処理は行わず、ブログ記事一覧へリダイレクトする。 * diff --git a/plugins/bc-blog/src/Controller/Admin/BlogTagsController.php b/plugins/bc-blog/src/Controller/Admin/BlogTagsController.php index 9c41ff6b1a..463e17470d 100755 --- a/plugins/bc-blog/src/Controller/Admin/BlogTagsController.php +++ b/plugins/bc-blog/src/Controller/Admin/BlogTagsController.php @@ -30,12 +30,13 @@ class BlogTagsController extends BlogAdminAppController /** * initialize - * + * * Admin/BlogTagsControllerの初期化を行う - * + * * @return void * @checked * @noTodo + * @unitTest */ public function initialize(): void { @@ -45,7 +46,7 @@ public function initialize(): void /** * [ADMIN] ブログタグ一覧 - * + * * ブログのタグ一覧を表示する。 * ページネーションによる遷移先でレコードがなければ1ページ目にリダイレクトする。 * @@ -76,7 +77,7 @@ public function index(BlogTagsServiceInterface $service, $blogContentId = []) * * ブロブのタグを登録する。 * 登録に成功した場合、タグの一覧へリダイレクトする。 - * + * * @param BlogTagsService $service * @return void */ @@ -104,7 +105,7 @@ public function add(BlogTagsServiceInterface $service) * [ADMIN] ブログタグ編集 * * 指定したブログのタグを編集し、ブログのタグ一覧へリダイレクトする - * + * * @param BlogTagsService $service * @param int $id タグID * @return void @@ -135,7 +136,7 @@ public function edit(BlogTagsServiceInterface $service, $id) * [ADMIN] ブログタグの削除処理 * * 指定したブログのタグを削除して、ブログのタグ一覧へリダイレクトする。 - * + * * @param BlogTagsService $service * @param int $id * @return void diff --git a/plugins/bc-blog/src/Controller/Api/BlogCommentsController.php b/plugins/bc-blog/src/Controller/Api/BlogCommentsController.php index a28760da15..9a75585fdf 100644 --- a/plugins/bc-blog/src/Controller/Api/BlogCommentsController.php +++ b/plugins/bc-blog/src/Controller/Api/BlogCommentsController.php @@ -29,7 +29,7 @@ class BlogCommentsController extends BcApiController * * 指定したブログのコメントに対して削除、公開、非公開の処理を一括で行う * - * ###エラー + * ### エラー * 受け取ったPOSTデータのキー名'batch'が'delete','publish','unpublish'以外の値であれば500エラーを発生させる * * @param BlogCommentsService $service diff --git a/plugins/bc-blog/src/Controller/Api/BlogPostsController.php b/plugins/bc-blog/src/Controller/Api/BlogPostsController.php index dba6d40930..743bc2db8f 100644 --- a/plugins/bc-blog/src/Controller/Api/BlogPostsController.php +++ b/plugins/bc-blog/src/Controller/Api/BlogPostsController.php @@ -24,7 +24,12 @@ class BlogPostsController extends BcApiController { /** - * バッチ処理 + * ブログ記事のバッチ処理 + * + * 指定したブログ記事に対して削除、公開、非公開の処理を一括で行う + * + * ### エラー + * 受け取ったPOSTデータのキー名'batch'が'delete','publish','unpublish'以外の値であれば500エラーを発生させる * * @param BlogPostsServiceInterface $service * @checked diff --git a/plugins/bc-blog/src/Controller/Api/BlogTagsController.php b/plugins/bc-blog/src/Controller/Api/BlogTagsController.php index 83c19e0eb6..f74594c028 100644 --- a/plugins/bc-blog/src/Controller/Api/BlogTagsController.php +++ b/plugins/bc-blog/src/Controller/Api/BlogTagsController.php @@ -26,7 +26,11 @@ class BlogTagsController extends BcApiController { /** - * [ADMIN] タグ登録 + * [ADMIN] ブログタグ登録 + * + * ブログのタグを登録する + * ブログタグの登録に失敗した場合、HTTPレスポンスのステータスに400を返します。 + * */ public function add(BlogTagsServiceInterface $service) { @@ -50,7 +54,13 @@ public function add(BlogTagsServiceInterface $service) } /** - * バッチ処理 + * ブログタグのバッチ処理 + * + * 指定したブログのコメントに対して削除処理を一括で行う + * + * ### エラー + * delete以外のHTTPメソッドには500エラーを返す + * 一括処理に失敗すると400エラーを返す * * @param BlogTagsService $service * @checked diff --git a/plugins/bc-blog/tests/TestCase/Controller/Admin/BlogPostsControllerTest.php b/plugins/bc-blog/tests/TestCase/Controller/Admin/BlogPostsControllerTest.php index 2b1399e235..66e9150bee 100755 --- a/plugins/bc-blog/tests/TestCase/Controller/Admin/BlogPostsControllerTest.php +++ b/plugins/bc-blog/tests/TestCase/Controller/Admin/BlogPostsControllerTest.php @@ -73,7 +73,7 @@ public function tearDown(): void */ public function testInitialize(): void { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->assertNotEmpty($this->BlogPostsController->BcAdminContents); } /** diff --git a/plugins/bc-blog/tests/TestCase/Controller/Admin/BlogTagsControllerTest.php b/plugins/bc-blog/tests/TestCase/Controller/Admin/BlogTagsControllerTest.php index 39eb7934ec..b6ff05bef8 100755 --- a/plugins/bc-blog/tests/TestCase/Controller/Admin/BlogTagsControllerTest.php +++ b/plugins/bc-blog/tests/TestCase/Controller/Admin/BlogTagsControllerTest.php @@ -1,6 +1,5 @@ * Copyright (c) baserCMS Users Community @@ -12,25 +11,52 @@ * @license https://basercms.net/license/index.html */ -App::uses('BlogTagsController', 'BcBlog.Controller'); +namespace BcBlog\Test\TestCase\Controller\Admin; + +use BaserCore\Test\Scenario\InitAppScenario; +use BaserCore\TestSuite\BcTestCase; +use BcBlog\Controller\Admin\BlogTagsController; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; /** * Class BlogTagsControllerTest * - * @package Blog.Test.Case.Controller - * @property BlogTagsController $BlogTagsController + * @property BlogTagsController $BlogTagsController */ -class BlogTagsControllerTest extends BaserTestCase +class BlogTagsControllerTest extends BcTestCase { + /** + * Trait + */ + use ScenarioAwareTrait; + + /** + * Fixtures + * + * @var array + */ + public $fixtures = [ + 'plugin.BaserCore.Factory/Sites', + 'plugin.BaserCore.Factory/SiteConfigs', + 'plugin.BaserCore.Factory/Users', + 'plugin.BaserCore.Factory/UsersUserGroups', + 'plugin.BaserCore.Factory/UserGroups', + 'plugin.BcBlog.Factory/BlogPosts', + 'plugin.BcBlog.Factory/BlogTags', + ]; + /** * set up * * @return void */ - public function setUp() + public function setUp(): void { + $this->setFixtureTruncate(); parent::setUp(); + $this->loadFixtureScenario(InitAppScenario::class); + $this->BlogTagsController = new BlogTagsController($this->loginAdmin($this->getRequest())); } /** @@ -38,55 +64,47 @@ public function setUp() * * @return void */ - public function tearDown() + public function tearDown(): void { parent::tearDown(); } /** - * [ADMIN] タグ一覧 - */ - public function testAdmin_index() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * [ADMIN] タグ登録 + * test index */ - public function testAdmin_add() + public function test_initialize() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->assertNotEmpty($this->BlogTagsController->BcAdminContents); } /** - * [ADMIN] タグ編集 + * test add */ - public function testAdmin_edit() + public function test_add(): void { $this->markTestIncomplete('このテストは、まだ実装されていません。'); } /** - * [ADMIN] 削除処理 + * test delete */ - public function testAdmin_delete() + public function test_delete() { $this->markTestIncomplete('このテストは、まだ実装されていません。'); } /** - * [ADMIN] 削除処理 (ajax) + * test edit */ - public function testAdmin_ajax_delete() + public function test_edit() { $this->markTestIncomplete('このテストは、まだ実装されていません。'); } /** - * [ADMIN] AJAXタグ登録 + * test index */ - public function testAdmin_ajax_add() + public function test_index() { $this->markTestIncomplete('このテストは、まだ実装されていません。'); } diff --git a/plugins/bc-content-link/src/Controller/Api/ContentLinksController.php b/plugins/bc-content-link/src/Controller/Api/ContentLinksController.php index 3052ba3e65..4947c632b8 100644 --- a/plugins/bc-content-link/src/Controller/Api/ContentLinksController.php +++ b/plugins/bc-content-link/src/Controller/Api/ContentLinksController.php @@ -60,7 +60,7 @@ public function add(ContentLinksServiceInterface $service) $message = __d('baser', 'リンク「{0}」を追加しました。', $entity->content->title); } catch (\Cake\ORM\Exception\PersistenceFailedException $e) { $entity = $e->getEntity(); - $message = __d('baser', "入力エラーです。内容を修正してください。\n"); + $message = __d('baser', "入力エラーです。内容を修正してください。"); $this->setResponse($this->response->withStatus(400)); } $this->set([ @@ -164,4 +164,46 @@ public function delete(ContentLinksServiceInterface $service, $id) $this->viewBuilder()->setOption('serialize', ['message', 'contentLink', 'errors']); } + /** + * コンテンツリンク取得 + * + * /baser/api/bc-content-link/content_links/view/{id}.json + * + * クエリーパラーメーター + * - status: string 公開ステータス(初期値:publish) + * - `publish` 公開されたページ + * - `` 全て + * + * @param ContentLinksServiceInterface $service + * @param $id + * @checked + * @noTodo + * @unitTest + */ + public function view(ContentLinksServiceInterface $service, $id) + { + $this->request->allowMethod('get'); + $queryParams = $this->getRequest()->getQueryParams(); + if(isset($queryParams['status'])) { + if(!$this->Authentication->getIdentity()) throw new ForbiddenException(); + } + + $queryParams = array_merge($queryParams, [ + 'status' => 'publish' + ]); + + $contentLink = $message = null; + try { + $contentLink = $service->get($id, $queryParams); + } catch(\Exception $e) { + $this->setResponse($this->response->withStatus(401)); + $message = $e->getMessage(); + } + + $this->set([ + 'contentLink' => $contentLink, + 'message' => $message + ]); + $this->viewBuilder()->setOption('serialize', ['contentLink', 'message']); + } } diff --git a/plugins/bc-content-link/tests/TestCase/Controller/Api/ContentLinksControllerTest.php b/plugins/bc-content-link/tests/TestCase/Controller/Api/ContentLinksControllerTest.php index 6491fb88c0..e1670173d4 100644 --- a/plugins/bc-content-link/tests/TestCase/Controller/Api/ContentLinksControllerTest.php +++ b/plugins/bc-content-link/tests/TestCase/Controller/Api/ContentLinksControllerTest.php @@ -73,6 +73,39 @@ public function tearDown(): void parent::tearDown(); } + /** + * test add + */ + public function test_add() + { + $data = [ + 'url' => '/test-add', + 'content' => [ + 'plugin' => 'BcContentLink', + 'type' => 'ContentLink', + 'site_id' => 1, + 'title' => 'test add link', + 'lft' => 1, + 'rght' => 2, + 'entity_id' => 1, + ] + ]; + $this->post('/baser/api/bc-content-link/content_links/add.json?token=' . $this->accessToken, $data); + $this->assertResponseOk(); + $result = json_decode((string)$this->_response->getBody()); + $this->assertEquals('リンク「test add link」を追加しました。', $result->message); + $this->assertEquals('BcContentLink', $result->content->plugin); + $this->assertEquals('/test-add', $result->contentLink->url); + + $data = [ + 'url' => '/test-add', + ]; + $this->post('/baser/api/bc-content-link/content_links/add.json?token=' . $this->accessToken, $data); + $this->assertResponseCode(400); + $result = json_decode((string)$this->_response->getBody()); + $this->assertEquals('入力エラーです。内容を修正してください。', $result->message); + $this->assertEquals('関連するコンテンツがありません', $result->errors->content->_required); + } /** * test edit */