diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..592d72f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,59 @@ +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - '3*' + +name: create_release + +jobs: + build: + name: create_release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Slack Notification on Start + uses: rtCamp/action-slack-notify@v2.2.0 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_RELEASE }} + SLACK_CHANNEL: notify-nc3-release + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: "#f0ad4e" + SLACK_MESSAGE: "Start Job" + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + body: | + NetCommons ${{ github.ref }} released. + draft: false + prerelease: false + + # テスト成功時はこちらのステップが実行される + - name: Slack Notification on Finish + uses: rtCamp/action-slack-notify@v2.2.0 + if: success() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_RELEASE }} + SLACK_CHANNEL: notify-nc3-release + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: good + SLACK_MESSAGE: "Job Success" + + # テスト失敗時はこちらのステップが実行される + - name: Slack Notification on Failure + uses: rtCamp/action-slack-notify@v2.2.0 + if: failure() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_RELEASE }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: danger + SLACK_MESSAGE: "Job Failure" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..6da4321 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,168 @@ +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + +name: tests + +jobs: + setup: + name: setup + runs-on: ubuntu-latest + steps: + - name: Slack Notification on Start + uses: rtCamp/action-slack-notify@v2.2.0 + if: env.SLACK_WEBHOOK != '' + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: "#f0ad4e" + + tests: + name: tests + needs: setup + runs-on: ubuntu-latest + strategy: + matrix: + php: [ '7.1', '7.2', '7.3', '7.4' ] + mysql: [ '5.7', '8.0' ] + + env: + NC3_BUILD_DIR: "/opt/nc3" + NC3_DOCKER_DIR: "/opt/docker" + NC3_GIT_URL: "git://github.com/NetCommons3/NetCommons3.git" + NC3_GIT_BRANCH: "master" + PLUGIN_BUILD_DIR: ${{ github.workspace }} + PHP_VERSION: ${{ matrix.php }} + MYSQL_VERSION: ${{ matrix.mysql }} + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: cakephp_test + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v2 + + - name: Fix up git URLs + run: echo -e '[url "https://github.com/"]\n insteadOf = "git://github.com/"' >> ~/.gitconfig + + - name: environment + run: | + echo "GITHUB_WORKSPACE=${GITHUB_WORKSPACE}" + echo "PLUGIN_BUILD_DIR=${PLUGIN_BUILD_DIR}" + echo "PHP_VERSION=${PHP_VERSION}" + echo "MYSQL_VERSION=${MYSQL_VERSION}" + ls -al ${PLUGIN_BUILD_DIR} + + - name: docker-compose install + run: | + curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > ~/docker-compose + chmod +x ~/docker-compose + sudo mv ~/docker-compose /usr/local/bin/docker-compose + docker-compose --version + + - name: git clone nc3 + run: git clone -b ${NC3_GIT_BRANCH} ${NC3_GIT_URL} ${NC3_BUILD_DIR} + + - name: git clone nc3_docker + run: git clone https://github.com/NetCommons3/nc3app-docker.git ${NC3_DOCKER_DIR} + + - name: docker-compose start + run: | + cd ${NC3_DOCKER_DIR} + docker-compose up -d + docker-compose start + + - run: docker ps + + - name: check libraries + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/start-on-docker.sh + + - name: nc3 build + run: | + cd ${NC3_DOCKER_DIR} + 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 +# env: +# COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# COVERALLS_FLAG_NAME: ${{ matrix.php }} +# run: | +# cd ${NC3_BUILD_DIR} +# ls -la ${NC3_BUILD_DIR} +# 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 + + # テスト失敗時はこちらのステップが実行される + - name: Slack Notification on Failure + uses: rtCamp/action-slack-notify@v2.2.0 + if: env.SLACK_WEBHOOK != '' && failure() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}(php${{ matrix.php }}, mysql${{ matrix.mysql }})" + SLACK_COLOR: danger + + teardown: + name: teardown + runs-on: ubuntu-latest + needs: tests + steps: + # テスト成功時はこちらのステップが実行される + - name: Slack Notification on Success + uses: rtCamp/action-slack-notify@v2.2.0 + if: env.SLACK_WEBHOOK != '' && success() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: good diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 19508b2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ -language: php - -php: - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - 7.1 - -sudo: false - -env: - matrix: - - NETCOMMONS_VERSION=master DB=mysql - global: - - secure: "Zne29ern9LsmaFB4IXG/Qu794ansG0duVm020H4SwOeHF6+wvgOqvfW2HCvuyPD5ZBNvwvy7Zx6euIP0nrlv8HJCpJLGqgcIH6DiC978Nu+cELS05AzbHGYkMKakjXX1LJIybmoQWBMfIWGQgGpyXB31Nmzr+BbZpQGdFREs1U0MF2S300XO6UrIKfBnJQINdg/YzDW5jAjtFPh79vMO2zdTVrkBLuDYuj4GhmOwwa9RBvU8nBvsPGvlmCqnY/+Od22OWir3qQ2xIJGVO33fDQROiSYu42py+RoWTzFsi/MTU4vSYDhTLNRj8Fnq4xQ/KZRUcJp+cNxQ8+mcTlyH27U5Hx8DJx7bPqgB4zP7z7mnCqML0WwkZ8Vr3oohQ19RWWwoeevp2fL+2Ltcg4aKeVRsdm3GRF87AucSZEeOKkk9Ah4UQMFYeReazeltMRnzW1U4LqIkyU9+fxEcmZdk6PGpyllyTjP0DFg1JXLwNYkow5OuWeZSm+VMYxI4AH/Jfq3G2xIBpr42rxjGAe7lNReSUbcxclG/NhMCCXD4Dgd2p1r46Jh8bE9JOaK7t+WYsRj98Ah/ijBtpHzyEZ54SE67z3yiG1DnnhUQmkGuxSoz/hvk27uHvtUMPbWXdr6Rgu9T6L02hWZPm+XVzp4Iu4jyg4UliJEdCHuyThdIlwU=" - - GIT_COMMITTER_NAME=s-nakajima - - GIT_COMMITTER_EMAIL=nakajimashouhei@gmail.com - - GIT_AUTHOR_NAME=s-nakajima - - GIT_AUTHOR_EMAIL=nakajimashouhei@gmail.com - -before_script: - - export NETCOMMONS_BUILD_DIR=`dirname $TRAVIS_BUILD_DIR`/NetCommons3 - - git clone git://github.com/NetCommons3/NetCommons3 $NETCOMMONS_BUILD_DIR - - cd $NETCOMMONS_BUILD_DIR - - git checkout $NETCOMMONS_VERSION - - travis_wait . tools/build/plugins/cakephp/travis/pre.sh - - . tools/build/plugins/cakephp/travis/environment.sh - -script: - - . tools/build/plugins/cakephp/travis/main.sh - -after_script: - - . tools/build/plugins/cakephp/travis/post.sh - -notifications: - email: - recipients: - - netcommons3@googlegroups.com - on_success: never # default: change - on_failure: always # default: always diff --git a/Model/Behavior/WorkflowBehavior.php b/Model/Behavior/WorkflowBehavior.php index 54a402a..5d55d44 100644 --- a/Model/Behavior/WorkflowBehavior.php +++ b/Model/Behavior/WorkflowBehavior.php @@ -18,6 +18,7 @@ * * @author Shohei Nakajima * @package NetCommons\Workflow\Model\Befavior + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ class WorkflowBehavior extends ModelBehavior { @@ -126,7 +127,8 @@ public function beforeSave(Model $model, $options = array()) { //is_activeのセット $model->data[$model->alias]['is_active'] = false; - if ($model->data[$model->alias]['status'] === WorkflowComponent::STATUS_PUBLISHED) { + // 各プラグインで直にフラグをセットする場合 1 or '1'もありえるため、stringにキャストする + if ((string)$model->data[$model->alias]['status'] === WorkflowComponent::STATUS_PUBLISHED) { //statusが公開ならis_activeを付け替える $model->data[$model->alias]['is_active'] = true; @@ -174,7 +176,7 @@ public function beforeValidate(Model $model, $options = array()) { $statuses = self::$statusesForEditor; } - $model->validate = Hash::merge($model->validate, array( + $model->validate = ValidateMerge::merge($model->validate, array( 'status' => array( 'numeric' => array( 'rule' => array('numeric'), @@ -226,16 +228,23 @@ private function __hasSaveField(Model $model, $needle) { * * @param Model $model Model using this behavior * @param array $conditions Model::find conditions default value + * @param bool $useCommentCreatable コメントの作成権限でもチェックするかどうか * @return array Conditions data * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ - public function getWorkflowConditions(Model $model, $conditions = array()) { + public function getWorkflowConditions( + Model $model, + $conditions = array(), + $useCommentCreatable = false + ) { if (Current::permission('content_editable')) { $activeConditions = array(); $latestConditons = array( $model->alias . '.is_latest' => true, ); - } elseif (Current::permission('content_creatable')) { + } elseif (Current::permission('content_creatable') || + $useCommentCreatable && Current::permission('content_comment_creatable')) { $activeConditions = array( $model->alias . '.is_active' => true, $model->alias . '.created_user !=' => Current::read('User.id'), @@ -270,8 +279,7 @@ public function getWorkflowConditions(Model $model, $conditions = array()) { $model->alias . '.is_origin' => true, ); } elseif ($model->hasField('is_translation')) { - $langs = $model->Language->getLanguage(); - if (count($langs) > 1) { + if ($model->Language->isMultipleLang()) { $langConditions = array( 'OR' => array( $model->alias . '.language_id' => Current::read('Language.id'), @@ -292,7 +300,16 @@ public function getWorkflowConditions(Model $model, $conditions = array()) { $langConditions = array(); } + $currentBlockId = Current::read('Block.id'); + $blockConditions = []; + if ($currentBlockId && $model->hasField('block_id')) { + $blockConditions = [ + $model->alias . '.block_id' => $currentBlockId, + ]; + } + $conditions = Hash::merge( + $blockConditions, array( $langConditions, array('OR' => array($activeConditions, $latestConditons)) @@ -309,12 +326,19 @@ public function getWorkflowConditions(Model $model, $conditions = array()) { * @param Model $model Model using this behavior * @param string $type Type of find operation (all / first / count / neighbors / list / threaded) * @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks) + * @param bool $useCommentCreatable コメントの作成権限でもチェックするかどうか * @return array Conditions data + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ - public function getWorkflowContents(Model $model, $type, $query = array()) { + public function getWorkflowContents( + Model $model, + $type, + $query = array(), + $useCommentCreatable = false + ) { $query = Hash::merge(array( 'recursive' => -1, - 'conditions' => $this->getWorkflowConditions($model) + 'conditions' => $this->getWorkflowConditions($model, [], $useCommentCreatable) ), $query); return $model->find($type, $query); @@ -361,7 +385,8 @@ public function canEditWorkflowContent(Model $model, $data) { if (! isset($data[$model->alias]['created_user'])) { return false; } - return ((int)$data[$model->alias]['created_user'] === (int)Current::read('User.id')); + return (Current::permission('content_creatable') && + ((int)$data[$model->alias]['created_user'] === (int)Current::read('User.id'))); } /** @@ -374,7 +399,8 @@ public function canEditWorkflowContent(Model $model, $data) { * @return bool true:削除可、false:削除不可 */ public function canDeleteWorkflowContent(Model $model, $data) { - if (! $this->canEditWorkflowContent($model, $data)) { + //Model側で継承している場合、そのcanEditWorkflowContentが実行されるように、$thisではなく、$modelで呼び出す。 + if (! $model->canEditWorkflowContent($data)) { return false; } if (Current::permission('content_publishable')) { diff --git a/README.md b/README.md index 32e118e..53be543 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,6 @@ Workflow ============== -Workflow for NetComomns3 - -[![Build Status](https://api.travis-ci.org/NetCommons3/Workflow.png?branch=master)](https://travis-ci.org/NetCommons3/Workflow) -[![Coverage Status](https://coveralls.io/repos/NetCommons3/Workflow/badge.png?branch=master)](https://coveralls.io/r/NetCommons3/Workflow?branch=master) - -| dependencies | status | -| ------------- | ------ | -| composer.json | [![Dependency Status](https://www.versioneye.com/user/projects/55e64f4fe7e33d000c0007e9/badge.png)](https://www.versioneye.com/user/projects/55e64f4fe7e33d000c0007e9) | +[![Tests Status](https://github.com/NetCommons3/Workflow/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/NetCommons3/Workflow/actions/workflows/tests.yml) +[![Coverage Status](https://coveralls.io/repos/NetCommons3/Workflow/badge.svg?branch=master)](https://coveralls.io/r/NetCommons3/Workflow?branch=master) +[![Stable Version](https://img.shields.io/packagist/v/netcommons/workflow.svg?label=stable)](https://packagist.org/packages/netcommons/workflow) diff --git a/Test/Case/Model/Behavior/WorkflowBehavior/CanCreateWorkflowContentTest.php b/Test/Case/Model/Behavior/WorkflowBehavior/CanCreateWorkflowContentTest.php index 2404da0..b123033 100644 --- a/Test/Case/Model/Behavior/WorkflowBehavior/CanCreateWorkflowContentTest.php +++ b/Test/Case/Model/Behavior/WorkflowBehavior/CanCreateWorkflowContentTest.php @@ -72,7 +72,8 @@ public function dataProvider() { */ public function testCanCreateWorkflowContent($permission, $assert) { //テスト実施 - Current::$current['Permission']['content_creatable']['value'] = $permission; + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_creatable', $permission); $result = $this->TestModel->canCreateWorkflowContent(); //チェック diff --git a/Test/Case/Model/Behavior/WorkflowBehavior/CanDeleteWorkflowContentTest.php b/Test/Case/Model/Behavior/WorkflowBehavior/CanDeleteWorkflowContentTest.php index 030a012..abb1f1e 100644 --- a/Test/Case/Model/Behavior/WorkflowBehavior/CanDeleteWorkflowContentTest.php +++ b/Test/Case/Model/Behavior/WorkflowBehavior/CanDeleteWorkflowContentTest.php @@ -97,8 +97,9 @@ public function dataProvider() { public function testCanDeleteWorkflowContent($publishPermission, $editPermission, $assert, $userId, $data) { //テスト実施 Current::$current['User']['id'] = $userId; - Current::$current['Permission']['content_editable']['value'] = $editPermission; - Current::$current['Permission']['content_publishable']['value'] = $publishPermission; + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_editable', $editPermission); + Current::writePermission('2', 'content_publishable', $publishPermission); $result = $this->TestModel->canDeleteWorkflowContent($data); //チェック @@ -116,8 +117,9 @@ public function testCanDeleteWorkflowContentWOKeyField() { //テスト実施 Current::$current['User']['id'] = '1'; - Current::$current['Permission']['content_editable']['value'] = true; - Current::$current['Permission']['content_publishable']['value'] = false; + Current::writePermission('2', 'content_editable', true); + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_publishable', false); $data = array('TestWorkflowBehaviorModel' => array('key' => 'publish_key', 'created_user' => '2')); $result = $this->TestModel->canDeleteWorkflowContent($data); diff --git a/Test/Case/Model/Behavior/WorkflowBehavior/CanEditWorkflowContentTest.php b/Test/Case/Model/Behavior/WorkflowBehavior/CanEditWorkflowContentTest.php index b4aec8f..9c11277 100644 --- a/Test/Case/Model/Behavior/WorkflowBehavior/CanEditWorkflowContentTest.php +++ b/Test/Case/Model/Behavior/WorkflowBehavior/CanEditWorkflowContentTest.php @@ -90,7 +90,9 @@ public function dataProvider() { public function testCanEditWorkflowContent($permission, $assert, $userId, $data) { //テスト実施 Current::$current['User']['id'] = $userId; - Current::$current['Permission']['content_editable']['value'] = $permission; + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_editable', $permission); + Current::writePermission('2', 'content_creatable', true); $result = $this->TestModel->canEditWorkflowContent($data); //チェック diff --git a/Test/Case/Model/Behavior/WorkflowBehavior/CanReadWorkflowContentTest.php b/Test/Case/Model/Behavior/WorkflowBehavior/CanReadWorkflowContentTest.php index ee13275..2afc439 100644 --- a/Test/Case/Model/Behavior/WorkflowBehavior/CanReadWorkflowContentTest.php +++ b/Test/Case/Model/Behavior/WorkflowBehavior/CanReadWorkflowContentTest.php @@ -72,7 +72,8 @@ public function dataProvider() { */ public function testCanReadWorkflowContent($permission, $assert) { //テスト実施 - Current::$current['Permission']['content_readable']['value'] = $permission; + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_readable', $permission); $result = $this->TestModel->canReadWorkflowContent(); //チェック diff --git a/Test/Case/Model/Behavior/WorkflowBehavior/GetWorkflowConditionsTest.php b/Test/Case/Model/Behavior/WorkflowBehavior/GetWorkflowConditionsTest.php index 944312c..ad0d0de 100644 --- a/Test/Case/Model/Behavior/WorkflowBehavior/GetWorkflowConditionsTest.php +++ b/Test/Case/Model/Behavior/WorkflowBehavior/GetWorkflowConditionsTest.php @@ -160,8 +160,9 @@ public function testWOLangWOContentCreateable() { public function testWithContentCreatable() { //テストデータ $conditions = array(); - Current::$current = Hash::insert(Current::$current, 'Permission.content_creatable.value', true); - Current::$current = Hash::insert(Current::$current, 'User.id', '2'); + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_creatable', true); + Current::write('User.id', '2'); //テスト実施 $conditions = $this->TestModel->getWorkflowConditions($conditions); @@ -186,8 +187,9 @@ public function testWithContentCreatable() { public function testPeriodWithContentCreatable() { //テストデータ $conditions = array(); - Current::$current = Hash::insert(Current::$current, 'Permission.content_creatable.value', true); - Current::$current = Hash::insert(Current::$current, 'User.id', '2'); + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_creatable', true); + Current::write('User.id', '2'); //テスト実施 $conditions = $this->TestWPeriodModel->getWorkflowConditions($conditions); @@ -216,8 +218,9 @@ public function testPeriodWithContentCreatable() { public function testWithContentEditable() { //テストデータ $conditions = array(); - Current::$current = Hash::insert(Current::$current, 'Permission.content_editable.value', true); - Current::$current = Hash::insert(Current::$current, 'User.id', '2'); + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_editable', true); + Current::write('User.id', '2'); //テスト実施 $conditions = $this->TestModel->getWorkflowConditions($conditions); @@ -243,8 +246,9 @@ public function testWithContentEditable() { public function testPeriodWithContentEditable() { //テストデータ $conditions = array(); - Current::$current = Hash::insert(Current::$current, 'Permission.content_editable.value', true); - Current::$current = Hash::insert(Current::$current, 'User.id', '2'); + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_editable', true); + Current::write('User.id', '2'); //テスト実施 $conditions = $this->TestWPeriodModel->getWorkflowConditions($conditions); diff --git a/Test/Case/Model/Behavior/WorkflowBehavior/SaveTest.php b/Test/Case/Model/Behavior/WorkflowBehavior/SaveTest.php index f175e3c..d53961b 100644 --- a/Test/Case/Model/Behavior/WorkflowBehavior/SaveTest.php +++ b/Test/Case/Model/Behavior/WorkflowBehavior/SaveTest.php @@ -48,7 +48,8 @@ public function setUp() { //テストプラグインのロード NetCommonsCakeTestCase::loadTestPlugin($this, 'Workflow', 'TestWorkflow'); - Current::$current = Hash::insert(Current::$current, 'Permission.content_publishable.value', true); + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_publishable', true); } /** diff --git a/Test/Case/Model/Behavior/WorkflowBehavior/ValidatesTest.php b/Test/Case/Model/Behavior/WorkflowBehavior/ValidatesTest.php index b064cb0..334d259 100644 --- a/Test/Case/Model/Behavior/WorkflowBehavior/ValidatesTest.php +++ b/Test/Case/Model/Behavior/WorkflowBehavior/ValidatesTest.php @@ -121,7 +121,8 @@ public function testValidationError($value, $publishable, $error) { $message = __d('net_commons', 'Invalid request.'); if ($publishable) { - Current::$current['Permission']['content_publishable']['value'] = true; + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_publishable', true); } $data = array($model => (new TestWorkflowBehaviorValidatesModelFixture())->records[0]); $data[$model][$field] = $value; diff --git a/Test/Case/View/Elements/FormTest.php b/Test/Case/View/Elements/FormTest.php index db61a5f..56f3537 100644 --- a/Test/Case/View/Elements/FormTest.php +++ b/Test/Case/View/Elements/FormTest.php @@ -24,7 +24,9 @@ class WorkflowViewElementsFormTest extends NetCommonsControllerTestCase { * * @var array */ - public $fixtures = array(); + public $fixtures = array( + 'plugin.workflow.workflow_comment', + ); /** * Plugin name diff --git a/Test/Case/View/Helper/WorkflowHelper/AddLinkButtonTest.php b/Test/Case/View/Helper/WorkflowHelper/AddLinkButtonTest.php index 975c310..767b5bc 100644 --- a/Test/Case/View/Helper/WorkflowHelper/AddLinkButtonTest.php +++ b/Test/Case/View/Helper/WorkflowHelper/AddLinkButtonTest.php @@ -41,8 +41,8 @@ class WorkflowHelperAddLinkButtonTest extends NetCommonsHelperTestCase { public function setUp() { parent::setUp(); - Current::$current = Hash::insert(Current::$current, 'Block.id', '1'); - Current::$current = Hash::insert(Current::$current, 'Frame.id', '2'); + Current::write('Block.id', '1'); + Current::write('Frame.id', '2'); } /** @@ -55,7 +55,8 @@ public function testAddLinkButton() { $title = 'Title'; $url = array('action' => 'workflow_add'); $options = array(); - Current::$current = Hash::insert(Current::$current, 'Permission.content_creatable.value', true); + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_creatable', true); //Helperロード $params = array('plugin' => 'workflow_plugin', 'controller' => 'workflow_controller'); @@ -81,7 +82,8 @@ public function testWithoutUrl() { $title = 'Title'; $url = null; $options = array(); - Current::$current = Hash::insert(Current::$current, 'Permission.content_creatable.value', true); + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_creatable', true); //Helperロード $params = array('plugin' => 'workflow_plugin', 'controller' => 'workflow_controller'); @@ -107,7 +109,8 @@ public function testWithoutContentCreatable() { $title = 'Title'; $url = null; $options = array(); - Current::$current = Hash::insert(Current::$current, 'Permission.content_creatable.value', false); + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_creatable', false); //Helperロード $params = array('plugin' => 'workflow_plugin', 'controller' => 'workflow_controller'); @@ -131,7 +134,8 @@ public function testWithAddActionController() { $title = 'Title'; $url = null; $options = array(); - Current::$current = Hash::insert(Current::$current, 'Permission.content_creatable.value', true); + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_creatable', true); //Helperロード $viewVars = array('addActionController' => 'add_workflow_controller'); diff --git a/Test/Case/View/Helper/WorkflowHelper/BeforeRenderTest.php b/Test/Case/View/Helper/WorkflowHelper/BeforeRenderTest.php index 7c43956..f317e99 100644 --- a/Test/Case/View/Helper/WorkflowHelper/BeforeRenderTest.php +++ b/Test/Case/View/Helper/WorkflowHelper/BeforeRenderTest.php @@ -61,10 +61,6 @@ public function testBeforeRender() { //チェック $pattern = '/' . preg_quote('View/Helper/TestWorkflowHelperBeforeRender', '/') . '/'; $this->assertRegExp($pattern, $this->view); - - //cssのURLチェック - $pattern = '//'; - $this->assertRegExp($pattern, $this->contents); } } diff --git a/Test/Case/View/Helper/WorkflowHelper/ButtonsTest.php b/Test/Case/View/Helper/WorkflowHelper/ButtonsTest.php index ded34b3..9418de7 100644 --- a/Test/Case/View/Helper/WorkflowHelper/ButtonsTest.php +++ b/Test/Case/View/Helper/WorkflowHelper/ButtonsTest.php @@ -94,9 +94,8 @@ public function dataProvider() { */ public function testButtons($status, $contentPublishable, $cancelUrl, $panel, $backUrl) { //テストデータ生成 - Current::$current = Hash::insert( - Current::$current, 'Permission.content_publishable.value', $contentPublishable - ); + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_publishable', $contentPublishable); $viewVars = array(); $requestData = array( diff --git a/TestSuite/WorkflowDeleteTest.php b/TestSuite/WorkflowDeleteTest.php index 06e1046..7206fa1 100644 --- a/TestSuite/WorkflowDeleteTest.php +++ b/TestSuite/WorkflowDeleteTest.php @@ -29,8 +29,8 @@ public function setUp() { Current::$current['Block']['id'] = '2'; Current::$current['Room']['id'] = '2'; - Current::$current['Permission']['content_editable']['value'] = true; - Current::$current['Permission']['content_publishable']['value'] = true; + Current::writePermission('2', 'content_editable', true); + Current::writePermission('2', 'content_publishable', true); } } diff --git a/TestSuite/WorkflowGetTest.php b/TestSuite/WorkflowGetTest.php index b27ca38..df308d6 100644 --- a/TestSuite/WorkflowGetTest.php +++ b/TestSuite/WorkflowGetTest.php @@ -29,8 +29,8 @@ public function setUp() { Current::$current['Block']['id'] = '2'; Current::$current['Room']['id'] = '2'; - Current::$current['Permission']['content_editable']['value'] = true; - Current::$current['Permission']['content_publishable']['value'] = true; + Current::writePermission('2', 'content_editable', true); + Current::writePermission('2', 'content_publishable', true); } } diff --git a/TestSuite/WorkflowSaveTest.php b/TestSuite/WorkflowSaveTest.php index 8cba3a6..eeb99d6 100644 --- a/TestSuite/WorkflowSaveTest.php +++ b/TestSuite/WorkflowSaveTest.php @@ -29,8 +29,8 @@ public function setUp() { Current::$current['Block']['id'] = '2'; Current::$current['Room']['id'] = '2'; - Current::$current['Permission']['content_editable']['value'] = true; - Current::$current['Permission']['content_publishable']['value'] = true; + Current::writePermission('2', 'content_editable', true); + Current::writePermission('2', 'content_publishable', true); } /** diff --git a/VERSION.txt b/VERSION.txt new file mode 100644 index 0000000..86fb650 --- /dev/null +++ b/VERSION.txt @@ -0,0 +1 @@ +3.3.7 diff --git a/View/Elements/index.ctp b/View/Elements/index.ctp index 1bcfc9c..95da861 100644 --- a/View/Elements/index.ctp +++ b/View/Elements/index.ctp @@ -17,7 +17,7 @@
DisplayUser->handleLink($comment, array('avatar' => true)); ?> - + Date->dateFormat($comment['WorkflowComment']['created']); ?>
diff --git a/View/Helper/WorkflowHelper.php b/View/Helper/WorkflowHelper.php index 69d4882..dd238e0 100644 --- a/View/Helper/WorkflowHelper.php +++ b/View/Helper/WorkflowHelper.php @@ -161,16 +161,27 @@ public function buttons($statusFieldName, $cancelUrl = null, $panel = true, $bac * * @param string $statusFieldName ステータスのフィールド名 * @param bool $displayBlockKey block_keyを含めるかどうか + * @param string $useWorkflowFieldName useWorkflowのフィールド名 * @return string Html * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ - public function inputComment($statusFieldName, $displayBlockKey = true) { + public function inputComment($statusFieldName, $displayBlockKey = true, + $useWorkflowFieldName = null) { $status = Hash::get($this->_View->data, $statusFieldName); - $output = $this->_View->element('Workflow.form', array( - 'contentPublishable' => Current::permission('content_publishable'), - 'contentStatus' => $status, - )); + // {プラグイン名}Setting.use_workflowから承認フラグを取得する. + // とれなかったら、今までと同じ承認コメントを表示する + // {プラグイン名}Settingは、頭大文字と小文字がある。登録・編集時に{プラグイン名}Settingがないプラグインもある。 + // 例)AnnouncementSetting.use_workflow、bbsSetting.use_workflow, blogSetting.use_workflow + $useWorkflow = Hash::get($this->_View->data, $useWorkflowFieldName, 1); + + $output = ''; + if ($useWorkflow) { + $output = $this->_View->element('Workflow.form', array( + 'contentPublishable' => Current::permission('content_publishable'), + 'contentStatus' => $status, + )); + } if ($displayBlockKey) { $output .= $this->NetCommonsForm->hidden('Block.key', ['value' => Current::read('Block.key')]); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b636b39..dffa9d0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,8 @@ + + + app/Plugin/Workflow @@ -14,6 +17,6 @@ - +