From b4e1fd079fb595b2bf9cc7bd9950f5fc9c015234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B4=E3=83=B3=E3=83=89=E3=83=BC?= Date: Thu, 26 Oct 2023 16:50:26 +0900 Subject: [PATCH 1/4] =?UTF-8?q?basercms-5.0.6=20=E3=82=92=E3=83=AA?= =?UTF-8?q?=E3=83=AA=E3=83=BC=E3=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/baser-core/VERSION.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/baser-core/VERSION.txt b/plugins/baser-core/VERSION.txt index 15a0980976..b9128c9ea1 100644 --- a/plugins/baser-core/VERSION.txt +++ b/plugins/baser-core/VERSION.txt @@ -1,4 +1,4 @@ -5.0.5 +5.0.6 /////////////////////////////////////////////////////////////////////////////////////////////////////////// // +---------------------------------------------------------------------------------------------------+ // @@ -14,6 +14,13 @@ CHG: 変更内容 / BUG: バグフィックス / NEW: 機能追加 +[2023-10-26] basercms-5.0.6 +- BUG [BC] fix #1903 コンテンツ一覧(表)コピーの際にコピー先のタイトルに「のコピー」とつかない問題の改善 +- BUG [BC] fix #2783 CGIモードでJWT認証が可能なよう改善 +- BUG [BC] fix #2403 アップロードファイルのAPIにフルパスのURLを追加 +- BUG [ML] fix #1901 バリデーションエラー時にチェックボックスのチェックが外れる +- BUG [ML] fix #2806 メールプラグインが有効化されていない場合にダッシュボードが表示できない問題の改善 + [2023-09-28] basercms-5.0.5 - BUG [BC] fix #2744 カスタムコンテンツのバリデーションエラーを改善 - BUG [BC] fix #2199 カスタムコンテンツのAPIで取得する情報に不要な連携データが含まれる処理の改善 From cf4037ef88459ccf409ca0d4a65e7730df93fcb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B4=E3=83=B3=E3=83=89=E3=83=BC?= Date: Thu, 26 Oct 2023 16:51:13 +0900 Subject: [PATCH 2/4] prepare release --- composer.json | 32 ++++++++++++++++---------------- plugins/baser-core/composer.json | 28 ++++++++++++++-------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/composer.json b/composer.json index 66d7ed660f..48e373d3c2 100644 --- a/composer.json +++ b/composer.json @@ -73,22 +73,22 @@ } }, "replace": { - "baserproject/baser-core": "5.0.5", - "baserproject/bc-admin-third": "5.0.5", - "baserproject/bc-blog": "5.0.5", - "baserproject/bc-column": "5.0.5", - "baserproject/bc-content-link": "5.0.5", - "baserproject/bc-custom-content": "5.0.5", - "baserproject/bc-editor-template": "5.0.5", - "baserproject/bc-favorite": "5.0.5", - "baserproject/bc-front": "5.0.5", - "baserproject/bc-installer": "5.0.5", - "baserproject/bc-mail": "5.0.5", - "baserproject/bc-search-index": "5.0.5", - "baserproject/bc-theme-config": "5.0.5", - "baserproject/bc-theme-file": "5.0.5", - "baserproject/bc-uploader": "5.0.5", - "baserproject/bc-widget-area": "5.0.5" + "baserproject/baser-core": "5.0.6", + "baserproject/bc-admin-third": "5.0.6", + "baserproject/bc-blog": "5.0.6", + "baserproject/bc-column": "5.0.6", + "baserproject/bc-content-link": "5.0.6", + "baserproject/bc-custom-content": "5.0.6", + "baserproject/bc-editor-template": "5.0.6", + "baserproject/bc-favorite": "5.0.6", + "baserproject/bc-front": "5.0.6", + "baserproject/bc-installer": "5.0.6", + "baserproject/bc-mail": "5.0.6", + "baserproject/bc-search-index": "5.0.6", + "baserproject/bc-theme-config": "5.0.6", + "baserproject/bc-theme-file": "5.0.6", + "baserproject/bc-uploader": "5.0.6", + "baserproject/bc-widget-area": "5.0.6" }, "scripts": { "post-install-cmd": "App\\Console\\Installer::postInstall", diff --git a/plugins/baser-core/composer.json b/plugins/baser-core/composer.json index b620e2e046..1b3bcb7505 100644 --- a/plugins/baser-core/composer.json +++ b/plugins/baser-core/composer.json @@ -15,20 +15,20 @@ "josegonzalez/dotenv": "^3.2", "mobiledetect/mobiledetectlib": "^2.8", "ext-json": "*", - "baserproject/bc-admin-third": "^5.1", - "baserproject/bc-blog": "^5.1", - "baserproject/bc-content-link": "^5.1", - "baserproject/bc-custom-content": "^5.1", - "baserproject/bc-editor-template": "^5.1", - "baserproject/bc-favorite": "^5.1", - "baserproject/bc-front": "^5.1", - "baserproject/bc-installer": "^5.1", - "baserproject/bc-mail": "^5.1", - "baserproject/bc-search-index": "^5.1", - "baserproject/bc-theme-config": "^5.1", - "baserproject/bc-theme-file": "^5.1", - "baserproject/bc-uploader": "^5.1", - "baserproject/bc-widget-area": "^5.1", + "baserproject/bc-admin-third": "^5.0.6", + "baserproject/bc-blog": "^5.0.6", + "baserproject/bc-content-link": "^5.0.6", + "baserproject/bc-custom-content": "^5.0.6", + "baserproject/bc-editor-template": "^5.0.6", + "baserproject/bc-favorite": "^5.0.6", + "baserproject/bc-front": "^5.0.6", + "baserproject/bc-installer": "^5.0.6", + "baserproject/bc-mail": "^5.0.6", + "baserproject/bc-search-index": "^5.0.6", + "baserproject/bc-theme-config": "^5.0.6", + "baserproject/bc-theme-file": "^5.0.6", + "baserproject/bc-uploader": "^5.0.6", + "baserproject/bc-widget-area": "^5.0.6", "imo-tikuwa/cakephp-soft-delete": "^2.0", "ext-mbstring": "*", "ext-zip": "*", From 9c8f26eea280e9725af2f5d4255fed28875c48bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=B4=E3=83=B3=E3=83=89=E3=83=BC?= Date: Thu, 26 Oct 2023 16:51:19 +0900 Subject: [PATCH 3/4] open 5.1-dev --- plugins/baser-core/composer.json | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/plugins/baser-core/composer.json b/plugins/baser-core/composer.json index 1b3bcb7505..b620e2e046 100644 --- a/plugins/baser-core/composer.json +++ b/plugins/baser-core/composer.json @@ -15,20 +15,20 @@ "josegonzalez/dotenv": "^3.2", "mobiledetect/mobiledetectlib": "^2.8", "ext-json": "*", - "baserproject/bc-admin-third": "^5.0.6", - "baserproject/bc-blog": "^5.0.6", - "baserproject/bc-content-link": "^5.0.6", - "baserproject/bc-custom-content": "^5.0.6", - "baserproject/bc-editor-template": "^5.0.6", - "baserproject/bc-favorite": "^5.0.6", - "baserproject/bc-front": "^5.0.6", - "baserproject/bc-installer": "^5.0.6", - "baserproject/bc-mail": "^5.0.6", - "baserproject/bc-search-index": "^5.0.6", - "baserproject/bc-theme-config": "^5.0.6", - "baserproject/bc-theme-file": "^5.0.6", - "baserproject/bc-uploader": "^5.0.6", - "baserproject/bc-widget-area": "^5.0.6", + "baserproject/bc-admin-third": "^5.1", + "baserproject/bc-blog": "^5.1", + "baserproject/bc-content-link": "^5.1", + "baserproject/bc-custom-content": "^5.1", + "baserproject/bc-editor-template": "^5.1", + "baserproject/bc-favorite": "^5.1", + "baserproject/bc-front": "^5.1", + "baserproject/bc-installer": "^5.1", + "baserproject/bc-mail": "^5.1", + "baserproject/bc-search-index": "^5.1", + "baserproject/bc-theme-config": "^5.1", + "baserproject/bc-theme-file": "^5.1", + "baserproject/bc-uploader": "^5.1", + "baserproject/bc-widget-area": "^5.1", "imo-tikuwa/cakephp-soft-delete": "^2.0", "ext-mbstring": "*", "ext-zip": "*", From fb62e7175b6a9c8a2d7126f23594c459752a7d7c Mon Sep 17 00:00:00 2001 From: ryuring Date: Thu, 26 Oct 2023 18:19:46 +0900 Subject: [PATCH 4/4] =?UTF-8?q?AppTable=E3=82=92=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../baser-core/src/Model/Table/AppTable.php | 67 +- .../src/Model/Table/ContentFoldersTable.php | 7 +- .../src/Model/Table/ContentsTable.php | 2 - .../src/Model/Validation/BcValidation.php | 14 + .../TestCase/Model/Table/BcAppTableTest.php | 627 ------------------ .../Model/Validation/BcValidationTest.php | 25 + 6 files changed, 48 insertions(+), 694 deletions(-) delete mode 100644 plugins/baser-core/tests/TestCase/Model/Table/BcAppTableTest.php diff --git a/plugins/baser-core/src/Model/Table/AppTable.php b/plugins/baser-core/src/Model/Table/AppTable.php index a59ba2ab2e..b96386668c 100755 --- a/plugins/baser-core/src/Model/Table/AppTable.php +++ b/plugins/baser-core/src/Model/Table/AppTable.php @@ -14,7 +14,6 @@ use BaserCore\Utility\BcUtil; use Cake\ORM\Association\BelongsToMany; use Cake\ORM\Table; -use Cake\Core\Configure; use Cake\I18n\FrozenTime; use BaserCore\Annotation\NoTodo; use BaserCore\Annotation\Checked; @@ -26,6 +25,10 @@ */ class AppTable extends Table { + + /** + * Trait + */ use BcEventDispatcherTrait; /** @@ -68,8 +71,7 @@ class AppTable extends Table */ public function setTable(string $table) { - $table = $this->addPrefix($table); - return parent::setTable($table); + return parent::setTable($this->addPrefix($table)); } /** @@ -83,8 +85,7 @@ public function setTable(string $table) */ public function getTable(): string { - $table = parent::getTable(); - $this->_table = $this->addPrefix($table); + $this->setTable(parent::getTable()); return $this->_table; } @@ -148,29 +149,6 @@ public function initialize(array $config): void FrozenTime::setToStringFormat('yyyy-MM-dd HH:mm:ss'); } - /** - * 配列の文字コードを変換する - * - * @param array $data 変換前のデータ - * @param string $outenc 変換後の文字コード - * @param string $inenc 変換元の文字コード - * @return array 変換後のデータ - * @TODO GLOBAL グローバルな関数として再配置する必要あり - */ - public function convertEncodingByArray($data, $outenc, $inenc) - { - foreach($data as $key => $value) { - if (is_array($value)) { - $data[$key] = $this->convertEncodingByArray($value, $outenc, $inenc); - } else { - if (mb_detect_encoding($value) <> $outenc) { - $data[$key] = mb_convert_encoding($value, $outenc, $inenc); - } - } - } - return $data; - } - /** * 機種依存文字の変換処理 * @@ -257,21 +235,6 @@ public function replaceText($str) return str_replace(array_keys($arr), array_values($arr), $str); } - /** - * 範囲を指定しての長さチェック - * - * @param mixed $check 対象となる値 - * @param int $min 値の最短値 - * @param int $max 値の最長値 - * @param boolean - */ - public function between($check, $min, $max) - { - $check = (is_array($check))? current($check) : $check; - $length = mb_strlen($check, Configure::read('App.encoding')); - return ($length >= $min && $length <= $max); - } - /** * 指定フィールドのMAX値を取得する * @@ -290,24 +253,6 @@ public function getMax(string $field, array $conditions = []): int return $max->{$field} ?? 0; } - /** - * 英数チェック - * - * @param string $value チェック対象文字列 - * @return boolean - */ - public static function alphaNumeric($value) - { - if (!$value) { - return true; - } - if (preg_match("/^[a-zA-Z0-9]+$/", $value)) { - return true; - } else { - return false; - } - } - /** * 一つ位置を上げる * @param string $id diff --git a/plugins/baser-core/src/Model/Table/ContentFoldersTable.php b/plugins/baser-core/src/Model/Table/ContentFoldersTable.php index 29b0dd6c71..e176365d27 100644 --- a/plugins/baser-core/src/Model/Table/ContentFoldersTable.php +++ b/plugins/baser-core/src/Model/Table/ContentFoldersTable.php @@ -17,7 +17,6 @@ use BcSearchIndex\Service\SearchIndexesServiceInterface; use BaserCore\Utility\BcContainerTrait; use Cake\Event\EventInterface; -use Cake\ORM\Exception\PersistenceFailedException; use Cake\Validation\Validator; use BaserCore\Annotation\NoTodo; use BaserCore\Annotation\Checked; @@ -69,7 +68,7 @@ public function initialize(array $config): void /** * validationDefault * - * @param Validator $validator + * @param Validator $validator * @return Validator * @checked * @noTodo @@ -165,7 +164,7 @@ public function copy(int $id, $newParentId, $newTitle, $newAuthorId, $newSiteId) 'id' => $id, ]); if ($event !== false) { - $entity = ($event->getResult() === null || $event->getResult() === true) ? $event->getData('data') : $event->getResult(); + $entity = ($event->getResult() === null || $event->getResult() === true)? $event->getData('data') : $event->getResult(); } $entity->content = new Content([ @@ -176,7 +175,7 @@ public function copy(int $id, $newParentId, $newTitle, $newAuthorId, $newSiteId) 'site_id' => $newSiteId, 'description' => $entity->content->description, 'eyecatch' => $entity->content->eyecatch, - 'layout_template' => $entity->content->layout_tmplate?? '' + 'layout_template' => $entity->content->layout_tmplate ?? '' ]); if (!is_null($newSiteId) && $oldEntity->content->site_id !== $newSiteId) { $entity->content->parent_id = $this->Contents->copyContentFolderPath($entity->content->url, $newSiteId); diff --git a/plugins/baser-core/src/Model/Table/ContentsTable.php b/plugins/baser-core/src/Model/Table/ContentsTable.php index d2827e5940..a35248680d 100644 --- a/plugins/baser-core/src/Model/Table/ContentsTable.php +++ b/plugins/baser-core/src/Model/Table/ContentsTable.php @@ -12,14 +12,12 @@ namespace BaserCore\Model\Table; use ArrayObject; -use Cake\Core\Plugin; use Cake\Utility\Hash; use Cake\Core\Configure; use Cake\I18n\FrozenTime; use Cake\ORM\TableRegistry; use BaserCore\Utility\BcUtil; use Cake\Event\EventInterface; -use Cake\Utility\Inflector; use Cake\Validation\Validator; use BaserCore\Annotation\NoTodo; use BaserCore\Annotation\Checked; diff --git a/plugins/baser-core/src/Model/Validation/BcValidation.php b/plugins/baser-core/src/Model/Validation/BcValidation.php index 7cd160082c..56808f9531 100644 --- a/plugins/baser-core/src/Model/Validation/BcValidation.php +++ b/plugins/baser-core/src/Model/Validation/BcValidation.php @@ -601,4 +601,18 @@ public static function checkSelectList($value): bool return ($result < 2); } + /** + * 範囲を指定しての長さチェック + * + * @param mixed $value 対象となる値 + * @param int $min 値の最短値 + * @param int $max 値の最長値 + * @param boolean + */ + public static function between($value, $min, $max) + { + $length = mb_strlen($value, Configure::read('App.encoding')); + return ($length >= $min && $length <= $max); + } + } diff --git a/plugins/baser-core/tests/TestCase/Model/Table/BcAppTableTest.php b/plugins/baser-core/tests/TestCase/Model/Table/BcAppTableTest.php deleted file mode 100644 index d6d2a4d83c..0000000000 --- a/plugins/baser-core/tests/TestCase/Model/Table/BcAppTableTest.php +++ /dev/null @@ -1,627 +0,0 @@ - - * Copyright (c) baserCMS Users Community - * - * @copyright Copyright (c) baserCMS Users Community - * @link https://basercms.net baserCMS Project - * @since baserCMS v 3.0.0-beta - * @license https://basercms.net/license/index.html - */ -App::uses('BcApp', 'Model'); -App::uses('Content', 'Model'); - -/** - * Class BcAppTest - * - * @property BcAppModel $BcApp - * @property Page $Page - * @property SiteConfig $SiteConfig - * @property Content $Content - * @property User $User - */ -class BcAppTest extends BaserTestCase -{ - - public $fixtures = [ - 'baser.Default.Page', - 'baser.Default.Dblog', - 'baser.Default.SiteConfig', - 'baser.Default.User', - 'baser.Default.UserGroup', - 'baser.Default.Permission', - 'baser.Default.SearchIndex', - 'baser.Default.Content', - 'baser.Default.Site' - ]; - - /** - * setUp - * - * @return void - */ - public function setUp() - { - parent::setUp(); - $this->BcApp = ClassRegistry::init('BcApp'); - $this->Page = ClassRegistry::init('Page'); - $this->SiteConfig = ClassRegistry::init('SiteConfig'); - $this->Dblog = ClassRegistry::init('Dblog'); - $this->User = ClassRegistry::init('User'); - $this->Content = ClassRegistry::init('Content'); - - } - - /** - * tearDown - * - * @return void - */ - public function tearDown() - { - unset($this->BcApp); - unset($this->Page); - unset($this->SiteConfig); - unset($this->Dblog); - parent::tearDown(); - } - - /** - * コンストラクタ - */ - public function test__construct() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * beforeSave - * - * @return boolean - * @access public - */ - public function testBeforeSave() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - - $this->Page->save([ - 'Page' => [ - 'name' => 'test', - 'page_category_id' => null, - 'title' => '', - 'url' => '', - 'description' => '', - 'status' => 1, - 'modified' => '', - ] - ]); - - $LastID = $this->Page->getLastInsertID(); - $result = $this->Page->find('first', [ - 'conditions' => ['id' => $LastID], - 'fields' => ['created'], - 'recursive' => -1 - ] - ); - - $this->BcApp->beforeSave(['type' => 'date']); - } - - /** - * Saves model data to the database. By default, validation occurs before save. - * - * @param array $data Data to save. - * @param boolean $validate If set, validation will be done before the save - * @param array $fieldList List of fields to allow to be written - * @return mixed On success Model::$data if its not empty or true, false on failure - */ - public function testSave($data = null, $validate = true, $fieldList = []) - { - $this->Page->save([ - 'Page' => [ - 'name' => 'test', - 'page_category_id' => null, - 'title' => '', - 'url' => '', - 'description' => '', - 'status' => 1, - 'modified' => null, - 'created' => '2015-02-22 22:22:22' - ] - ]); - $now = date('Y-m-d H'); - - $LastID = $this->Page->getLastInsertID(); - $result = $this->Page->find('first', [ - 'conditions' => ['id' => $LastID], - 'fields' => ['created', 'modified'], - 'recursive' => -1 - ] - ); - $created = date('Y-m-d H', strtotime($result['Page']['created'])); - $modified = date('Y-m-d H', strtotime($result['Page']['modified'])); - - $message = 'created,modifiedを更新できません'; - $this->assertEquals($now, $created, $message); - $this->assertEquals($now, $modified, $message); - } - - /** - * 配列の文字コードを変換する - * - * @param array 変換前のデータ - * @param string 変換後の文字コード - * @param string 変換元の文字コード - * @dataProvider convertEncodingByArrayDataProvider - */ - public function testConvertEncodingByArray($data, $outenc, $inenc) - { - $result = $this->BcApp->convertEncodingByArray($data, $outenc, $inenc); - foreach($result as $key => $value) { - $encode = mb_detect_encoding($value); - $this->assertEquals($outenc, $encode); - } - } - - public function convertEncodingByArrayDataProvider() - { - return [ - [["テスト1"], "ASCII", "SJIS"], - [["テスト1", "テスト2"], "UTF-8", "SJIS"], - [["テスト1", "テスト2"], "SJIS-win", "UTF-8"], - ]; - } - - /** - * データベースログを記録する - */ - public function testSaveDbLog() - { - - // Dblogにログを追加 - $message = 'テストです'; - $this->BcApp->saveDblog($message); - - // 最後に追加したログを取得 - $LastID = $this->Dblog->getLastInsertID(); - $result = $this->Dblog->find('first', [ - 'conditions' => ['Dblog.id' => $LastID], - 'fields' => 'name', - ] - ); - $this->assertEquals($message, $result['Dblog']['name']); - - } - - /** - * 機種依存文字の変換処理 - * - * @param string 変換対象文字列 - * @param string 変換後予想文字列 - * @dataProvider replaceTextDataProvider - */ - public function testReplaceText($str, $expect) - { - $result = $this->BcApp->replaceText($str); - $this->assertEquals($expect, $result); - } - - public function replaceTextDataProvider() - { - return [ - ["\xE2\x85\xA0", "I"], - ["\xE2\x91\xA0", "(1)"], - ["\xE3\x8D\x89", "ミリ"], - ["\xE3\x88\xB9", "(代)"], - ]; - } - - /** - * データベース初期化 - * - * @param $pluginName - * @param $options - * @param $expected - * - * @dataProvider initDbDataProvider - * - * MEMO: pluginNameが実在する場合が未実装 - */ - public function testInitDb($pluginName, $options, $expected) - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - $result = $this->BcApp->initDb($pluginName, $options); - $this->assertEquals($expected, $result); - } - - public function initDbDataProvider() - { - return [ - ['', [], true], - ['hoge', ['dbDataPattern' => true], 1] - ]; - } - - /** - * 範囲を指定しての長さチェック - * - * @param mixed $check - * @param int $min - * @param int $max - * @param boolean $expect - * @dataProvider betweenDataProvider - */ - public function testBetween($check, $min, $max, $expect) - { - $result = $this->BcApp->between($check, $min, $max); - $this->assertEquals($expect, $result); - } - - public function betweenDataProvider() - { - return [ - ["あいう", 2, 4, true], - ["あいう", 3, 3, true], - ["あいう", 4, 3, false], - [["あいう", "あいうえお"], 2, 4, true], - ]; - } - - /** - * 指定フィールドのMAX値を取得する - */ - public function testGetMax() - { - $result = $this->Page->getMax('Page\.id'); - $this->assertEquals(11, $result, '指定フィールドのMAX値を取得できません'); - } - - /** - * テーブルにフィールドを追加する - */ - public function testAddField() - { - $options = [ - 'field' => 'testField', - 'column' => [ - 'type' => 'text', - 'null' => true, - 'default' => null, - ], - 'table' => 'pages', - ]; - $this->Page->addField($options); - $columns = $this->Page->getColumnTypes(); - $this->assertEquals(isset($columns['testField']), true); - } - - /** - * フィールド構造を変更する - */ - public function testEditField() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - $options = [ - 'field' => 'testField', - 'column' => [ - 'name' => 'testColumn', - ], - ]; - $this->BcApp->editField($options); - $columns = $this->Page->getColumnTypes(); - } - - /** - * フィールド名を変更する - */ - public function testRenameField() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - - /** - * フィールドを削除する - */ - public function testDelField() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * テーブルの存在チェックを行う - * - * @param string $tableName - * @param boolean $expect - * @dataProvider tableExistsDataProvider - */ - public function testTableExists($tableName, $expect) - { - $db = ConnectionManager::getDataSource('default'); - $prefix = $db->config['prefix']; - - $result = $this->BcApp->tableExists($prefix . $tableName); - $this->assertEquals($expect, $result); - } - - public function tableExistsDataProvider() - { - return [ - ["users", true], - ["notexist", false], - ]; - } - - /** - * 英数チェック - * - * @param string $check チェック対象文字列 - * @param boolean $expect - * @dataProvider alphaNumericDataProvider - */ - public function testAlphaNumeric($check, $expect) - { - $result = $this->BcApp->alphaNumeric($check); - $this->assertEquals($expect, $result); - } - - public function alphaNumericDataProvider() - { - return [ - [["aiueo"], true], - [["12345"], true], - [["あいうえお"], false], - ]; - } - - /** - * データの重複チェックを行う - */ - public function testDuplicate() - { - $check = ['id' => 1]; - $result = $this->Page->duplicate($check); - $this->assertEquals(false, $result); - - $check = ['id' => 100]; - $result = $this->Page->duplicate($check); - $this->assertEquals(true, $result); - } - - /** - * 一つ位置を上げる - */ - public function testSortup() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * 一つ位置を下げる - */ - public function testSortdown() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * 並び順を変更する - */ - public function testChangeSort() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * Key Value 形式のテーブルよりデータを取得して - * 1レコードとしてデータを展開する - */ - public function testFindExpanded() - { - $result = $this->SiteConfig->findExpanded(); - - $message = 'Key Value 形式のテーブルよりデータを取得して1レコードとしてデータを展開することができません'; - $this->assertEquals('baserCMS inc. [デモ]', $result['name'], $message); - $this->assertEquals('baser,CMS,コンテンツマネジメントシステム,開発支援', $result['keyword'], $message); - } - - /** - * Key Value 形式のテーブルにデータを保存する - */ - public function testSaveKeyValue() - { - $data = [ - 'SiteConfig' => [ - 'test1' => 'テストです1', - 'test2' => 'テストです2', - ] - ]; - $this->SiteConfig->saveKeyValue($data); - $result = $this->SiteConfig->findExpanded(); - - $message = 'Key Value 形式のテーブルにデータを保存することができません'; - $this->assertEquals('テストです1', $result['test1'], $message); - $this->assertEquals('テストです2', $result['test2'], $message); - - } - - /** - * Deconstructs a complex data type (array or object) into a single field value. - */ - public function testDeconstruct() - { - $field = 'Page.contents'; - $data = [ - 'wareki' => true, - 'year' => 'h-27', - ]; - $result = $this->Page->deconstruct($field, $data); - - $expected = [ - 'wareki' => true, - 'year' => 2015 - ]; - - $this->assertEquals($expected, $result, 'deconstruct が 和暦に対応していません'); - } - - /** - * 指定したモデル以外のアソシエーションを除外する - * - * @param array $auguments アソシエーションを除外しないモデル - * @param array $expectedHasKey 期待する存在するキー - * @param array $expectedNotHasKey 期待する存在しないキー - * @dataProvider reduceAssociationsDataProvider - */ - public function testReduceAssociations($arguments, $expectedHasKeys, $expectedNotHasKeys) - { - $this->User->reduceAssociations($arguments); - $result = $this->User->find('first', ['conditions' => ['User.id' => 2], 'recursive' => 2]); - - // 存在するキー - foreach($expectedHasKeys as $key) { - $this->assertArrayHasKey($key, $result, '指定したモデル以外のアソシエーションを除外できません'); - } - - // 存在しないキー - foreach($expectedNotHasKeys as $key) { - $this->assertArrayNotHasKey($key, $result, '指定したモデル以外のアソシエーションを除外できません'); - } - } - - public function reduceAssociationsDataProvider() - { - return [ - [[], ['User'], ['UserGroup', 'Favorite']], - [['UserGroup'], ['User', 'UserGroup'], ['Favorite']], - [['UserGroup.Permission'], [], ['Permission']], - [['User', 'UserGroup', 'Favorite'], [], ['Permission']], - ]; - } - - /** - * Deletes multiple model records based on a set of conditions. - */ - public function testDeleteAll() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * Updates multiple model records based on a set of conditions. - */ - public function testUpdateAll() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * Used to report user friendly errors. - * If there is a file app/error.php or app/app_error.php this file will be loaded - * error.php is the AppError class it should extend ErrorHandler class. - */ - public function testCakeError() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * Queries the datasource and returns a result set array. - */ - public function testFind() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * イベントを発火 - */ - public function testDispatchEvent() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * データが公開済みかどうかチェックする - * - * @param boolean $status 公開ステータス - * @param string $publishBegin 公開開始日時 - * @param string $publishEnd 公開終了日時 - * @param boolean $expect - * @dataProvider isPublishDataProvider - */ - public function testIsPublish($status, $publishBegin, $publishEnd, $expect) - { - $result = $this->BcApp->isPublish($status, $publishBegin, $publishEnd); - $this->assertEquals($expect, $result); - } - - public function isPublishDataProvider() - { - return [ - [true, null, null, true], - [false, null, null, false], - [true, '2015-01-01 00:00:00', null, true], - [true, '3000-01-01 00:00:00', null, false], - [true, null, '2015-01-01 00:00:00', false], - [true, null, '3000-01-01 00:00:00', true], - [true, '2015-01-01 00:00:00', '3000-01-01 00:00:00', true], - [true, '2015-01-01 00:00:00', '2015-01-02 00:00:00', false], - ]; - } - - /** - * ツリーより再帰的に削除する - */ - public function testRemoveFromTreeRecursive() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - public function testExists() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - public function testDelete() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - public function testDataIter() - { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - } - - /** - * @test モデルのモックが作成できるかテスト - */ - public function testGetMock() - { - $expect = 'do not save!'; - $Model = $this->getMockForModel('BcAppModel', ['save']); - $Model->expects($this->any()) - ->method('save') - ->will($this->returnValue($expect)); - - $actual = $Model->save(['Hoge' => ['name' => 'fuga']]); - $this->assertEquals($expect, $actual, 'スタブが正しく実行されること'); - - } - - /** - * 公開済の conditions を取得 - */ - public function testGetConditionAllowPublish() - { - $result = $this->BcApp->getConditionAllowPublish(); - $pattern = '/' . '([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})' . '/'; - $this->assertMatchesRegularExpression($pattern, $result[0]['or']['0']['BcApp.publish_begin <=']); - $this->assertEquals($result[0]['or']['1']['BcApp.publish_begin'], null); - $this->assertMatchesRegularExpression($pattern, $result[1]['or']['0']['BcApp.publish_end >=']); - $this->assertEquals($result[1]['or']['1']['BcApp.publish_end'], null); - } - -} diff --git a/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php b/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php index f41450c54d..33369c04e9 100644 --- a/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php +++ b/plugins/baser-core/tests/TestCase/Model/Validation/BcValidationTest.php @@ -599,5 +599,30 @@ public function test_checkSelectList() $this->assertTrue($result); } + /** + * 範囲を指定しての長さチェック + * + * @param mixed $check + * @param int $min + * @param int $max + * @param boolean $expect + * @dataProvider betweenDataProvider + */ + public function testBetween($check, $min, $max, $expect) + { + $this->markTestIncomplete('このテストはまだ実装されていません。'); + $result = $this->BcApp->between($check, $min, $max); + $this->assertEquals($expect, $result); + } + + public function betweenDataProvider() + { + return [ + ["あいう", 2, 4, true], + ["あいう", 3, 3, true], + ["あいう", 4, 3, false], + [["あいう", "あいうえお"], 2, 4, true], + ]; + } }