Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ブロックの権限設定テストの共通化対応 #20

Merged
merged 1 commit into from
Oct 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Controller/BbsBlockRolePermissionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public function edit() {
return;
}
$this->NetCommons->handleValidationError($this->BbsSetting->validationErrors);
$this->request->data['BlockRolePermission'] = Hash::merge(
$permissions['BlockRolePermissions'],
$this->request->data['BlockRolePermission']
);

} else {
$this->request->data['BbsSetting'] = $bbs['BbsSetting'];
Expand Down
18 changes: 4 additions & 14 deletions Test/Case/AllBbsesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @copyright Copyright 2014, NetCommons Project
*/

App::uses('NetCommonsTestSuite', 'NetCommons.TestSuite');

/**
* Bbses All Test Suite
*
Expand All @@ -24,20 +26,8 @@ class AllBbsesTest extends CakeTestSuite {
*/
public static function suite() {
$plugin = preg_replace('/^All([\w]+)Test$/', '$1', __CLASS__);
$suite = new CakeTestSuite(sprintf('All %s Plugin tests', $plugin));

$directory = CakePlugin::path($plugin) . 'Test' . DS . 'Case';
$Folder = new Folder($directory);
$exceptions = array(
'BbsesControllerTestBase.php',
'BbsModelTestBase.php'
);
$files = $Folder->tree(null, $exceptions, 'files');
foreach ($files as $file) {
if (substr($file, -4) === '.php') {
$suite->addTestFile($file);
}
}
$suite = new NetCommonsTestSuite(sprintf('All %s Plugin tests', $plugin));
$suite->addTestDirectoryRecursive(CakePlugin::path($plugin) . 'Test' . DS . 'Case');
return $suite;
}
}
165 changes: 165 additions & 0 deletions Test/Case/Controller/BbsBlockRolePermissionsController/EditTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php
/**
* BlockRolePermissionsController Test Case
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/

App::uses('BbsBlockRolePermissionsController', 'Bbses.Controller');
App::uses('BlockRolePermissionsControllerEditTest', 'Blocks.TestSuite');

/**
* BlockRolePermissionsController Test Case
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Bbses\Test\Case\Controller
*/
class BbsBlockRolePermissionsControllerEditTest extends BlockRolePermissionsControllerEditTest {

/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'plugin.bbses.bbs',
'plugin.bbses.bbs_setting',
'plugin.bbses.bbs_frame_setting',
'plugin.bbses.bbs_article',
'plugin.bbses.bbs_article_tree',
'plugin.bbses.bbs_articles_user',
'plugin.workflow.workflow_comment',
);

/**
* Plugin name
*
* @var array
*/
public $plugin = 'bbses';

/**
* Controller name
*
* @var string
*/
protected $_controller = 'bbs_block_role_permissions';

/**
* テストDataの取得
*
* @param bool $isPost POSTかどうか
* @return array
*/
private function __getData($isPost) {
if ($isPost) {
$data = array(
'BbsSetting' => array(
'id' => 2,
'bbs_key' => 'bbs_2',
'use_workflow' => true,
'use_comment_approval' => true,
'approval_type' => true,
)
);
} else {
$data = array(
'BbsSetting' => array(
'use_workflow',
'use_comment_approval',
'approval_type',
)
);
}
return $data;
}

/**
* edit()アクションDataProvider
*
* ### 戻り値
* - approvalFields コンテンツ承認の利用有無のフィールド
* - exception Exception
* - return testActionの実行後の結果
*
* @return void
*/
public function dataProviderEditGet() {
return array(
array('approvalFields' => $this->__getData(false))
);
}

/**
* editアクションのGETテスト(Exceptionエラー)
*
* @param array $approvalFields コンテンツ承認の利用有無のフィールド
* @param string|null $exception Exception
* @param string $return testActionの実行後の結果
* @dataProvider dataProviderEditGet
* @return void
*/
public function testEditGetExceptionError($approvalFields, $exception = null, $return = 'view') {
$this->_mockForReturnFalse('Bbses.Bbs', 'getBbs');

$exception = 'BadRequestException';
$this->testEditGet($approvalFields, $exception, $return);
}

/**
* editアクションのGET(JSON)テスト(Exceptionエラー)
*
* @param array $approvalFields コンテンツ承認の利用有無のフィールド
* @param string|null $exception Exception
* @param string $return testActionの実行後の結果
* @dataProvider dataProviderEditGet
* @return void
*/
public function testEditGetJsonExceptionError($approvalFields, $exception = null, $return = 'view') {
$this->_mockForReturnFalse('Bbses.Bbs', 'getBbs');

$exception = 'BadRequestException';
$return = 'json';
$this->testEditGet($approvalFields, $exception, $return);
}

