-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
771c951
commit 6079bd3
Showing
4 changed files
with
313 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
/** | ||
* Announcement Model | ||
* | ||
* @property Block $Block | ||
* | ||
* @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('BlocksAppModel', 'Blocks.Model'); | ||
|
||
/** | ||
* Comment Model | ||
* | ||
* @author Shohei Nakajima <nakajimashouhei@gmail.com> | ||
* @package NetCommons\Announcements\Model | ||
*/ | ||
class Comment extends BlocksAppModel { | ||
|
||
/** | ||
* start limit | ||
* | ||
* @var int | ||
*/ | ||
const STARTLIMIT = 5; | ||
|
||
/** | ||
* max limit | ||
* | ||
* @var int | ||
*/ | ||
const MAXLIMIT = 100; | ||
|
||
/** | ||
* Validation rules | ||
* | ||
* @var array | ||
*/ | ||
public $validate = array(); | ||
|
||
//The Associations below have been created with all possible keys, those that are not needed can be removed | ||
|
||
/** | ||
* belongsTo associations | ||
* | ||
* @var array | ||
*/ | ||
public $belongsTo = array( | ||
'CreatedUser' => array( | ||
'className' => 'Users.UserAttributesUser', | ||
'foreignKey' => false, | ||
'conditions' => array( | ||
'Comment.created_user = CreatedUser.user_id', | ||
'CreatedUser.key' => 'nickname' | ||
), | ||
'fields' => array('CreatedUser.key', 'CreatedUser.value'), | ||
'order' => '' | ||
) | ||
); | ||
|
||
/** | ||
* Called during validation operations, before validation. Please note that custom | ||
* validation rules can be defined in $validate. | ||
* | ||
* @param array $options Options passed from Model::save(). | ||
* @return bool True if validate operation should continue, false to abort | ||
* @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforevalidate | ||
* @see Model::save() | ||
*/ | ||
public function beforeValidate($options = array()) { | ||
$this->validate = array( | ||
'plugin_key' => array( | ||
'notEmpty' => array( | ||
'rule' => array('notEmpty'), | ||
'message' => __d('net_commons', 'Invalid request.'), | ||
'required' => true, | ||
) | ||
), | ||
'content_key' => array( | ||
'notEmpty' => array( | ||
'rule' => array('notEmpty'), | ||
'message' => __d('net_commons', 'Invalid request.'), | ||
'required' => true, | ||
) | ||
), | ||
'comment' => array( | ||
'notEmpty' => array( | ||
'rule' => array('notEmpty'), | ||
'message' => __d('net_commons', 'Invalid request.'), | ||
'required' => true, | ||
) | ||
), | ||
); | ||
|
||
return parent::beforeValidate($options); | ||
} | ||
|
||
/** | ||
* before save | ||
* | ||
* @param array $options Options passed from Model::save(). | ||
* @return bool True if the operation should continue, false if it should abort | ||
*/ | ||
public function beforeSave($options = array()) { | ||
if (! isset($this->data[$this->name]['id'])) { | ||
$this->data[$this->name]['created_user'] = CakeSession::read('Auth.User.id'); | ||
} | ||
$this->data[$this->name]['modified_user'] = CakeSession::read('Auth.User.id'); | ||
return true; | ||
} | ||
|
||
} |
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,85 @@ | ||
<?php | ||
/** | ||
* Comment 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('Comment', 'Blocks.Model'); | ||
|
||
/** | ||
* Comment Test Case | ||
* | ||
* @author Shohei Nakajima <nakajimashouhei@gmail.com> | ||
* @package NetCommons\Blocks\Test\Case\Model | ||
*/ | ||
class CommentTest extends CakeTestCase { | ||
|
||
/** | ||
* Fixtures | ||
* | ||
* @var array | ||
*/ | ||
public $fixtures = array( | ||
'plugin.blocks.comment', | ||
'plugin.blocks.user_attributes_user', | ||
); | ||
|
||
/** | ||
* setUp method | ||
* | ||
* @return void | ||
*/ | ||
public function setUp() { | ||
parent::setUp(); | ||
$this->Comment = ClassRegistry::init('Blocks.Comment'); | ||
} | ||
|
||
/** | ||
* tearDown method | ||
* | ||
* @return void | ||
*/ | ||
public function tearDown() { | ||
unset($this->Comment); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* testCreateSave | ||
* | ||
* @return void | ||
*/ | ||
public function testSave() { | ||
CakeSession::write('Auth.User.id', 1); | ||
|
||
$comment['Comment'] = array( | ||
'plugin_key' => 'blocks', | ||
'content_key' => 'content', | ||
'comment' => 'testSave', | ||
); | ||
$result = $this->Comment->save($comment); | ||
unset($result['Comment']['created']); | ||
unset($result['Comment']['modified']); | ||
|
||
$expected = array( | ||
'Comment' => array( | ||
'id' => '2', | ||
'plugin_key' => 'blocks', | ||
'content_key' => 'content', | ||
'comment' => 'testSave', | ||
'created_user' => 1, | ||
'modified_user' => 1 | ||
) | ||
); | ||
$this->assertEquals($expected, $result, 'Error Equals Comment'); | ||
|
||
CakeSession::write('Auth.User.id', null); | ||
} | ||
|
||
} |
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,58 @@ | ||
<?php | ||
/** | ||
* CommentFixture | ||
* | ||
* @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 | ||
*/ | ||
|
||
/** | ||
* CommentFixture | ||
* | ||
* @author Shohei Nakajima <nakajimashouhei@gmail.com> | ||
* @package NetCommons\Blocks\Test\Fixture | ||
*/ | ||
class CommentFixture extends CakeTestFixture { | ||
|
||
/** | ||
* Fields | ||
* | ||
* @var array | ||
*/ | ||
public $fields = array( | ||
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary', 'comment' => 'ID | | | '), | ||
'plugin_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'plugin key | プラグインKey | plugins.key | ', 'charset' => 'utf8'), | ||
'content_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'content key | 各プラグインのコンテンツKey | | ', 'charset' => 'utf8'), | ||
'comment' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'Comment | コメント | | ', 'charset' => 'utf8'), | ||
'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', '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' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'modified datetime | 更新日時 | | '), | ||
'indexes' => array( | ||
'PRIMARY' => array('column' => 'id', 'unique' => 1), | ||
), | ||
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'), | ||
); | ||
|
||
/** | ||
* Records | ||
* | ||
* @var array | ||
*/ | ||
public $records = array( | ||
array( | ||
'id' => 1, | ||
'plugin_key' => 'test_plugin', | ||
'content_key' => 'test_contet', | ||
'comment' => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida, phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit, feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.', | ||
'created_user' => 1, | ||
'created' => '2014-06-18 02:06:22', | ||
'modified_user' => 1, | ||
'modified' => '2014-06-18 02:06:22' | ||
), | ||
); | ||
|
||
} |
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,54 @@ | ||
<?php | ||
/** | ||
* UserAttributesUserFixture | ||
* | ||
* @author Jun Nishikawa <topaz2@m0n0m0n0.com> | ||
* @link http://www.netcommons.org NetCommons Project | ||
* @license http://www.netcommons.org/license.txt NetCommons License | ||
*/ | ||
|
||
/** | ||
* Summary for UserAttributesUserFixture | ||
*/ | ||
class UserAttributesUserFixture extends CakeTestFixture { | ||
|
||
/** | ||
* Fields | ||
* | ||
* @var array | ||
*/ | ||
public $fields = array( | ||
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), | ||
'language_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 6), | ||
'user_id' => array('type' => 'integer', 'null' => false, 'default' => null), | ||
'user_attribute_id' => array('type' => 'integer', 'null' => false, 'default' => null), | ||
'key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'Key to identify record meaning. | ||
e.g.) nickname, age, ', 'charset' => 'utf8'), | ||
'value' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), | ||
'created_user' => array('type' => 'integer', 'null' => true, 'default' => null), | ||
'created' => array('type' => 'datetime', 'null' => true, 'default' => null), | ||
'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null), | ||
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), | ||
'indexes' => array( | ||
'PRIMARY' => array('column' => 'id', 'unique' => 1), | ||
), | ||
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'), | ||
); | ||
|
||
/** | ||
* Records | ||
* | ||
* @var array | ||
*/ | ||
public $records = array( | ||
array( | ||
'id' => 1, | ||
'language_id' => 2, | ||
'user_id' => 1, | ||
'user_attribute_id' => 1, | ||
'key' => 'nickname', | ||
'value' => 'admin', | ||
), | ||
); | ||
|
||
} |