From 932176935191cb2f4014b4f58e597b67dfa6f547 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Fri, 24 Feb 2023 13:31:48 +0900 Subject: [PATCH 01/16] =?UTF-8?q?test:=20Github=20Action=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9501566..7cfa881 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -44,6 +44,7 @@ jobs: MYSQL_VERSION: ${{ matrix.mysql }} MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: cakephp_test + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 From 32b2e4564d3da4f1e9fbfacf768af46e90fdd08b Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Sat, 25 Feb 2023 20:57:05 +0900 Subject: [PATCH 02/16] change: Version number to 3.3.6 --- VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index fa7adc7..9c25013 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -3.3.5 +3.3.6 From 81559b11547c9dc239df4207409f3426bd3671a2 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Thu, 6 Apr 2023 18:28:56 +0900 Subject: [PATCH 03/16] =?UTF-8?q?fix:=20=E5=AD=90=E8=A8=98=E4=BA=8B?= =?UTF-8?q?=E3=81=8C=E3=81=82=E3=82=8B=E3=81=A8=E3=80=81=E3=83=AD=E3=82=B0?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=81=97=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=81=A7=E3=82=82(0=E6=9C=AA?= =?UTF-8?q?=E6=89=BF=E8=AA=8D)=E3=81=8C=E8=A1=A8=E7=A4=BA=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=A6=E3=81=84=E3=81=9F=E3=81=9F=E3=82=81=E3=80=81?= =?UTF-8?q?=E6=9C=AA=E6=89=BF=E8=AA=8D=E8=A8=98=E4=BA=8B=E3=81=8C=E3=81=AA?= =?UTF-8?q?=E3=81=91=E3=82=8C=E3=81=B0=E8=A1=A8=E7=A4=BA=E3=81=97=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- View/Elements/BbsArticles/all/index_bbs_article.ctp | 2 +- View/Elements/BbsArticles/flat/index_bbs_article.ctp | 2 +- View/Elements/BbsArticles/root/index_bbs_article.ctp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/View/Elements/BbsArticles/all/index_bbs_article.ctp b/View/Elements/BbsArticles/all/index_bbs_article.ctp index cb37348..f5583cf 100644 --- a/View/Elements/BbsArticles/all/index_bbs_article.ctp +++ b/View/Elements/BbsArticles/all/index_bbs_article.ctp @@ -26,7 +26,7 @@
- +
- +
- + Date: Thu, 6 Apr 2023 19:05:36 +0900 Subject: [PATCH 04/16] =?UTF-8?q?fix:=20=E6=8E=B2=E7=A4=BA=E6=9D=BF?= =?UTF-8?q?=E3=81=A7=E3=80=81=E5=85=AC=E9=96=8B=E6=A8=A9=E9=99=90=E3=81=8C?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=83=A6=E3=83=BC=E3=82=B6=E8=BF=94=E4=BF=A1?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=81=A8=E3=80=81=E8=A1=A8=E7=A4=BA=E3=83=BB?= =?UTF-8?q?=E7=B7=A8=E9=9B=86=E3=83=BB=E5=89=8A=E9=99=A4=E3=81=8C=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=81=AA=E3=81=8F=E3=81=AA=E3=81=A3=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=9F=E3=81=9F=E3=82=81=E4=BF=AE=E6=AD=A3=20https://github.?= =?UTF-8?q?com/researchmap/RmNetCommons3/issues/2806?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/BbsArticlesController.php | 21 +++++++++++---------- Model/BbsArticle.php | 21 ++++++++++++++++++--- Model/Behavior/BbsArticleBehavior.php | 4 ++-- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Controller/BbsArticlesController.php b/Controller/BbsArticlesController.php index 4ddb506..ac16d11 100644 --- a/Controller/BbsArticlesController.php +++ b/Controller/BbsArticlesController.php @@ -50,7 +50,8 @@ class BbsArticlesController extends BbsesAppController { 'NetCommons.Permission' => array( //アクセスの権限 'allow' => array( - 'add,edit,delete' => 'content_creatable', + 'add' => 'content_creatable', + 'edit,delete' => 'content_comment_creatable', 'reply' => 'content_comment_creatable', 'approve' => 'content_comment_publishable', ), @@ -105,7 +106,7 @@ public function index() { $query['conditions'] = $this->BbsArticle->getWorkflowConditions(array( 'BbsArticleTree.parent_id' => null, 'BbsArticle.bbs_key' => $this->viewVars['bbs']['key'], - )); + ), true); //ソート $options = array( @@ -215,7 +216,7 @@ public function view() { $this->BbsArticle->alias . '.bbs_key' => $this->viewVars['bbs']['key'], $this->BbsArticle->alias . '.key' => $bbsArticleKey ) - )); + ), true); if (! $bbsArticle) { return $this->throwBadRequest(); } @@ -242,7 +243,7 @@ public function view() { //子記事の取得 $this->BbsArticleTree->Behaviors->load('Tree', array( - 'scope' => $this->BbsArticle->getWorkflowConditions() + 'scope' => $this->BbsArticle->getWorkflowConditions([], true) )); if ($this->viewVars['bbsFrameSetting']['display_type'] === BbsFrameSetting::DISPLAY_TYPE_FLAT) { @@ -324,7 +325,7 @@ public function reply() { $this->BbsArticle->alias . '.bbs_key' => $this->viewVars['bbs']['key'], $this->BbsArticle->alias . '.key' => $bbsArticleKey ) - )); + ), true); if (!isset($bbsArticle['BbsArticle']['status']) || $bbsArticle['BbsArticle']['status'] !== WorkflowComponent::STATUS_PUBLISHED) { @@ -399,7 +400,7 @@ public function edit() { $this->BbsArticle->alias . '.bbs_key' => $this->viewVars['bbs']['key'], $this->BbsArticle->alias . '.key' => $bbsArticleKey ) - )); + ), true); if (empty($bbsArticle)) { return $this->throwBadRequest(); } @@ -451,7 +452,7 @@ public function delete() { $this->BbsArticle->alias . '.bbs_key' => $this->viewVars['bbs']['key'], $this->BbsArticle->alias . '.key' => $this->data['BbsArticle']['key'] ) - )); + ), true); //削除権限チェック if (! $this->BbsArticle->canDeleteWorkflowContent($bbsArticle)) { @@ -465,7 +466,7 @@ public function delete() { 'conditions' => array( $this->BbsArticleTree->alias . '.id' => $bbsArticle['BbsArticleTree']['parent_id'], ) - )); + ), true); if (! $parentBbsArticle) { return $this->throwBadRequest(); } @@ -502,7 +503,7 @@ public function approve() { $this->BbsArticle->alias . '.bbs_key' => $this->data['BbsArticle']['bbs_key'], $this->BbsArticle->alias . '.key' => $this->data['BbsArticle']['key'] ) - )); + ), true); if (! $bbsArticle) { return $this->throwBadRequest(); } @@ -597,7 +598,7 @@ private function __setBbsArticleByTreeId($viewVarsKey, $bbsArticleTreeId) { 'conditions' => array( $this->BbsArticleTree->alias . '.id' => $bbsArticleTreeId, ) - )); + ), true); if (! $bbsArticle) { return false; } diff --git a/Model/BbsArticle.php b/Model/BbsArticle.php index 79dc5ee..a623896 100644 --- a/Model/BbsArticle.php +++ b/Model/BbsArticle.php @@ -282,8 +282,6 @@ public function saveBbsArticle($data) { * @throws InternalErrorException */ public function deleteBbsArticle($data) { - //トランザクションBegin - $this->begin(); $this->set($data); $bbsArticleTree = $this->BbsArticleTree->find('first', array( @@ -308,6 +306,8 @@ public function deleteBbsArticle($data) { ), )); + //トランザクションBegin + $this->begin(); try { //BbsArticleの削除 $this->contentKey = $bbsArticleTrees; @@ -331,6 +331,14 @@ public function deleteBbsArticle($data) { $data['Bbs']['key'], $data['BbsArticle']['language_id'] ); + if (isset($this->data['BbsArticleTree']['root_id']) && + $this->data['BbsArticleTree']['root_id']) { + $this->updateBbsArticleChildCount( + $this->data['BbsArticleTree']['root_id'], + $this->data[$this->alias]['language_id'] + ); + } + //トランザクションCommit $this->commit(); @@ -370,7 +378,14 @@ public function canEditWorkflowContent($data) { if ($childArticle) { return false; } - return (Current::permission('content_creatable') && + + if (empty($data['BbsArticleTree']['root_id'])) { + $permission = 'content_creatable'; + } else { + $permission = 'content_comment_creatable'; + } + + return (Current::permission($permission) && ((int)$data['BbsArticle']['created_user'] === (int)Current::read('User.id'))); } diff --git a/Model/Behavior/BbsArticleBehavior.php b/Model/Behavior/BbsArticleBehavior.php index 4776a40..cbd53e2 100644 --- a/Model/Behavior/BbsArticleBehavior.php +++ b/Model/Behavior/BbsArticleBehavior.php @@ -156,7 +156,7 @@ public function getChildrenArticleCounts(Model $model, $bbsKey, $bbsArticles, $a 'conditions' => $model->getWorkflowConditions(array( 'BbsArticleTree.root_id' => $articleTreeIds, 'BbsArticleTree.bbs_key' => $bbsKey, - )), + ), true), 'joins' => [ [ 'type' => 'INNER', @@ -213,7 +213,7 @@ public function getChildrenArticleTitles(Model $model, $articleTreeIds) { ], $trackable), 'conditions' => $model->getWorkflowConditions(array( 'BbsArticleTree.root_id' => $articleTreeIds, - )), + ), true), ); $results = $model->find('all', $query); From e4fc30c1c19a99f3bd6075a7694892b5c06f3210 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Thu, 6 Apr 2023 19:10:09 +0900 Subject: [PATCH 05/16] =?UTF-8?q?fix:=20=E8=A8=98=E4=BA=8B=E8=A9=B3?= =?UTF-8?q?=E7=B4=B0=E3=82=92=E8=A1=A8=E7=A4=BA=E3=81=97=E3=81=9F=E3=81=A8?= =?UTF-8?q?=E3=81=8D=E3=81=AE=E8=BF=94=E4=BF=A1=E3=81=A7=E8=A6=AA=E8=A8=98?= =?UTF-8?q?=E4=BA=8B=E3=82=92=E7=A4=BA=E3=81=99=E3=80=8C>>=201=E3=80=8D?= =?UTF-8?q?=E3=81=AE=E8=A1=A8=E7=A4=BA=E3=81=8C=E3=81=9A=E3=82=8C=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=9F=E3=83=90=E3=82=B0=E4=BF=AE=E6=AD=A3=20https:?= =?UTF-8?q?//github.com/researchmap/RmNetCommons3/issues/2806?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/BbsArticlesController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/BbsArticlesController.php b/Controller/BbsArticlesController.php index ac16d11..31ab71e 100644 --- a/Controller/BbsArticlesController.php +++ b/Controller/BbsArticlesController.php @@ -270,7 +270,7 @@ public function view() { $bbsArticleChildren[$child['BbsArticleTree']['id']] = $child; } - $this->set('bbsArticleChildren', $children); + $this->set('bbsArticleChildren', $bbsArticleChildren); } /** From baf6dcd61058d9196176bf2fe957a167343c7797 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Fri, 7 Apr 2023 09:24:04 +0900 Subject: [PATCH 06/16] =?UTF-8?q?test:=20=E3=80=8CWaiting=20for=20a=20runn?= =?UTF-8?q?er=20to=20pick=20up=20this=20job...=E3=80=8D=E3=81=8C=E3=81=A7?= =?UTF-8?q?=E3=81=A6Github=20Action=E3=81=8C=E5=8B=95=E3=81=8B=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=81=9F=E3=82=81=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7cfa881..3b2212b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,7 @@ name: tests jobs: setup: name: setup - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - name: Slack Notification on Start uses: rtCamp/action-slack-notify@v2.2.0 @@ -28,7 +28,7 @@ jobs: tests: name: tests needs: setup - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest strategy: matrix: php: [ '7.1', '7.2', '7.3', '7.4' ] @@ -148,7 +148,7 @@ jobs: teardown: name: teardown - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest needs: tests steps: # テスト成功時はこちらのステップが実行される From 99cfea12d0b5b25637529e74521f38065db75b7f Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Fri, 7 Apr 2023 09:50:05 +0900 Subject: [PATCH 07/16] =?UTF-8?q?test:=20github=20action=E3=81=A7=E9=80=94?= =?UTF-8?q?=E4=B8=AD=E3=81=A7=E3=82=A8=E3=83=A9=E3=83=BC=E3=81=AB=E3=81=AA?= =?UTF-8?q?=E3=81=A3=E3=81=A6=E3=82=82=E5=BE=8C=E7=B6=9A=E3=81=AB=E9=80=B2?= =?UTF-8?q?=E3=82=80=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/tests.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3b2212b..77f9121 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -92,37 +92,44 @@ jobs: docker-compose exec -T nc3app bash /opt/scripts/app-build.sh - name: phpcs (PHP CodeSniffer) + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose exec -T nc3app bash /opt/scripts/phpcs.sh - name: phpmd (PHP Mess Detector) + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose exec -T nc3app bash /opt/scripts/phpmd.sh - name: phpcpd (PHP Copy/Paste Detector) + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose exec -T nc3app bash /opt/scripts/phpcpd.sh - name: gjslint (JavaScript Style Check) + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose exec -T nc3app bash /opt/scripts/gjslint.sh - name: phpdoc (PHP Documentor) + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose exec -T nc3app bash /opt/scripts/phpdoc.sh - name: phpunit (PHP UnitTest) + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose exec -T nc3app bash /opt/scripts/phpunit.sh sudo -s chmod a+w -R ${NC3_BUILD_DIR}/build - name: push coveralls + if: success() env: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} COVERALLS_FLAG_NAME: ${{ matrix.php }} @@ -132,6 +139,7 @@ jobs: vendors/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v - name: docker-compose remove + if: always() run: | cd ${NC3_DOCKER_DIR} docker-compose rm -f From 6bd6f36b9ccb62bab48ce623536ffd494bfea54a Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Mon, 10 Apr 2023 21:25:07 +0900 Subject: [PATCH 08/16] =?UTF-8?q?fix:=20=E3=82=B3=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=81=AE=E3=81=BF=E6=89=BF=E8=AA=8D=E3=81=82=E3=82=8A?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=A6=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=A6=E3=82=82=E5=8D=B3?= =?UTF-8?q?=E6=99=82=E5=85=AC=E9=96=8B=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=86=E3=83=90=E3=82=B0=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=20https://github.com/researchmap/RmNetCommons3/issues/2806#iss?= =?UTF-8?q?uecomment-1501429547?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/BbsArticle.php | 2 +- Model/Behavior/BbsesWorkflowBehavior.php | 62 +++++++++++++++++++ .../BbsArticlesController/ViewTest.php | 10 +-- .../Model/BbsArticle/SaveBbsArticleTest.php | 38 ++++++++++++ View/Elements/BbsArticles/edit_form.ctp | 22 ++++--- View/Helper/BbsesFormHelper.php | 12 +--- 6 files changed, 121 insertions(+), 25 deletions(-) create mode 100644 Model/Behavior/BbsesWorkflowBehavior.php diff --git a/Model/BbsArticle.php b/Model/BbsArticle.php index a623896..86a6a54 100644 --- a/Model/BbsArticle.php +++ b/Model/BbsArticle.php @@ -54,7 +54,7 @@ class BbsArticle extends BbsesAppModel { 'Likes.Like', 'NetCommons.OriginalKey', 'Workflow.WorkflowComment', - 'Workflow.Workflow', + 'Bbses.BbsesWorkflow', 'Mails.MailQueue' => array( 'embedTags' => array( 'X-SUBJECT' => 'BbsArticle.title', diff --git a/Model/Behavior/BbsesWorkflowBehavior.php b/Model/Behavior/BbsesWorkflowBehavior.php new file mode 100644 index 0000000..fc45d2d --- /dev/null +++ b/Model/Behavior/BbsesWorkflowBehavior.php @@ -0,0 +1,62 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('WorkflowBehavior', 'Workflow.Model/Behavior'); + +/** + * Workflow Behavior + * + * @author Shohei Nakajima + * @package Bbses\Workflow\Model\Befavior + */ +class BbsesWorkflowBehavior extends WorkflowBehavior { + +/** + * beforeValidate is called before a model is validated, you can use this callback to + * add behavior validation rules into a models validate array. Returning false + * will allow you to make the validation fail. + * + * @param Model $model Model using this behavior + * @param array $options Options passed from Model::save(). + * @return mixed False or null will abort the operation. Any other result will continue. + * @see Model::save() + */ + public function beforeValidate(Model $model, $options = array()) { + if (empty($model->data['BbsArticleTree']['root_id'])) { + return parent::beforeValidate($model, $options); + } + + if (Current::permission('content_comment_publishable')) { + $statuses = WorkflowBehavior::$statuses; + } else { + $statuses = WorkflowBehavior::$statusesForEditor; + } + + $model->validate = ValidateMerge::merge($model->validate, array( + 'status' => array( + 'numeric' => array( + 'rule' => array('numeric'), + 'message' => __d('net_commons', 'Invalid request.'), + 'allowEmpty' => false, + 'required' => true, + 'on' => 'create', // Limit validation to 'create' or 'update' operations + ), + 'inList' => array( + 'rule' => array('inList', $statuses), + 'message' => __d('net_commons', 'Invalid request.'), + ) + ), + )); + + return true; + } + +} diff --git a/Test/Case/Controller/BbsArticlesController/ViewTest.php b/Test/Case/Controller/BbsArticlesController/ViewTest.php index f9a3843..bcaada4 100644 --- a/Test/Case/Controller/BbsArticlesController/ViewTest.php +++ b/Test/Case/Controller/BbsArticlesController/ViewTest.php @@ -288,11 +288,11 @@ public function dataProviderViewByEditable() { */ public function testViewError($urlOptions, $assert, $exception = null, $return = 'view') { //Exception - ClassRegistry::removeObject('WorkflowBehavior'); - $workflowBehaviorMock = $this->getMock('WorkflowBehavior', ['canReadWorkflowContent']); - ClassRegistry::addObject('WorkflowBehavior', $workflowBehaviorMock); - $this->BbsArticle->Behaviors->unload('Workflow'); - $this->BbsArticle->Behaviors->load('Workflow', $this->BbsArticle->actsAs['Workflow.Workflow']); + ClassRegistry::removeObject('BbsesWorkflowBehavior'); + $workflowBehaviorMock = $this->getMock('BbsesWorkflowBehavior', ['canReadWorkflowContent']); + ClassRegistry::addObject('BbsesWorkflowBehavior', $workflowBehaviorMock); + $this->BbsArticle->Behaviors->unload('BbsesWorkflow'); + $this->BbsArticle->Behaviors->load('BbsesWorkflow', $this->BbsArticle->actsAs['Bbses.BbsesWorkflow']); $workflowBehaviorMock ->expects($this->once()) diff --git a/Test/Case/Model/BbsArticle/SaveBbsArticleTest.php b/Test/Case/Model/BbsArticle/SaveBbsArticleTest.php index e2b1116..b789078 100644 --- a/Test/Case/Model/BbsArticle/SaveBbsArticleTest.php +++ b/Test/Case/Model/BbsArticle/SaveBbsArticleTest.php @@ -129,6 +129,8 @@ public function setUp() { Current::write('Language.id', '2'); parent::setUp(); + Current::writePermission('2', 'content_comment_publishable', true); + $model = $this->_modelName; $this->$model->Behaviors->unload('Like'); $this->$model->Behaviors->unload('Topics'); @@ -136,6 +138,42 @@ public function setUp() { $this->$model->BbsArticleTree->Behaviors->unload('Like'); } +/** + * Test to call BbsesWorkflowBehavior::beforeSave + * + * BbsesWorkflowBehaviorをモックに置き換えて登録処理を呼び出します。
+ * BbsesWorkflowBehavior::beforeSaveが1回呼び出されることをテストします。
+ * ##### 参考URL + * http://stackoverflow.com/questions/19833495/how-to-mock-a-cakephp-behavior-for-unit-testing] + * + * @param array $data 登録データ + * @dataProvider dataProviderSave + * @return void + * @throws CakeException Workflow.Workflowがロードされていないとエラー + */ + public function testCallWorkflowBehavior($data) { + $model = $this->_modelName; + $method = $this->_methodName; + + if (! $this->$model->Behaviors->loaded('Bbses.BbsesWorkflow')) { + $error = '"Workflow.Workflow" not loaded in ' . $this->$model->alias . '.'; + throw new CakeException($error); + } + + ClassRegistry::removeObject('BbsesWorkflowBehavior'); + $workflowBehaviorMock = $this->getMock('BbsesWorkflowBehavior', ['beforeSave']); + ClassRegistry::addObject('BbsesWorkflowBehavior', $workflowBehaviorMock); + $this->$model->Behaviors->unload('BbsesWorkflow'); + $this->$model->Behaviors->load('BbsesWorkflow', $this->$model->actsAs['Bbses.BbsesWorkflow']); + + $workflowBehaviorMock + ->expects($this->once()) + ->method('beforeSave') + ->will($this->returnValue(true)); + + $this->$model->$method($data); + } + /** * SaveのDataProvider * diff --git a/View/Elements/BbsArticles/edit_form.ctp b/View/Elements/BbsArticles/edit_form.ctp index a16b613..44905a4 100644 --- a/View/Elements/BbsArticles/edit_form.ctp +++ b/View/Elements/BbsArticles/edit_form.ctp @@ -51,17 +51,19 @@
params['action'] === 'edit' && $this->data['BbsArticleTree']['root_id']) { - echo $this->BbsesForm->replyEditButtons('BbsArticle.status'); - } else { + if ($this->params['action'] === 'edit' && $this->data['BbsArticleTree']['root_id'] || + $this->params['action'] === 'reply') { if ($this->params['action'] === 'reply') { - $key = isset($currentBbsArticle['BbsArticle']['key']) - ? $currentBbsArticle['BbsArticle']['key'] - : null; - $cancelUrl = NetCommonsUrl::blockUrl( - array('action' => 'view', 'key' => $key) - ); - } elseif ($this->params['action'] === 'edit') { + $key = $currentBbsArticle['BbsArticle']['key'] ?? null; + } else { + $key = $this->request->data['BbsArticle']['key'] ?? null; + } + $cancelUrl = NetCommonsUrl::blockUrl( + array('action' => 'view', 'key' => $key) + ); + echo $this->BbsesForm->replyButtons('BbsArticle.status', $cancelUrl); + } else { + if ($this->params['action'] === 'edit') { $key = isset($this->request->data['BbsArticle']['key']) ? $this->request->data['BbsArticle']['key'] : null; diff --git a/View/Helper/BbsesFormHelper.php b/View/Helper/BbsesFormHelper.php index 547d833..1a53439 100644 --- a/View/Helper/BbsesFormHelper.php +++ b/View/Helper/BbsesFormHelper.php @@ -38,9 +38,10 @@ class BbsesFormHelper extends AppHelper { * 返信フォームのボタン表示 * * @param string $statusFieldName ステータスのフィールド名("Modelname.fieldname") + * @param string $cancelUrl キャンセルボタン * @return string ボタンHTML */ - public function replyEditButtons($statusFieldName) { + public function replyButtons($statusFieldName, $cancelUrl) { $output = ''; $output .= '