/**
* edit()アクションDataProvider
*
* ### 戻り値
* - data POSTデータ
* - exception Exception
* - return testActionの実行後の結果
*
* @return void
*/
public function dataProviderEditPost() {
return array(
array('data' => $this->__getData(true))
);
}

/**
* editアクションのPOSTテスト(Saveエラー)
*
* @param array $data POSTデータ
* @param string|null $exception Exception
* @param string $return testActionの実行後の結果
* @dataProvider dataProviderEditPost
* @return void
*/
public function testEditPostSaveError($data, $exception = null, $return = 'view') {
$data['BlockRolePermission']['content_creatable'][Role::ROOM_ROLE_KEY_GENERAL_USER]['roles_room_id'] = 'aaaa';

//テスト実施
$exception = false;
$result = $this->testEditPost($data, false, $return);

$approvalFields = $this->__getData(false);
$this->_assertEditGetPermission($approvalFields, $result);
}
}
104 changes: 91 additions & 13 deletions Test/Fixture/BbsFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,28 @@
*/
class BbsFixture extends CakeTestFixture {

/**
* Full Table Name
*
* @var string
*/
public $table = 'bbses';

/**
* Fields
*
* @var array
*/
public $fields = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary', 'comment' => 'ID | | | '),
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary', 'comment' => 'ID | | | '),
'key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'bbs key | 掲示板キー | Hash値 | ', 'charset' => 'utf8'),
'block_id' => array('type' => 'integer', 'null' => false, 'default' => null),
'block_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false),
'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'bbs name | 掲示板名称 | | ', 'charset' => 'utf8'),
'bbs_article_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'comment' => 'Article count | 記事数 | | '),
'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => 'created user | 作成者 | users.id | '),
'bbs_article_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false, 'comment' => 'Article count | 記事数 | | '),
'bbs_article_modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'Article modified datetime | 記事の最終更新日時 | | '),
'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => 'created user | 作成者 | users.id | '),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'created datetime | 作成日時 | | '),
'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => 'modified user | 更新者 | users.id | '),
'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => 'modified user | 更新者 | users.id | '),
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'modified datetime | 更新日時 | | '),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1)
Expand All @@ -46,17 +54,87 @@ class BbsFixture extends CakeTestFixture {
* @var array
*/
public $records = array(
//掲示板1
array(
'id' => 1,
'key' => 'bbs_1',
'block_id' => 1,
'name' => 'テスト掲示板1',
'bbs_article_count' => 1,
'created_user' => 1,
'created' => '2014-06-18 02:06:22',
'modified_user' => 1,
'modified' => '2014-06-18 02:06:22',
)
'block_id' => '1',
'name' => 'Test bbs 1',
'bbs_article_count' => 1,
'bbs_article_modified' => 1,
),
array(
'id' => 2,
'key' => 'bbs_1',
'block_id' => '2',
'name' => 'Test bbs 1',
'bbs_article_count' => 1,
'bbs_article_modified' => 1,
),
//掲示板2
array(
'id' => 3,
'key' => 'bbs_2',
'block_id' => '4',
'name' => 'Test bbs 2',
'bbs_article_count' => 1,
'bbs_article_modified' => 1,
),
//掲示板3
array(
'id' => 4,
'key' => 'bbs_3',
'block_id' => '6',
'name' => 'Test bbs 3',
'bbs_article_count' => 1,
'bbs_article_modified' => 1,
),

//掲示板4(ワークフローなし)
array(
'id' => 5,
'key' => 'bbs_4',
'block_id' => '11',
'name' => 'Test bbs 4',
'bbs_article_count' => 1,
'bbs_article_modified' => 1,
),
//掲示板5(コメントなし)
array(
'id' => 6,
'key' => 'bbs_5',
'block_id' => '12',
'name' => 'Test bbs 5',
'bbs_article_count' => 1,
'bbs_article_modified' => 1,
),
//掲示板6(コメントの承認なし)
array(
'id' => 7,
'key' => 'bbs_6',
'block_id' => '13',
'name' => 'Test bbs 6',
'bbs_article_count' => 1,
'bbs_article_modified' => 1,
),
//掲示板7(いいねなし)
array(
'id' => 8,
'key' => 'bbs_7',
'block_id' => '14',
'name' => 'Test bbs 7',
'bbs_article_count' => 1,
'bbs_article_modified' => 1,
),
//掲示板8(わるいねなし)
array(
'id' => 9,
'key' => 'bbs_8',
'block_id' => '15',
'name' => 'Test bbs 8',
'bbs_article_count' => 1,
'bbs_article_modified' => 1,
),
);

}
Loading