diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8764193 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# Remove files for archives generated using `git archive` +Test export-ignore +.gitattributes export-ignore +.travis.yml export-ignore +phpunit.xml.dist export-ignore 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/Config/Migration/001_plugin_records.php b/Config/Migration/001_plugin_records.php new file mode 100644 index 0000000..3bcad83 --- /dev/null +++ b/Config/Migration/001_plugin_records.php @@ -0,0 +1,139 @@ + + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('NetCommonsMigration', 'NetCommons.Config/Migration'); +App::uses('Space', 'Rooms.Model'); + +/** + * Add plugin migration + * + * @package NetCommons\PluginManager\Config\Migration + */ +class PluginRecords extends NetCommonsMigration { + +/** + * Migration description + * + * @var string + */ + public $description = 'plugin_records'; + +/** + * Actions to be performed + * + * @var array $migration + */ + public $migration = array( + 'up' => array(), + 'down' => array(), + ); + +/** + * plugin data + * + * @var array $migration + */ + public $records = array( + 'Plugin' => array( + //日本語 + array( + 'language_id' => '2', + 'is_origin' => true, + 'is_translation' => true, + 'key' => 'links', + 'namespace' => 'netcommons/links', + 'name' => 'リンクリスト', + 'type' => 1, + 'default_action' => 'links/index', + 'default_setting_action' => 'link_blocks/index', + 'display_topics' => 1, + 'display_search' => 1, + ), + //英語 + array( + 'language_id' => '1', + 'is_origin' => false, + 'is_translation' => true, + 'key' => 'links', + 'namespace' => 'netcommons/links', + 'name' => 'Bookmark List', + 'type' => 1, + 'default_action' => 'links/index', + 'default_setting_action' => 'link_blocks/index', + 'display_topics' => 1, + 'display_search' => 1, + ), + ), + 'PluginsRole' => array( + array( + 'role_key' => 'room_administrator', + 'plugin_key' => 'links' + ), + ), + //PluginsRoomは、beforeでセットする + ); + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + $pluginName = $this->records['Plugin'][0]['key']; + $this->records['PluginsRoom'] = array( + //サイト全体 + array( + 'room_id' => Space::getRoomIdRoot(Space::WHOLE_SITE_ID, 'Room'), + 'plugin_key' => $pluginName + ), + //パブリックスペース + array( + 'room_id' => Space::getRoomIdRoot(Space::PUBLIC_SPACE_ID, 'Room'), + 'plugin_key' => $pluginName + ), + //プライベートスペース + array( + 'room_id' => Space::getRoomIdRoot(Space::PRIVATE_SPACE_ID, 'Room'), + 'plugin_key' => $pluginName + ), + //グループスペース + array( + 'room_id' => Space::getRoomIdRoot(Space::COMMUNITY_SPACE_ID, 'Room'), + 'plugin_key' => $pluginName + ), + ); + return true; + } + +/** + * After migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function after($direction) { + $this->loadModels([ + 'Plugin' => 'PluginManager.Plugin', + ]); + + if ($direction === 'down') { + $this->Plugin->uninstallPlugin($this->records['Plugin'][0]['key']); + return true; + } + + foreach ($this->records as $model => $records) { + if (!$this->updateRecords($model, $records)) { + return false; + } + } + return true; + } +} diff --git a/Config/Migration/002_mail_setting_records.php b/Config/Migration/002_mail_setting_records.php new file mode 100644 index 0000000..05f8544 --- /dev/null +++ b/Config/Migration/002_mail_setting_records.php @@ -0,0 +1,125 @@ + + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('MailsMigration', 'Mails.Config/Migration'); + +/** + * メール設定データのMigration + * + * @package NetCommons\Mails\Config\Migration + */ +class LinkMailSettingRecords extends MailsMigration { + +/** + * プラグインキー + * + * @var string + */ + const PLUGIN_KEY = 'links'; + +/** + * Migration description + * + * @var string + */ + public $description = 'mail_setting_records'; + +/** + * Actions to be performed + * + * @var array $migration + */ + public $migration = array( + 'up' => array(), + 'down' => array(), + ); + +/** + * plugin data + * + * @var array $migration + */ + public $records = array( + 'MailSetting' => array( + //コンテンツ通知 - 設定 + array( + 'plugin_key' => self::PLUGIN_KEY, + 'block_key' => null, + 'is_mail_send' => false, + 'is_mail_send_approval' => true, + ), + ), + 'MailSettingFixedPhrase' => array( + //コンテンツ通知 - 定型文 + // * 英語 + array( + 'language_id' => '1', + 'plugin_key' => self::PLUGIN_KEY, + 'block_key' => null, + 'type_key' => 'contents', + 'mail_fixed_phrase_subject' => '', //デフォルト(__d('mails', 'MailSetting.mail_fixed_phrase_subject')) + 'mail_fixed_phrase_body' => '{X-PLUGIN_NAME}にリンクが追加されたのでお知らせします。 +ルーム名: {X-ROOM} +リンクリスト名: {X-BLOCK_NAME} +リンク先: {X-LINK_URL} +タイトル: {X-TITLE} +カテゴリ: {X-CATEGORY_NAME} +登録者: {X-USER} +登録日時: {X-TO_DATE} +説明: +{X-DESCRIPTION} + +このリンクを確認するには、下記アドレスへ +{X-URL}', + ), + // * 日本語 + array( + 'language_id' => '2', + 'plugin_key' => self::PLUGIN_KEY, + 'block_key' => null, + 'type_key' => 'contents', + 'mail_fixed_phrase_subject' => '', + 'mail_fixed_phrase_body' => '{X-PLUGIN_NAME}にリンクが追加されたのでお知らせします。 +ルーム名: {X-ROOM} +リンクリスト名: {X-BLOCK_NAME} +リンク先: {X-LINK_URL} +タイトル: {X-TITLE} +カテゴリ: {X-CATEGORY_NAME} +登録者: {X-USER} +登録日時: {X-TO_DATE} +説明: +{X-DESCRIPTION} + +このリンクについて確認するには、下記アドレスへ +{X-URL}', + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + return true; + } + +/** + * After migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function after($direction) { + return parent::updateAndDelete($direction, self::PLUGIN_KEY); + } +} diff --git a/Config/Migration/1430464483_initial.php b/Config/Migration/1430464483_initial.php new file mode 100644 index 0000000..92eb280 --- /dev/null +++ b/Config/Migration/1430464483_initial.php @@ -0,0 +1,130 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +/** + * Migration file + * + * @author Shohei Nakajima + * @package NetCommons\Faqs\Config\Migration + */ +class Initial extends CakeMigration { + +/** + * Migration description + * + * @var string + */ + public $description = 'initial'; + +/** + * Actions to be performed + * + * @var array $migration + */ + public $migration = array( + 'up' => array( + 'create_table' => array( + 'link_frame_settings' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary', 'comment' => 'ID'), + 'frame_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'フレームKey', 'charset' => 'utf8'), + 'display_type' => array('type' => 'integer', 'null' => false, 'default' => '1', 'length' => 4, 'comment' => '表示方法種別 1: ドロップダウン型、2:リスト型(説明なし)、3:リスト型(説明あり)'), + 'open_new_tab' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'comment' => 'リンクの開き方 0:同じウィンドウ内、1:新しいタブ'), + 'display_click_count' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'comment' => 'リンクのクリック数の表示 0:表示しない、1:表示する'), + 'category_separator_line' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'カテゴリ間の区切り線', 'charset' => 'utf8'), + 'list_style' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'リストマーク', 'charset' => 'utf8'), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'comment' => '作成者'), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '作成日時'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'comment' => '更新者'), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '更新日時'), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'), + ), + 'link_orders' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary', 'comment' => 'ID'), + 'block_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'ブロックKey', 'charset' => 'utf8'), + 'category_key' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'カテゴリKey', 'charset' => 'utf8'), + 'link_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'リンクKey', 'charset' => 'utf8'), + 'weight' => array('type' => 'integer', 'null' => false, 'default' => '0', 'comment' => '表示の重み(表示順序)'), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => '作成者'), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '作成日時'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => '更新者'), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '更新日時'), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'), + ), + 'link_settings' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary', 'comment' => 'ID'), + 'block_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'Block key | ブロックキー | Hash値 | ', 'charset' => 'utf8'), + 'use_workflow' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'comment' => 'Use workflow, 0:Unused 1:Use | コンテンツの承認機能 0:使わない 1:使う | | '), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => '作成者'), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '作成日時'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => '更新者'), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '更新日時'), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'), + ), + 'links' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary', 'comment' => 'ID'), + 'block_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'comment' => 'ブロックID'), + 'category_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'comment' => 'カテゴリーID'), + 'language_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 6, 'comment' => '言語ID'), + 'key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'リンクキー', 'charset' => 'utf8'), + 'status' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 4, 'comment' => '公開状況 1:公開中、2:公開申請中、3:下書き中、4:差し戻し'), + 'is_active' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => 'アクティブなコンテンツかどうか 0:アクティブでない 1:アクティブ'), + 'is_latest' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => '最新コンテンツかどうか 0:最新でない 1:最新'), + 'url' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'リンク先URL', 'charset' => 'utf8'), + 'title' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'タイトル', 'charset' => 'utf8'), + 'description' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '説明', 'charset' => 'utf8'), + 'click_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'comment' => 'クリック数'), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'comment' => '作成者'), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '作成日時'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'comment' => '更新者'), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '更新日時'), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'), + ), + ), + ), + 'down' => array( + 'drop_table' => array( + 'link_frame_settings', 'link_orders', 'link_settings', 'links' + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + return true; + } + +/** + * After migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function after($direction) { + return true; + } +} diff --git a/Config/Migration/1468972227_delete_link_settings.php b/Config/Migration/1468972227_delete_link_settings.php new file mode 100644 index 0000000..f05ca77 --- /dev/null +++ b/Config/Migration/1468972227_delete_link_settings.php @@ -0,0 +1,76 @@ + + * @author Mitsuru Mutaguchi + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +/** + * Migration file + * + * @author Mitsuru Mutaguchi + * @package NetCommons\Links\Config\Migration + */ +class DeleteLinkSettings extends CakeMigration { + +/** + * Migration description + * + * @var string + */ + public $description = 'delete_link_settings'; + +/** + * Actions to be performed + * + * @var array $migration + */ + public $migration = array( + 'up' => array( + 'drop_table' => array( + 'link_settings' + ), + ), + 'down' => array( + 'create_table' => array( + 'link_settings' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary', 'comment' => 'ID'), + 'block_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'Block key | ブロックキー | Hash値 | ', 'charset' => 'utf8'), + 'use_workflow' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'comment' => 'Use workflow, 0:Unused 1:Use | コンテンツの承認機能 0:使わない 1:使う | | '), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => '作成者'), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '作成日時'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => '更新者'), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '更新日時'), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'), + ), + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + return true; + } + +/** + * After migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function after($direction) { + return true; + } +} diff --git a/Config/Migration/1469438065_add_index.php b/Config/Migration/1469438065_add_index.php new file mode 100644 index 0000000..3d3b890 --- /dev/null +++ b/Config/Migration/1469438065_add_index.php @@ -0,0 +1,132 @@ + + * @author Mitsuru Mutaguchi + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +/** + * Migration file + * + * @author Mitsuru Mutaguchi + * @package NetCommons\Links\Config\Migration + */ +class AddIndex extends CakeMigration { + +/** + * Migration description + * + * @var string + */ + public $description = 'add_index'; + +/** + * Actions to be performed + * + * @var array $migration + */ + public $migration = array( + 'up' => array( + 'alter_field' => array( + 'link_frame_settings' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary', 'comment' => 'ID'), + 'frame_key' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'comment' => 'フレームKey', 'charset' => 'utf8'), + 'display_type' => array('type' => 'integer', 'null' => false, 'default' => '1', 'length' => 4, 'unsigned' => false, 'comment' => '表示方法種別 1: ドロップダウン型、2:リスト型(説明なし)、3:リスト型(説明あり)'), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'comment' => '作成者'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'comment' => '更新者'), + ), + 'link_orders' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary', 'comment' => 'ID'), + 'link_key' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'comment' => 'リンクKey', 'charset' => 'utf8'), + 'weight' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false, 'comment' => '表示の重み(表示順序)'), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => '作成者'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => '更新者'), + ), + 'links' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary', 'comment' => 'ID'), + 'block_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'index', 'comment' => 'ブロックID'), + 'category_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'comment' => 'カテゴリーID'), + 'language_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 6, 'unsigned' => false, 'comment' => '言語ID'), + 'status' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 4, 'unsigned' => false, 'comment' => '公開状況 1:公開中、2:公開申請中、3:下書き中、4:差し戻し'), + 'click_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false, 'comment' => 'クリック数'), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'comment' => '作成者'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'comment' => '更新者'), + ), + ), + 'create_field' => array( + 'link_frame_settings' => array( + 'indexes' => array( + 'frame_key' => array('column' => 'frame_key', 'unique' => 0), + ), + ), + 'link_orders' => array( + 'indexes' => array( + 'link_key' => array('column' => 'link_key', 'unique' => 0), + ), + ), + 'links' => array( + 'indexes' => array( + 'block_id' => array('column' => array('block_id', 'language_id'), 'unique' => 0), + ), + ), + ), + ), + 'down' => array( + 'alter_field' => array( + 'link_frame_settings' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary', 'comment' => 'ID'), + 'frame_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'フレームKey', 'charset' => 'utf8'), + 'display_type' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 4, 'comment' => '表示方法種別 1: ドロップダウン型、2:リスト型(説明なし)、3:リスト型(説明あり)'), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'comment' => '作成者'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'comment' => '更新者'), + ), + 'link_orders' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary', 'comment' => 'ID'), + 'link_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'リンクKey', 'charset' => 'utf8'), + 'weight' => array('type' => 'integer', 'null' => false, 'default' => '0', 'comment' => '表示の重み(表示順序)'), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => '作成者'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => '更新者'), + ), + 'links' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary', 'comment' => 'ID'), + 'block_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'comment' => 'ブロックID'), + 'category_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'comment' => 'カテゴリーID'), + 'language_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 6, 'comment' => '言語ID'), + 'status' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 4, 'comment' => '公開状況 1:公開中、2:公開申請中、3:下書き中、4:差し戻し'), + 'click_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'comment' => 'クリック数'), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'comment' => '作成者'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'comment' => '更新者'), + ), + ), + 'drop_field' => array( + 'link_frame_settings' => array('indexes' => array('frame_key')), + 'link_orders' => array('indexes' => array('link_key')), + 'links' => array('indexes' => array('block_id')), + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + return true; + } + +/** + * After migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function after($direction) { + return true; + } +} diff --git a/Config/Migration/1481097090_add_fields_for_m17n.php b/Config/Migration/1481097090_add_fields_for_m17n.php new file mode 100644 index 0000000..129675c --- /dev/null +++ b/Config/Migration/1481097090_add_fields_for_m17n.php @@ -0,0 +1,68 @@ + + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('NetCommonsMigration', 'NetCommons.Config/Migration'); + +/** + * 多言語化対応 + * + * @author Shohei Nakajima + * @package NetCommons\Links\Config\Migration + */ +class AddFieldsForM17n extends NetCommonsMigration { + +/** + * Migration description + * + * @var string + */ + public $description = 'add_fields_for_m17n'; + +/** + * Actions to be performed + * + * @var array $migration + */ + public $migration = array( + 'up' => array( + 'create_field' => array( + 'links' => array( + 'is_origin' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'comment' => 'オリジナルかどうか', 'after' => 'language_id'), + 'is_translation' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => '翻訳したかどうか', 'after' => 'is_origin'), + ), + ), + ), + 'down' => array( + 'drop_field' => array( + 'links' => array('is_origin', 'is_translation'), + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + return true; + } + +/** + * After migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function after($direction) { + return true; + } +} diff --git a/Config/Migration/1484545481_add_is_original_copy.php b/Config/Migration/1484545481_add_is_original_copy.php new file mode 100644 index 0000000..1cfd16d --- /dev/null +++ b/Config/Migration/1484545481_add_is_original_copy.php @@ -0,0 +1,67 @@ + + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('NetCommonsMigration', 'NetCommons.Config/Migration'); + +/** + * 多言語化対応 + * + * @author Shohei Nakajima + * @package NetCommons\Links\Config\Migration + */ +class AddIsOriginalCopy extends NetCommonsMigration { + +/** + * Migration description + * + * @var string + */ + public $description = 'add_is_original_copy'; + +/** + * Actions to be performed + * + * @var array $migration + */ + public $migration = array( + 'up' => array( + 'create_field' => array( + 'links' => array( + 'is_original_copy' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => 'オリジナルのコピー。言語を新たに追加したときに使用する', 'after' => 'is_translation'), + ), + ), + ), + 'down' => array( + 'drop_field' => array( + 'links' => array('is_original_copy'), + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + return true; + } + +/** + * After migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function after($direction) { + return true; + } +} diff --git a/Config/Schema/empty b/Config/Schema/empty deleted file mode 100644 index e69de29..0000000 diff --git a/Config/Schema/schema.php b/Config/Schema/schema.php new file mode 100644 index 0000000..ae2cd06 --- /dev/null +++ b/Config/Schema/schema.php @@ -0,0 +1,126 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +/** + * Schema file + * + * @author Noriko Arai + * @author Shohei Nakajima + * @package NetCommons\Likes\Config\Schema + * @SuppressWarnings(PHPMD.LongVariable) + */ +class LinksSchema extends CakeSchema { + +/** + * Database connection + * + * @var string + */ + public $connection = 'master'; + +/** + * before + * + * @param array $event event + * @return bool + */ + public function before($event = array()) { + return true; + } + +/** + * after + * + * @param array $event event + * @return void + */ + public function after($event = array()) { + } + +/** + * link_frame_settings table + * + * @var array + */ + public $link_frame_settings = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary', 'comment' => 'ID'), + 'frame_key' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'comment' => 'フレームKey', 'charset' => 'utf8'), + 'display_type' => array('type' => 'integer', 'null' => false, 'default' => '1', 'length' => 4, 'unsigned' => false, 'comment' => '表示方法種別 1: ドロップダウン型、2:リスト型(説明なし)、3:リスト型(説明あり)'), + 'open_new_tab' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'comment' => 'リンクの開き方 0:同じウィンドウ内、1:新しいタブ'), + 'display_click_count' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'comment' => 'リンクのクリック数の表示 0:表示しない、1:表示する'), + 'category_separator_line' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'カテゴリ間の区切り線', 'charset' => 'utf8'), + 'list_style' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'リストマーク', 'charset' => 'utf8'), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'comment' => '作成者'), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '作成日時'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'comment' => '更新者'), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '更新日時'), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'frame_key' => array('column' => 'frame_key', 'unique' => 0) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + +/** + * link_orders table + * + * @var array + */ + public $link_orders = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary', 'comment' => 'ID'), + 'block_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'ブロックKey', 'charset' => 'utf8'), + 'category_key' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'カテゴリKey', 'charset' => 'utf8'), + 'link_key' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'comment' => 'リンクKey', 'charset' => 'utf8'), + 'weight' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false, 'comment' => '表示の重み(表示順序)'), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => '作成者'), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '作成日時'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => '更新者'), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '更新日時'), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'link_key' => array('column' => 'link_key', 'unique' => 0) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + +/** + * links table + * + * @var array + */ + public $links = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary', 'comment' => 'ID'), + 'block_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'index', 'comment' => 'ブロックID'), + 'category_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'comment' => 'カテゴリーID'), + 'language_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 6, 'unsigned' => false, 'comment' => '言語ID'), + 'is_origin' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'comment' => 'オリジナルかどうか'), + 'is_translation' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => '翻訳したかどうか'), + 'is_original_copy' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => 'オリジナルのコピー。言語を新たに追加したときに使用する'), + 'key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'リンクキー', 'charset' => 'utf8'), + 'status' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 4, 'unsigned' => false, 'comment' => '公開状況 1:公開中、2:公開申請中、3:下書き中、4:差し戻し'), + 'is_active' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => 'アクティブなコンテンツかどうか 0:アクティブでない 1:アクティブ'), + 'is_latest' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => '最新コンテンツかどうか 0:最新でない 1:最新'), + 'url' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'リンク先URL', 'charset' => 'utf8'), + 'title' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'タイトル', 'charset' => 'utf8'), + 'description' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '説明', 'charset' => 'utf8'), + 'click_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false, 'comment' => 'クリック数'), + 'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'comment' => '作成者'), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '作成日時'), + 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'comment' => '更新者'), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '更新日時'), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'block_id' => array('column' => array('block_id', 'language_id'), 'unique' => 0) + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + +} diff --git a/Console/Command/Task/empty b/Console/Command/Task/empty deleted file mode 100644 index e69de29..0000000 diff --git a/Controller/Component/empty b/Controller/Component/empty deleted file mode 100644 index e69de29..0000000 diff --git a/Controller/LinkBlockRolePermissionsController.php b/Controller/LinkBlockRolePermissionsController.php new file mode 100644 index 0000000..701b428 --- /dev/null +++ b/Controller/LinkBlockRolePermissionsController.php @@ -0,0 +1,98 @@ + + * @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('LinksAppController', 'Links.Controller'); + +/** + * BlockRolePermissions Controller + * + * @author Shohei Nakajima + * @package NetCommons\Links\Controller + */ +class LinkBlockRolePermissionsController extends LinksAppController { + +/** + * layout + * + * @var array + */ + public $layout = 'NetCommons.setting'; + +/** + * use models + * + * @var array + */ + public $uses = array( + 'Links.LinkBlock', + 'Links.LinkSetting', + ); + +/** + * use components + * + * @var array + */ + public $components = array( + 'NetCommons.Permission' => array( + 'allow' => array( + 'edit' => 'block_permission_editable', + ), + ), + ); + +/** + * use helpers + * + * @var array + */ + public $helpers = array( + 'Blocks.BlockRolePermissionForm', + 'Blocks.BlockTabs' => array( + 'mainTabs' => array('block_index', 'frame_settings'), + 'blockTabs' => array('block_settings', 'mail_settings', 'role_permissions'), + ), + ); + +/** + * edit + * + * @return void + */ + public function edit() { + if (! $linkBlock = $this->LinkBlock->getLinkBlock()) { + return $this->throwBadRequest(); + } + + $permissions = $this->Workflow->getBlockRolePermissions( + array('content_creatable', 'content_publishable') + ); + $this->set('roles', $permissions['Roles']); + + if ($this->request->is('post')) { + if ($this->LinkSetting->saveLinkSetting($this->request->data)) { + $this->redirect(NetCommonsUrl::backToIndexUrl('default_setting_action')); + return; + } + $this->NetCommons->handleValidationError($this->LinkSetting->validationErrors); + $this->request->data['BlockRolePermission'] = Hash::merge( + $permissions['BlockRolePermissions'], + $this->request->data['BlockRolePermission'] + ); + + } else { + $this->request->data['LinkSetting'] = $linkBlock['LinkSetting']; + $this->request->data['Block'] = $linkBlock['Block']; + $this->request->data['BlockRolePermission'] = $permissions['BlockRolePermissions']; + $this->request->data['Frame'] = Current::read('Frame'); + } + } +} diff --git a/Controller/LinkBlocksController.php b/Controller/LinkBlocksController.php new file mode 100644 index 0000000..448074f --- /dev/null +++ b/Controller/LinkBlocksController.php @@ -0,0 +1,163 @@ + + * @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('LinksAppController', 'Links.Controller'); + +/** + * BlocksController + * + * @author Shohei Nakajima + * @package NetCommons\Links\Controller + */ +class LinkBlocksController extends LinksAppController { + +/** + * layout + * + * @var array + */ + public $layout = 'NetCommons.setting'; + +/** + * use models + * + * @var array + */ + public $uses = array( + 'Links.LinkBlock', + ); + +/** + * use components + * + * @var array + */ + public $components = array( + 'Categories.CategoryEdit', + 'NetCommons.Permission' => array( + 'allow' => array( + 'index,add,edit,delete' => 'block_editable', + ), + ), + 'Paginator', + 'Categories.Categories', + ); + +/** + * use helpers + * + * @var array + */ + public $helpers = array( + 'Blocks.BlockForm', + 'Blocks.BlockIndex', + 'Blocks.BlockTabs' => array( + 'mainTabs' => array('block_index', 'frame_settings'), + 'blockTabs' => array('block_settings', 'mail_settings', 'role_permissions'), + ), + ); + +/** + * beforeFilter + * + * @return void + */ + public function beforeFilter() { + parent::beforeFilter(); + $this->Auth->deny('index'); + + //CategoryEditComponentの削除 + if ($this->params['action'] === 'index') { + $this->Components->unload('Categories.CategoryEdit'); + } + } + +/** + * index + * + * @return void + */ + public function index() { + $this->Paginator->settings = array( + 'LinkBlock' => $this->LinkBlock->getBlockIndexSettings() + ); + + $linkBlocks = $this->Paginator->paginate('LinkBlock'); + if (! $linkBlocks) { + $this->view = 'Blocks.Blocks/not_found'; + return; + } + $this->set('linkBlocks', $linkBlocks); + $this->request->data['Frame'] = Current::read('Frame'); + } + +/** + * add + * + * @return void + */ + public function add() { + $this->view = 'edit'; + + if ($this->request->is('post')) { + //登録処理 + if ($this->LinkBlock->saveLinkBlock($this->data)) { + return $this->redirect(NetCommonsUrl::backToIndexUrl('default_setting_action')); + } + $this->NetCommons->handleValidationError($this->LinkBlock->validationErrors); + + } else { + //表示処理(初期データセット) + $this->request->data = $this->LinkBlock->createLinkBlock(); + $this->request->data['Frame'] = Current::read('Frame'); + } + } + +/** + * edit + * + * @return void + */ + public function edit() { + if ($this->request->is('put')) { + //登録処理 + if ($this->LinkBlock->saveLinkBlock($this->data)) { + return $this->redirect(NetCommonsUrl::backToIndexUrl('default_setting_action')); + } + $this->NetCommons->handleValidationError($this->LinkBlock->validationErrors); + + } else { + //表示処理(初期データセット) + $linkBlock = $this->LinkBlock->getLinkBlock(); + if (! $linkBlock) { + return $this->throwBadRequest(); + } + $this->request->data += $linkBlock; + $this->request->data['Frame'] = Current::read('Frame'); + } + } + +/** + * delete + * + * @return void + */ + public function delete() { + if (! $this->request->is('delete')) { + return $this->throwBadRequest(); + } + if (! $this->LinkBlock->deleteLinkBlock($this->data)) { + return $this->throwBadRequest(); + } + + $this->redirect(NetCommonsUrl::backToIndexUrl('default_setting_action')); + } +} diff --git a/Controller/LinkFrameSettingsController.php b/Controller/LinkFrameSettingsController.php new file mode 100644 index 0000000..9b216de --- /dev/null +++ b/Controller/LinkFrameSettingsController.php @@ -0,0 +1,95 @@ + + * @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('LinksAppController', 'Links.Controller'); + +/** + * LinkFrameSettingsController Controller + * + * @author Shohei Nakajima + * @package NetCommons\Links\Controller + */ +class LinkFrameSettingsController extends LinksAppController { + +/** + * layout + * + * @var array + */ + public $layout = 'NetCommons.setting'; + +/** + * use models + * + * @var array + */ + public $uses = array( + 'Links.LinkFrameSetting' + ); + +/** + * use components + * + * @var array + */ + public $components = array( + 'NetCommons.Permission' => array( + 'allow' => array( + 'edit' => 'page_editable', + ), + ), + ); + +/** + * use helpers + * + * @var array + */ + public $helpers = array( + 'Blocks.BlockForm', + 'Blocks.BlockTabs' => array( + 'mainTabs' => array('block_index', 'frame_settings'), + 'blockTabs' => array('block_settings', 'role_permissions'), + ), + ); + +/** + * edit + * + * @return void + */ + public function edit() { + if ($this->request->is('put') || $this->request->is('post')) { + if (isset($this->request->data['LinkFrameSetting']['has_description']) && + $this->request->data['LinkFrameSetting']['has_description']) { + $this->request->data['LinkFrameSetting']['display_type'] + = LinkFrameSetting::TYPE_LIST_WITH_DESCRIPTION; + } + + if ($this->LinkFrameSetting->saveLinkFrameSetting($this->request->data)) { + return $this->redirect(NetCommonsUrl::backToPageUrl(true)); + } else { + return $this->throwBadRequest(); + } + + } else { + $this->request->data = $this->LinkFrameSetting->getLinkFrameSetting(true); + $displayType = $this->request->data['LinkFrameSetting']['display_type']; + if ($displayType === LinkFrameSetting::TYPE_LIST_WITH_DESCRIPTION) { + $this->request->data['LinkFrameSetting']['has_description'] = true; + $this->request->data['LinkFrameSetting']['display_type'] + = LinkFrameSetting::TYPE_LIST_ONLY_TITLE; + } + + $this->request->data['Frame'] = Current::read('Frame'); + } + } +} diff --git a/Controller/LinkListsAppController.php b/Controller/LinkListsAppController.php deleted file mode 100644 index 1a01fb3..0000000 --- a/Controller/LinkListsAppController.php +++ /dev/null @@ -1,7 +0,0 @@ - -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ -class LinkListsCategoriesController extends LinkListsAppController { - -/** - * Components - * - * @var array - */ - public $components = array('Paginator'); - -/** - * index method - * - * @return void - */ - public function index() { - $this->LinkListsCategory->recursive = 0; - $this->set('linkListsCategories', $this->Paginator->paginate()); - } - -/** - * view method - * - * @throws NotFoundException - * @param string $id - * @return void - */ - public function view($id = null) { - if (!$this->LinkListsCategory->exists($id)) { - throw new NotFoundException(__('Invalid link lists category')); - } - $options = array('conditions' => array('LinkListsCategory.' . $this->LinkListsCategory->primaryKey => $id)); - $this->set('linkListsCategory', $this->LinkListsCategory->find('first', $options)); - } - -/** - * add method - * - * @return void - */ - public function add() { - if ($this->request->is('post')) { - $this->LinkListsCategory->create(); - if ($this->LinkListsCategory->save($this->request->data)) { - $this->Session->setFlash(__('The link lists category has been saved.')); - return $this->redirect(array('action' => 'index')); - } else { - $this->Session->setFlash(__('The link lists category could not be saved. Please, try again.')); - } - } - $linklistsBlocks = $this->LinkListsCategory->LinklistsBlock->find('list'); - $languages = $this->LinkListsCategory->Language->find('list'); - $this->set(compact('linklistsBlocks', 'languages')); - } - -/** - * edit method - * - * @throws NotFoundException - * @param string $id - * @return void - */ - public function edit($id = null) { - if (!$this->LinkListsCategory->exists($id)) { - throw new NotFoundException(__('Invalid link lists category')); - } - if ($this->request->is(array('post', 'put'))) { - if ($this->LinkListsCategory->save($this->request->data)) { - $this->Session->setFlash(__('The link lists category has been saved.')); - return $this->redirect(array('action' => 'index')); - } else { - $this->Session->setFlash(__('The link lists category could not be saved. Please, try again.')); - } - } else { - $options = array('conditions' => array('LinkListsCategory.' . $this->LinkListsCategory->primaryKey => $id)); - $this->request->data = $this->LinkListsCategory->find('first', $options); - } - $linklistsBlocks = $this->LinkListsCategory->LinklistsBlock->find('list'); - $languages = $this->LinkListsCategory->Language->find('list'); - $this->set(compact('linklistsBlocks', 'languages')); - } - -/** - * delete method - * - * @throws NotFoundException - * @param string $id - * @return void - */ - public function delete($id = null) { - $this->LinkListsCategory->id = $id; - if (!$this->LinkListsCategory->exists()) { - throw new NotFoundException(__('Invalid link lists category')); - } - $this->request->onlyAllow('post', 'delete'); - if ($this->LinkListsCategory->delete()) { - $this->Session->setFlash(__('The link lists category has been deleted.')); - } else { - $this->Session->setFlash(__('The link lists category could not be deleted. Please, try again.')); - } - return $this->redirect(array('action' => 'index')); - }} diff --git a/Controller/LinkListsController.php b/Controller/LinkListsController.php deleted file mode 100644 index fc5b237..0000000 --- a/Controller/LinkListsController.php +++ /dev/null @@ -1,117 +0,0 @@ - -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ -class LinkListsController extends LinkListsAppController { - -/** - * Components - * - * @var array - */ - public $components = array('Paginator'); - -/** - * index method - * - * @return void - */ - public function index() { - $this->LinkList->recursive = 0; - $this->set('linkLists', $this->Paginator->paginate()); - } - -/** - * view method - * - * @throws NotFoundException - * @param string $id - * @return void - */ - public function view($id = null) { - if (!$this->LinkList->exists($id)) { - throw new NotFoundException(__('Invalid link list')); - } - $options = array('conditions' => array('LinkList.' . $this->LinkList->primaryKey => $id)); - $this->set('linkList', $this->LinkList->find('first', $options)); - } - -/** - * add method - * - * @return void - */ - public function add() { - if ($this->request->is('post')) { - $this->LinkList->create(); - if ($this->LinkList->save($this->request->data)) { - $this->Session->setFlash(__('The link list has been saved.')); - return $this->redirect(array('action' => 'index')); - } else { - $this->Session->setFlash(__('The link list could not be saved. Please, try again.')); - } - } - $linklistsBlocks = $this->LinkList->LinklistsBlock->find('list'); - $languages = $this->LinkList->Language->find('list'); - $linklistsCategories = $this->LinkList->LinklistsCategory->find('list'); - $blocks = $this->LinkList->Block->find('list'); - $this->set(compact('linklistsBlocks', 'languages', 'linklistsCategories', 'blocks')); - } - -/** - * edit method - * - * @throws NotFoundException - * @param string $id - * @return void - */ - public function edit($id = null) { - if (!$this->LinkList->exists($id)) { - throw new NotFoundException(__('Invalid link list')); - } - if ($this->request->is(array('post', 'put'))) { - if ($this->LinkList->save($this->request->data)) { - $this->Session->setFlash(__('The link list has been saved.')); - return $this->redirect(array('action' => 'index')); - } else { - $this->Session->setFlash(__('The link list could not be saved. Please, try again.')); - } - } else { - $options = array('conditions' => array('LinkList.' . $this->LinkList->primaryKey => $id)); - $this->request->data = $this->LinkList->find('first', $options); - } - $linklistsBlocks = $this->LinkList->LinklistsBlock->find('list'); - $languages = $this->LinkList->Language->find('list'); - $linklistsCategories = $this->LinkList->LinklistsCategory->find('list'); - $blocks = $this->LinkList->Block->find('list'); - $this->set(compact('linklistsBlocks', 'languages', 'linklistsCategories', 'blocks')); - } - -/** - * delete method - * - * @throws NotFoundException - * @param string $id - * @return void - */ - public function delete($id = null) { - $this->LinkList->id = $id; - if (!$this->LinkList->exists()) { - throw new NotFoundException(__('Invalid link list')); - } - $this->request->onlyAllow('post', 'delete'); - if ($this->LinkList->delete()) { - $this->Session->setFlash(__('The link list has been deleted.')); - } else { - $this->Session->setFlash(__('The link list could not be deleted. Please, try again.')); - } - return $this->redirect(array('action' => 'index')); - }} diff --git a/Controller/LinkMailSettingsController.php b/Controller/LinkMailSettingsController.php new file mode 100644 index 0000000..b0b7705 --- /dev/null +++ b/Controller/LinkMailSettingsController.php @@ -0,0 +1,36 @@ + + * @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('MailSettingsController', 'Mails.Controller'); + +/** + * メール設定Controller + * + * @author Shohei Nakajima + * @package NetCommons\Links\Controller + */ +class LinkMailSettingsController extends MailSettingsController { + +/** + * use helpers + * + * @var array + */ + public $helpers = array( + 'Blocks.BlockRolePermissionForm', + 'Blocks.BlockTabs' => array( + 'mainTabs' => array('block_index', 'frame_settings'), + 'blockTabs' => array('block_settings', 'mail_settings', 'role_permissions'), + ), + 'Mails.MailForm', + ); + +} diff --git a/Controller/LinkOrdersController.php b/Controller/LinkOrdersController.php new file mode 100644 index 0000000..88ebe4b --- /dev/null +++ b/Controller/LinkOrdersController.php @@ -0,0 +1,103 @@ + + * @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('LinksAppController', 'Links.Controller'); + +/** + * LinkOrders Controller + * + * @author Shohei Nakajima + * @package NetCommons\Links\Controller + */ +class LinkOrdersController extends LinksAppController { + +/** + * use models + * + * @var array + */ + public $uses = array( + 'Links.Link', + 'Links.LinkBlock', + 'Links.LinkOrder', + 'Categories.Category', + 'Categories.CategoriesLanguage', + ); + +/** + * use component + * + * @var array + */ + public $components = array( + 'NetCommons.Permission' => array( + 'allow' => array( + 'edit' => 'content_editable', + ), + ), + 'Categories.Categories', + ); + +/** + * edit + * + * @return void + */ + public function edit() { + $linkBlock = $this->LinkBlock->getLinkBlock(); + if (! $linkBlock) { + return $this->throwBadRequest(); + } + + if ($this->request->is('put')) { + if ($this->LinkOrder->saveLinkOrders($this->data)) { + return $this->redirect(NetCommonsUrl::backToPageUrl()); + } + $this->NetCommons->handleValidationError($this->LinkOrder->validationErrors); + + } else { + //カテゴリ + array_unshift($this->viewVars['categories'], ( + $this->Category->create(['id' => 0]) + + $this->CategoriesLanguage->create(['name' => __d('links', 'No Category')]) + )); + + $this->request->data['Frame'] = Current::read('Frame'); + $this->request->data['Block'] = Current::read('Block'); + } + + //リンクデータ取得 + $results = $this->Link->find('all', array( + 'recursive' => 0, + 'conditions' => array( + 'Link.block_id' => Current::read('Block.id'), + 'Link.is_latest' => true, + ), + 'order' => array( + 'CategoryOrder.weight' => 'asc', + 'LinkOrder.weight' => 'asc', + ), + )); + + $links = []; + $linkOrders = []; + foreach ($results as $result) { + $categoryId = (int)$result['Link']['category_id']; + $linkOrder = $result['LinkOrder']; + $links[$categoryId][] = $result; + $linkOrders[$linkOrder['id']] = $result; + } + $this->request->data['LinkOrders'] = $linkOrders; + $this->set('links', $links); + $this->set('linkBlock', $linkBlock['LinkBlock']); + } + +} diff --git a/Controller/LinksAppController.php b/Controller/LinksAppController.php new file mode 100644 index 0000000..fa171ce --- /dev/null +++ b/Controller/LinksAppController.php @@ -0,0 +1,32 @@ + + * @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('AppController', 'Controller'); +App::uses('LinkFrameSetting', 'Links.Model'); + +/** + * LinksApp Controller + * + * @author Shohei Nakajima + * @package NetCommons\Links\Controller + */ +class LinksAppController extends AppController { + +/** + * use component + * + * @var array + */ + public $components = array( + 'Pages.PageLayout', + 'Security', + ); +} diff --git a/Controller/LinksController.php b/Controller/LinksController.php new file mode 100644 index 0000000..72aa6e1 --- /dev/null +++ b/Controller/LinksController.php @@ -0,0 +1,394 @@ + + * @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('LinksAppController', 'Links.Controller'); +App::uses('HttpSocket', 'Network/Http'); + +/** + * Links Controller + * + * @author Shohei Nakajima + * @package NetCommons\Links\Controller + */ +class LinksController extends LinksAppController { + +/** + * use model + * + * @var array + */ + public $uses = array( + 'Links.Link', + 'Links.LinkBlock', + 'Links.LinkOrder', + 'Links.LinkFrameSetting', + 'Categories.Category', + 'Categories.CategoriesLanguage', + ); + +/** + * use component + * + * @var array + */ + public $components = array( + 'NetCommons.Permission' => array( + 'allow' => array( + 'get,add,edit,delete' => 'content_creatable', + ), + ), + 'Categories.Categories', + ); + +/** + * use helpers + * + * @var array + */ + public $helpers = array( + 'NetCommons.Token', + 'Workflow.Workflow', + ); + +/** + * beforeFilter + * + * @return void + */ + public function beforeFilter() { + parent::beforeFilter(); + $this->Auth->allow('link'); + + if (! Current::read('Block.id')) { + return $this->setAction('emptyRender'); + } + $this->LinkBlock->unbindModel(['belongsTo' => ['TrackableCreator', 'TrackableUpdater']], true); + $linkBlock = $this->LinkBlock->getLinkBlock([ + 'LinkBlock.id', + 'LinkBlock.room_id', + 'LinkBlock.plugin_key', + 'LinkBlock.key', + 'LinkBlock.public_type', + 'LinkBlock.publish_start', + 'LinkBlock.publish_end', + 'LinkBlock.content_count', + 'name' + ]); + if (! $linkBlock) { + return $this->setAction('throwBadRequest'); + } + $this->set('linkBlock', $linkBlock['LinkBlock']); + } + +/** + * index + * + * @return void + */ + public function index() { + $linkFrameSetting = $this->LinkFrameSetting->getLinkFrameSetting(true); + if (! $linkFrameSetting) { + return $this->throwBadRequest(); + } + $this->set('linkFrameSetting', $linkFrameSetting['LinkFrameSetting']); + + //カテゴリ + array_unshift($this->viewVars['categories'], ( + $this->Category->create(['id' => 0]) + + $this->CategoriesLanguage->create(['name' => '']) + )); + + //取得 + $this->Link->unbindModel(['belongsTo' => ['TrackableCreator', 'TrackableUpdater']], true); + $results = $this->Link->getWorkflowContents('all', array( + 'recursive' => 0, + 'fields' => [ + 'Link.id', + 'Link.block_id', + 'Link.category_id', + 'Link.language_id', + 'Link.key', + 'Link.status', + 'Link.url', + 'Link.title', + 'Link.description', + 'Link.click_count', + ], + 'conditions' => array( + 'Link.block_id' => Current::read('Block.id'), + ), + 'order' => array( + 'CategoryOrder.weight' => 'asc', + 'LinkOrder.weight' => 'asc', + ), + )); + $links = []; + foreach ($results as $link) { + $categoryId = (int)$link['Link']['category_id']; + $linkId = $link['Link']['id']; + $links[$categoryId][$linkId] = $link; + } + $this->set('links', $links); + } + +/** + * view + * + * @return void + */ + public function view() { + $linkFrameSetting = $this->LinkFrameSetting->getLinkFrameSetting(true); + $this->set('linkFrameSetting', $linkFrameSetting['LinkFrameSetting']); + + $link = $this->Link->getWorkflowContents('first', array( + 'recursive' => 0, + 'conditions' => array( + $this->Link->alias . '.block_id' => Current::read('Block.id'), + $this->Link->alias . '.key' => $this->params['key'] + ) + )); + if (! $link) { + return $this->throwBadRequest(); + } + $this->set('link', $link); + + $categoryId = isset($link['Link']['category_id']) + ? $link['Link']['category_id'] + : null; + $category = Hash::extract( + $this->viewVars['categories'], + '{n}.Category[id=' . $categoryId . ']' + ); + $category = isset($category[0]) + ? $category[0] + : []; + $this->set('category', $category); + + //if (! $this->Link->updateCount($link['Link']['id'])) { + // return $this->throwBadRequest(); + //} + + //新着データを既読にする + $this->Link->saveTopicUserStatus($link); + } + +/** + * Get url + * + * @return void + * @throws SocketException + */ + public function get() { + $url = isset($this->request->query['url']) + ? $this->request->query['url'] + : null; + if (! $url || $url === 'http://') { + return $this->throwBadRequest( + sprintf(__d('net_commons', 'Please input %s.'), __d('links', 'URL')) + ); + } + try { + $socket = new HttpSocket(array('request' => array('redirect' => 10))); + $response = $socket->get($url); + if (! $response->isOk()) { + throw new SocketException(__d('links', 'Failed to obtain the title for this page.')); + } + } catch (SocketException $ex) { + CakeLog::error($ex); + return $this->throwBadRequest(__d('links', 'Failed to obtain the title for this page.')); + } + + $results = array( + 'title' => null, + 'description' => null, + ); + + $body = $response->body; + $pattern = '/(.*)<\/title>/i'; + $matches = array(); + if (preg_match($pattern, $body, $matches)) { + $results['title'] = mb_convert_encoding($matches[1], 'utf-8', 'auto'); + } + $pattern = '<meta[^"\'<>\]]*' . + 'name=([\'"]?)' . + 'description\\1[^"\'<>\]]*' . + 'content=([\'"]?)([^"\'<>\]]*)\\2[^"\'<>\]]*>'; + $matches = array(); + if (preg_match('/' . $pattern . '/i', $body, $matches)) { + $results['description'] = mb_convert_encoding($matches[3], 'utf-8', 'auto'); + } else { + $results['description'] = ''; + } + + if ($results['title']) { + $this->NetCommons->renderJson($results); + } else { + return $this->throwBadRequest(__d('links', 'Failed to obtain the title for this page.')); + } + } + +/** + * add + * + * @return void + */ + public function add() { + $this->view = 'edit'; + + if ($this->request->is('post')) { + //登録処理 + $data = $this->data; + $data['Link']['status'] = $this->Workflow->parseStatus(); + $categoryId = isset($data['Link']['category_id']) + ? $data['Link']['category_id'] + : null; + $category = Hash::extract( + $this->viewVars['categories'], + '{n}.Category[id=' . $categoryId . ']' + ); + $data['LinkOrder']['category_key'] = isset($category[0]['key']) + ? $category[0]['key'] + : ''; + unset($data['Link']['id'], $data['LinkOrder']['weight']); + + if ($this->Link->saveLink($data)) { + return $this->redirect(NetCommonsUrl::backToPageUrl()); + } + $this->NetCommons->handleValidationError($this->Link->validationErrors); + + } else { + $this->request->data += $this->Link->create(array( + 'url' => 'http://' + )); + $this->request->data += $this->LinkOrder->create(); + $this->request->data['Frame'] = Current::read('Frame'); + $this->request->data['Block'] = Current::read('Block'); + } + } + +/** + * edit + * + * @return void + */ + public function edit() { + //データ取得 + $linkKey = $this->params['key']; + if ($this->request->is('put')) { + $linkKey = $this->data['Link']['key']; + } + $link = $this->Link->getWorkflowContents('first', array( + 'recursive' => 0, + 'conditions' => array( + $this->Link->alias . '.block_id' => Current::read('Block.id'), + $this->Link->alias . '.key' => $linkKey + ) + )); + if (empty($link)) { + return $this->throwBadRequest(); + } + + //編集権限チェック + if (! $this->Link->canEditWorkflowContent($link)) { + return $this->throwBadRequest(); + } + + if ($this->request->is('put')) { + //登録処理 + $data = $this->data; + $data['Link']['status'] = $this->Workflow->parseStatus(); + $categoryId = isset($data['Link']['category_id']) + ? $data['Link']['category_id'] + : null; + $category = Hash::extract( + $this->viewVars['categories'], + '{n}.Category[id=' . $categoryId . ']' + ); + $data['LinkOrder']['category_key'] = isset($category[0]['key']) + ? $category[0]['key'] + : ''; + unset($data['Link']['id']); + + if ($this->Link->saveLink($data)) { + return $this->redirect(NetCommonsUrl::backToPageUrl()); + } + $this->NetCommons->handleValidationError($this->Link->validationErrors); + + } else { + $this->request->data = $link; + $this->request->data['Frame'] = Current::read('Frame'); + $this->request->data['Block'] = Current::read('Block'); + } + + //コメント取得 + $comments = $this->Link->getCommentsByContentKey($linkKey); + $this->set('comments', $comments); + } + +/** + * delete + * + * @return void + */ + public function delete() { + if (! $this->request->is('delete')) { + return $this->throwBadRequest(); + } + + //データ取得 + $link = $this->Link->getWorkflowContents('first', array( + 'recursive' => -1, + 'conditions' => array( + $this->Link->alias . '.block_id' => Current::read('Block.id'), + $this->Link->alias . '.key' => $this->data['Link']['key'] + ) + )); + + //削除権限チェック + if (! $this->Link->canDeleteWorkflowContent($link)) { + return $this->throwBadRequest(); + } + + if (! $this->Link->deleteLink($this->data)) { + return $this->throwBadRequest(); + } + + $this->redirect(NetCommonsUrl::backToPageUrl()); + } + +/** + * link + * + * @return void + */ + public function link() { + if (! $this->request->is('put')) { + return $this->throwBadRequest(); + } + + $link = $this->Link->getWorkflowContents('first', array( + 'recursive' => -1, + 'conditions' => array( + $this->Link->alias . '.block_id' => Current::read('Block.id'), + $this->Link->alias . '.id' => Hash::get($this->data, 'Link.id') + ) + )); + if (! $link) { + return $this->throwBadRequest(); + } + + if (! $this->Link->updateCount($this->data['Link']['id'])) { + return $this->throwBadRequest(); + } + + $this->NetCommons->renderJson(); + } +} diff --git a/Lib/empty b/Lib/empty deleted file mode 100644 index e69de29..0000000 diff --git a/Locale/eng/LC_MESSAGES/links.po b/Locale/eng/LC_MESSAGES/links.po new file mode 100644 index 0000000..bc71d7e --- /dev/null +++ b/Locale/eng/LC_MESSAGES/links.po @@ -0,0 +1,133 @@ +# LANGUAGE translation of CakePHP Application +# Copyright YEAR NAME <EMAIL@ADDRESS> +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n" +"Last-Translator: NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" + +#: Links/Controller/LinkOrdersController.php:66 +msgid "No Category" +msgstr "" + +#: Links/Controller/LinksController.php:154 +#: Links/Model/Link.php:149;157;158 +#: Links/Test/Case/Controller/LinksController/AddTest.php:229 +#: Links/Test/Case/Controller/LinksController/EditTest.php:339 +#: Links/Test/Case/Controller/LinksController/GetTest.php:120 +#: Links/Test/Case/Model/Link/ValidateTest.php:85;87 +#: Links/View/Elements/Links/edit_form.ctp:29 +msgid "URL" +msgstr "" + +#: Links/Controller/LinksController.php:161;165;191 +#: Links/Test/Case/Controller/LinksController/GetTest.php:141 +msgid "Failed to obtain the title for this page." +msgstr "" + +#: Links/Model/Link.php:167 +#: Links/Test/Case/Controller/LinksController/AddTest.php:236 +#: Links/Test/Case/Controller/LinksController/EditTest.php:346 +#: Links/Test/Case/Model/Link/ValidateTest.php:89 +#: Links/View/Elements/Links/edit_form.ctp:50 +msgid "Title" +msgstr "" + +#: Links/Model/LinkBlock.php:184 +#: Links/Test/Case/Controller/LinkBlocksController/EditTest.php:128;157 +#: Links/Test/Case/Model/LinkBlock/ValidateTest.php:79 +#: Links/View/Elements/LinkBlocks/edit_form.ctp:22 +#: Links/View/LinkBlocks/index.ctp:30 +msgid "Link list Title" +msgstr "" + +#: Links/Model/LinkBlock.php:233 +#: Links/Test/Case/Model/LinkBlock/CreateLinkBlockTest.php:74 +msgid "New Bookmark List %s" +msgstr "" + +#: Links/Model/LinkFrameSetting.php:94 +msgid "(no line)" +msgstr "" + +#: Links/View/Elements/LinkBlockRolePermissions/edit_form.ctp:19 +msgid "Link creatable roles" +msgstr "" + +#: Links/View/Elements/LinkBlocks/delete_form.ctp:14;22 +msgid "Link List" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:27 +msgid "Display method" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:31 +msgid "Show by dropdown" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:32 +msgid "Show list" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:41 +msgid "Show description" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:51 +msgid "Line" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:94 +msgid "Marker" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:111;131 +msgid "Sample" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:142 +msgid "Open as a new tab" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:147 +msgid "Count view" +msgstr "" + +#: Links/View/Elements/Links/delete_form.ctp:22 +msgid "Link" +msgstr "" + +#: Links/View/Elements/Links/edit_form.ctp:43 +msgid "GO!" +msgstr "" + +#: Links/View/Elements/Links/edit_form.ctp:58 +msgid "Description" +msgstr "" + +#: Links/View/Elements/Links/index_dropdown.ctp:17 +msgid "Select link to show" +msgstr "" + +#: Links/View/Elements/Links/index_dropdown.ctp:52 +#: Links/View/LinkOrders/edit.ctp:38 +#: Links/View/Links/index.ctp:65;72 +msgid "No link found." +msgstr "" + +#: Links/View/LinkMailSettings/edit.ctp:24 +msgid "MailSetting.mail_fixed_phrase_body.popover" +msgstr "" + +#: Links/View/Links/index.ctp:54 +msgid "Create link" +msgstr "" + diff --git a/Locale/jpn/LC_MESSAGES/links.po b/Locale/jpn/LC_MESSAGES/links.po new file mode 100644 index 0000000..f834613 --- /dev/null +++ b/Locale/jpn/LC_MESSAGES/links.po @@ -0,0 +1,135 @@ +# LANGUAGE translation of CakePHP Application +# Copyright YEAR NAME <EMAIL@ADDRESS> +# +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"PO-Revision-Date: 2015-06-01 18:05+0900\n" +"Last-Translator: NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" +"POT-Creation-Date: \n" +"Language: ja\n" +"X-Generator: Poedit 1.8.1\n" + +#: Links/Controller/LinkOrdersController.php:66 +msgid "No Category" +msgstr "カテゴリーなし" + +#: Links/Controller/LinksController.php:154 +#: Links/Model/Link.php:149;157;158 +#: Links/Test/Case/Controller/LinksController/AddTest.php:229 +#: Links/Test/Case/Controller/LinksController/EditTest.php:339 +#: Links/Test/Case/Controller/LinksController/GetTest.php:120 +#: Links/Test/Case/Model/Link/ValidateTest.php:85;87 +#: Links/View/Elements/Links/edit_form.ctp:29 +msgid "URL" +msgstr "" + +#: Links/Controller/LinksController.php:161;165;191 +#: Links/Test/Case/Controller/LinksController/GetTest.php:141 +msgid "Failed to obtain the title for this page." +msgstr "入力したURLからタイトルと説明を取得できませんでした" + +#: Links/Model/Link.php:167 +#: Links/Test/Case/Controller/LinksController/AddTest.php:236 +#: Links/Test/Case/Controller/LinksController/EditTest.php:346 +#: Links/Test/Case/Model/Link/ValidateTest.php:89 +#: Links/View/Elements/Links/edit_form.ctp:50 +msgid "Title" +msgstr "タイトル" + +#: Links/Model/LinkBlock.php:184 +#: Links/Test/Case/Controller/LinkBlocksController/EditTest.php:128;157 +#: Links/Test/Case/Model/LinkBlock/ValidateTest.php:79 +#: Links/View/Elements/LinkBlocks/edit_form.ctp:22 +#: Links/View/LinkBlocks/index.ctp:30 +msgid "Link list Title" +msgstr "リンクリスト名" + +#: Links/Model/LinkBlock.php:233 +#: Links/Test/Case/Model/LinkBlock/CreateLinkBlockTest.php:74 +msgid "New Bookmark List %s" +msgstr "新規リンクリスト%s" + +#: Links/Model/LinkFrameSetting.php:94 +msgid "(no line)" +msgstr "(線なし)" + +#: Links/View/Elements/LinkBlockRolePermissions/edit_form.ctp:19 +msgid "Link creatable roles" +msgstr "リンクを追加できる権限" + +#: Links/View/Elements/LinkBlocks/delete_form.ctp:14;22 +msgid "Link List" +msgstr "リンクリスト" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:27 +msgid "Display method" +msgstr "表示方法選択" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:31 +msgid "Show by dropdown" +msgstr "ドロップダウン" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:32 +msgid "Show list" +msgstr "一覧表示" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:41 +msgid "Show description" +msgstr "説明付き" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:51 +msgid "Line" +msgstr "カテゴリ間の区切り線" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:94 +msgid "Marker" +msgstr "リストマーカー" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:111;131 +msgid "Sample" +msgstr "サンプル" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:142 +msgid "Open as a new tab" +msgstr "新しいタブで開く" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:147 +msgid "Count view" +msgstr "クリック回数の表示" + +#: Links/View/Elements/Links/delete_form.ctp:22 +msgid "Link" +msgstr "リンク" + +#: Links/View/Elements/Links/edit_form.ctp:43 +msgid "GO!" +msgstr "取得" + +#: Links/View/Elements/Links/edit_form.ctp:58 +msgid "Description" +msgstr "説明" + +#: Links/View/Elements/Links/index_dropdown.ctp:17 +msgid "Select link to show" +msgstr "リンクを選択してください" + +#: Links/View/Elements/Links/index_dropdown.ctp:52 +#: Links/View/LinkOrders/edit.ctp:38 +#: Links/View/Links/index.ctp:65;72 +msgid "No link found." +msgstr "リンクがありません。" + +# メール関連 +#: Links/View/LinkMailSettings/edit.ctp:24 +msgid "MailSetting.mail_fixed_phrase_body.popover" +msgstr "{X-SITE_NAME} : サイト名<br>{X-PLUGIN_NAME} : プラグイン名<br>{X-ROOM} : ルーム名<br>{X-BLOCK_NAME} : リンクリスト名<br>{X-LINK_URL} : リンク先<br>{X-TITLE} : タイトル<br>{X-CATEGORY_NAME} : カテゴリ<br>{X-DESCRIPTION} : 説明<br>{X-USER} : 登録者<br>{X-TO_DATE} : 登録日時<br>{X-URL} : 登録内容のURL" + +#: Links/View/Links/index.ctp:54 +msgid "Create link" +msgstr "リンクの作成" diff --git a/Locale/links.pot b/Locale/links.pot new file mode 100644 index 0000000..bc71d7e --- /dev/null +++ b/Locale/links.pot @@ -0,0 +1,133 @@ +# LANGUAGE translation of CakePHP Application +# Copyright YEAR NAME <EMAIL@ADDRESS> +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n" +"Last-Translator: NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" + +#: Links/Controller/LinkOrdersController.php:66 +msgid "No Category" +msgstr "" + +#: Links/Controller/LinksController.php:154 +#: Links/Model/Link.php:149;157;158 +#: Links/Test/Case/Controller/LinksController/AddTest.php:229 +#: Links/Test/Case/Controller/LinksController/EditTest.php:339 +#: Links/Test/Case/Controller/LinksController/GetTest.php:120 +#: Links/Test/Case/Model/Link/ValidateTest.php:85;87 +#: Links/View/Elements/Links/edit_form.ctp:29 +msgid "URL" +msgstr "" + +#: Links/Controller/LinksController.php:161;165;191 +#: Links/Test/Case/Controller/LinksController/GetTest.php:141 +msgid "Failed to obtain the title for this page." +msgstr "" + +#: Links/Model/Link.php:167 +#: Links/Test/Case/Controller/LinksController/AddTest.php:236 +#: Links/Test/Case/Controller/LinksController/EditTest.php:346 +#: Links/Test/Case/Model/Link/ValidateTest.php:89 +#: Links/View/Elements/Links/edit_form.ctp:50 +msgid "Title" +msgstr "" + +#: Links/Model/LinkBlock.php:184 +#: Links/Test/Case/Controller/LinkBlocksController/EditTest.php:128;157 +#: Links/Test/Case/Model/LinkBlock/ValidateTest.php:79 +#: Links/View/Elements/LinkBlocks/edit_form.ctp:22 +#: Links/View/LinkBlocks/index.ctp:30 +msgid "Link list Title" +msgstr "" + +#: Links/Model/LinkBlock.php:233 +#: Links/Test/Case/Model/LinkBlock/CreateLinkBlockTest.php:74 +msgid "New Bookmark List %s" +msgstr "" + +#: Links/Model/LinkFrameSetting.php:94 +msgid "(no line)" +msgstr "" + +#: Links/View/Elements/LinkBlockRolePermissions/edit_form.ctp:19 +msgid "Link creatable roles" +msgstr "" + +#: Links/View/Elements/LinkBlocks/delete_form.ctp:14;22 +msgid "Link List" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:27 +msgid "Display method" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:31 +msgid "Show by dropdown" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:32 +msgid "Show list" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:41 +msgid "Show description" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:51 +msgid "Line" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:94 +msgid "Marker" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:111;131 +msgid "Sample" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:142 +msgid "Open as a new tab" +msgstr "" + +#: Links/View/Elements/LinkFrameSettings/edit_form.ctp:147 +msgid "Count view" +msgstr "" + +#: Links/View/Elements/Links/delete_form.ctp:22 +msgid "Link" +msgstr "" + +#: Links/View/Elements/Links/edit_form.ctp:43 +msgid "GO!" +msgstr "" + +#: Links/View/Elements/Links/edit_form.ctp:58 +msgid "Description" +msgstr "" + +#: Links/View/Elements/Links/index_dropdown.ctp:17 +msgid "Select link to show" +msgstr "" + +#: Links/View/Elements/Links/index_dropdown.ctp:52 +#: Links/View/LinkOrders/edit.ctp:38 +#: Links/View/Links/index.ctp:65;72 +msgid "No link found." +msgstr "" + +#: Links/View/LinkMailSettings/edit.ctp:24 +msgid "MailSetting.mail_fixed_phrase_body.popover" +msgstr "" + +#: Links/View/Links/index.ctp:54 +msgid "Create link" +msgstr "" + diff --git a/Model/Behavior/empty b/Model/Behavior/empty deleted file mode 100644 index e69de29..0000000 diff --git a/Model/Datasource/empty b/Model/Datasource/empty deleted file mode 100644 index e69de29..0000000 diff --git a/Model/Link.php b/Model/Link.php new file mode 100644 index 0000000..5efd24a --- /dev/null +++ b/Model/Link.php @@ -0,0 +1,360 @@ +<?php +/** + * Link Model + * + * @property Block $Block + * @property Category $Category + * + * @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('LinksAppModel', 'Links.Model'); + +/** + * Link Model + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Model + */ +class Link extends LinksAppModel { + +/** + * use behaviors + * + * @var array + */ + public $actsAs = array( + 'NetCommons.OriginalKey', + 'Workflow.WorkflowComment', + 'Workflow.Workflow', + 'Mails.MailQueue' => array( + 'embedTags' => array( + 'X-TITLE' => 'Link.title', + 'X-LINK_URL' => 'Link.url', + 'X-DESCRIPTION' => 'Link.description', + 'X-CATEGORY_NAME' => 'CategoriesLanguage.name', + ), + ), + 'Topics.Topics' => array( + 'fields' => array( + 'title' => 'Link.title', + 'summary' => 'Link.description', + 'path' => '/:plugin_key/:plugin_key/view/:block_id/:content_key', + ), + 'search_contents' => array('url') + ), + //多言語 + 'M17n.M17n' => array( + 'commonFields' => array('category_id') + ), + ); + +/** + * 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( + 'LinkOrder' => array( + 'className' => 'Links.LinkOrder', + 'foreignKey' => false, + 'conditions' => 'LinkOrder.link_key=Link.key', + 'fields' => '', + //'order' => array('LinkOrder.weight' => 'asc') + ), + 'Category' => array( + 'className' => 'Categories.Category', + 'foreignKey' => 'category_id', + 'conditions' => '', + 'fields' => '', + 'order' => '' + ), + 'CategoryOrder' => array( + 'className' => 'Categories.CategoryOrder', + 'foreignKey' => false, + 'conditions' => 'CategoryOrder.category_key=Category.key', + 'fields' => '', + //'order' => array('CategoryOrder.weight' => 'asc') + ), + 'Block' => array( + 'className' => 'Blocks.Block', + 'foreignKey' => 'block_id', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'counterCache' => array( + 'content_count' => array( + 'Link.is_origin' => true, + 'Link.is_latest' => true + ), + ), + ), + ); + +/** + * Called before each find operation. Return false if you want to halt the find + * call, otherwise return the (modified) query data. + * + * @param array $query Data used to execute this query, i.e. conditions, order, etc. + * @return mixed true if the operation should continue, false if it should abort; or, modified + * $query to continue with new $query + * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforefind + */ + public function beforeFind($query) { + //$this->idがある場合、登録処理として判断する + $recursive = isset($query['recursive']) + ? $query['recursive'] + : null; + if ($recursive > -1 && ! $this->id) { + $belongsTo = $this->Category->bindModelCategoryLang('Link.category_id'); + $this->bindModel($belongsTo, true); + } + return parent::beforeFind($query); + } + +/** + * 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_merge($this->validate, array( + 'block_id' => array( + 'numeric' => array( + 'rule' => array('numeric'), + 'message' => __d('net_commons', 'Invalid request.'), + 'allowEmpty' => false, + 'required' => true, + 'on' => 'update', // Limit validation to 'create' or 'update' operations + ), + ), + 'key' => array( + 'notBlank' => array( + 'rule' => array('notBlank'), + 'message' => __d('net_commons', 'Invalid request.'), + 'allowEmpty' => false, + 'required' => true, + 'on' => 'update', // Limit validation to 'create' or 'update' operations + ), + ), + 'language_id' => array( + 'numeric' => array( + 'rule' => array('numeric'), + 'message' => __d('net_commons', 'Invalid request.'), + 'required' => true, + ), + ), + 'click_count' => array( + 'numeric' => array( + 'rule' => array('numeric'), + 'message' => __d('net_commons', 'Invalid request.'), + 'allowEmpty' => true, + ), + ), + + //status to set in PublishableBehavior. + + 'url' => array( + 'notBlank' => array( + 'rule' => array('notBlank'), + 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('links', 'URL')), + 'allowEmpty' => false, + 'required' => true, + ), + 'url' => array( + 'rule' => array('url'), + 'message' => sprintf( + __d('net_commons', 'Unauthorized pattern for %s. Please input the data in %s format.'), + __d('links', 'URL'), + __d('links', 'URL') + ), + 'allowEmpty' => false, + 'required' => true, + ), + ), + 'title' => array( + 'notBlank' => array( + 'rule' => array('notBlank'), + 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('links', 'Title')), + 'allowEmpty' => false, + 'required' => true, + ), + ), + )); + + if ($this->data['Link']['url'] === 'http://') { + $this->data['Link']['url'] = ''; + } + + if (isset($this->data['LinkOrder'])) { + $this->LinkOrder->set($this->data['LinkOrder']); + if (! $this->LinkOrder->validates()) { + $this->validationErrors = array_merge( + $this->validationErrors, $this->LinkOrder->validationErrors + ); + return false; + } + } + + return parent::beforeValidate($options); + } + +/** + * Called after each successful save operation. + * + * @param bool $created True if this save created a new record + * @param array $options Options passed from Model::save(). + * @return void + * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#aftersave + * @see Model::save() + * @throws InternalErrorException + */ + public function afterSave($created, $options = array()) { + //LinkOrder登録 + if (isset($this->LinkOrder->data['LinkOrder'])) { + $this->data['LinkOrder']['link_key'] = $this->data[$this->alias]['key']; + $result = $this->LinkOrder->save($this->data['LinkOrder'], false); + if (! $result) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + $this->data['LinkOrder'] = $result['LinkOrder']; + } + } + +/** + * Save Link + * + * @param array $data received post data + * @return bool True on success, false on validation errors + * @throws InternalErrorException + */ + public function saveLink($data) { + $this->loadModels([ + 'Category' => 'Categories.Category', + 'LinkOrder' => 'Links.LinkOrder', + ]); + + //カテゴリ名をメールに含める + if (! empty($data['Link']['category_id'])) { + $data += $this->Category->getCategory($data['Link']['category_id']); + } + + //トランザクションBegin + $this->begin(); + + //バリデーション + $this->set($data); + if (! $this->validates()) { + return false; + } + + try { + //Link登録 + $link = $this->save(null, false); + if (! $link) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + + //トランザクションCommit + $this->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->rollback($ex); + } + + return $link; + } + +/** + * Delete Link + * + * @param array $data received post data + * @return mixed On success Model::$data if its not empty or true, false on failure + * @throws InternalErrorException + */ + public function deleteLink($data) { + $this->loadModels([ + 'LinkOrder' => 'Links.LinkOrder', + ]); + + //トランザクションBegin + $this->begin(); + + try { + $this->contentKey = $data['Link']['key']; + if (! $this->deleteAll(array($this->alias . '.key' => $data['Link']['key']), false, true)) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + + if (! $this->LinkOrder->delete($data['LinkOrder']['id'])) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + + //トランザクションCommit + $this->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->rollback($ex); + } + + return true; + } + +/** + * クリック数の更新 + * + * @param int $id links.id + * @return bool True on success, false on validation errors + * @throws InternalErrorException + */ + public function updateCount($id) { + //トランザクションBegin + $this->begin(); + + try { + $result = $this->updateAll( + array( + $this->alias . '.click_count' => $this->alias . '.click_count + 1' + ), + array( + $this->alias . '.id' => $id, + $this->alias . '.block_id' => Current::read('Block.id'), + ) + ); + if (! $result) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + + //トランザクションCommit + $this->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->rollback($ex); + } + + $this->setSlaveDataSource(); + + return true; + } + +} diff --git a/Model/LinkBlock.php b/Model/LinkBlock.php new file mode 100644 index 0000000..28dbb07 --- /dev/null +++ b/Model/LinkBlock.php @@ -0,0 +1,343 @@ +<?php +/** + * LinkBlock Model + * + * @property Language $Language + * @property Room $Room + * @property Frame $Frame + * + * @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('BlockBaseModel', 'Blocks.Model'); + +/** + * LinkBlock Model + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Model + */ +class LinkBlock extends BlockBaseModel { + +/** + * Custom database table name + * + * @var string + */ + public $useTable = 'blocks'; + +/** + * 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( + 'Block' => array( + 'className' => 'Blocks.Block', + 'foreignKey' => 'id', + 'type' => 'INNER', + 'conditions' => '', + 'fields' => '', + 'order' => '' + ) + ); + +/** + * use behaviors + * + * @var array + */ + public $actsAs = array( + 'Blocks.Block' => array( + 'name' => 'LinkBlock.name', + 'loadModels' => array( + 'BlockSetting' => 'Blocks.BlockSetting', + 'Category' => 'Categories.Category', + 'CategoryOrder' => 'Categories.CategoryOrder', + ) + ), + 'Categories.Category', + 'NetCommons.OriginalKey', + //多言語 + 'M17n.M17n', + ); + +/** + * Array of virtual fields this model has. Virtual fields are aliased + * SQL expressions. Fields added to this property will be read as other fields in a model + * but will not be saveable. + * + * `public $virtualFields = array('two' => '1 + 1');` + * + * Is a simplistic example of how to set virtualFields + * + * @var array + * @link http://book.cakephp.org/2.0/ja/models/model-attributes.html#virtualfields + */ + public $virtualFields = array( + 'language_id' => 'LinkBlocksLanguage.language_id', + 'name' => 'LinkBlocksLanguage.name', + 'block_id' => 'LinkBlock.id', + 'is_origin' => 'LinkBlocksLanguage.is_origin', + 'is_translation' => 'LinkBlocksLanguage.is_translation', + ); + +/** + * Constructor + * + * @param bool|int|string|array $id Set this ID for this model on startup, + * can also be an array of options, see above. + * @param string $table Name of database table to use. + * @param string $ds DataSource connection name. + * @return void + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) + */ + public function __construct($id = false, $table = null, $ds = null) { + parent::__construct($id, $table, $ds); + + $this->loadModels([ + 'Link' => 'Links.Link', + 'LinkSetting' => 'Links.LinkSetting', + 'LinkOrder' => 'Links.LinkOrder', + ]); + } + +/** + * Called before each find operation. Return false if you want to halt the find + * call, otherwise return the (modified) query data. + * + * @param array $query Data used to execute this query, i.e. conditions, order, etc. + * @return mixed true if the operation should continue, false if it should abort; or, modified + * $query to continue with new $query + * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforefind + */ + public function beforeFind($query) { + if (! isset($this->belongsTo['BlocksLanguage'])) { + $belongsTo = $this->Block->bindModelBlockLang('LinkBlock.id'); + $this->bindModel($belongsTo, true); + } + + $this->bindModel(array( + 'belongsTo' => array( + 'LinkBlocksLanguage' => array( + 'className' => 'Blocks.BlocksLanguage', + 'foreignKey' => false, + 'type' => 'INNER', + 'conditions' => array( + 'LinkBlocksLanguage.id = BlocksLanguage.id', + //'LinkBlocksLanguage.language_id' => Current::read('Language.id', '0') + ), + 'fields' => array('LinkBlocksLanguage.language_id', 'LinkBlocksLanguage.name'), + 'order' => '' + ), + ) + ), true); + return true; + } + +/** + * 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_merge($this->validate, array( + 'language_id' => array( + 'numeric' => array( + 'rule' => array('numeric'), + 'message' => __d('net_commons', 'Invalid request.'), + 'required' => false, + ), + ), + 'room_id' => array( + 'numeric' => array( + 'rule' => array('numeric'), + 'message' => __d('net_commons', 'Invalid request.'), + 'required' => false, + ), + ), + 'name' => array( + 'notBlank' => array( + 'rule' => array('notBlank'), + 'message' => sprintf( + __d('net_commons', 'Please input %s.'), __d('links', 'Link list Title') + ), + 'required' => true, + ) + ) + )); + + if (isset($this->data['LinkSetting'])) { + $this->LinkSetting->set($this->data['LinkSetting']); + if (! $this->LinkSetting->validates()) { + $this->validationErrors = array_merge( + $this->validationErrors, $this->LinkSetting->validationErrors + ); + return false; + } + } + + return parent::beforeValidate($options); + } + +/** + * Called after each successful save operation. + * + * @param bool $created True if this save created a new record + * @param array $options Options passed from Model::save(). + * @return void + * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#aftersave + * @see Model::save() + * @throws InternalErrorException + */ + public function afterSave($created, $options = array()) { + //LinkSetting登録 + if (isset($this->data['LinkSetting'])) { + $this->LinkSetting->set($this->data['LinkSetting']); + $this->LinkSetting->save(null, false); + } + parent::afterSave($created, $options); + } + +/** + * LinkBlockデータ生成 + * + * @return array LinkBlockデータ配列 + */ + public function createLinkBlock() { + $linkBlock = $this->createAll(array( + 'LinkBlock' => array( + 'language_id' => Current::read('Language.id'), + 'room_id' => Current::read('Room.id'), + 'name' => __d('links', 'New Bookmark List %s', date('YmdHis')), + ), + 'BlocksLanguage' => array( + 'language_id' => Current::read('Language.id'), + ), + )); + return ($linkBlock + $this->LinkSetting->createBlockSetting()); + } + +/** + * LinkBlockデータ取得 + * + * @param array $fields 取得するカラムリスト + * @return array LinkBlockデータ配列 + */ + public function getLinkBlock($fields = null) { + $linkBlock = $this->find('first', array( + 'fields' => $fields, + 'recursive' => 0, + 'conditions' => $this->getBlockConditionById(), + )); + + if (! $linkBlock) { + return false; + } + return ($linkBlock + $this->LinkSetting->getLinkSetting()); + } + +/** + * LinkBlock登録処理 + * + * @param array $data received post data + * @return bool True on success, false on validation errors + * @throws InternalErrorException + */ + public function saveLinkBlock($data) { + //トランザクションBegin + $this->begin(); + + //バリデーション + $this->set($data); + if (! $this->validates()) { + return false; + } + + try { + //登録処理 + if (isset($data[$this->alias]['id'])) { + if (! $this->save(null, false)) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + } else { + //BlockBehaviorで登録するため、useTableをfalseにする + $this->useTable = false; + $this->save(null, false); + } + + //トランザクションCommit + $this->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->rollback($ex); + } + + return true; + } + +/** + * LinkBlockの削除処理 + * + * @param array $data received post data + * @return mixed On success Model::$data if its not empty or true, false on failure + * @throws InternalErrorException + */ + public function deleteLinkBlock($data) { + //トランザクションBegin + $this->begin(); + + $conditions = array( + $this->alias . '.key' => $data[$this->alias]['key'] + ); + $blocks = $this->find('list', array( + 'recursive' => -1, + 'conditions' => $conditions, + )); + $blocks = array_keys($blocks); + + try { + $this->Link->blockKey = $data[$this->alias]['key']; + $conditions = array($this->Link->alias . '.block_id' => $blocks); + if (! $this->Link->deleteAll($conditions, false, true)) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + + $conditions = array($this->LinkOrder->alias . '.block_key' => $data[$this->alias]['key']); + if (! $this->LinkOrder->deleteAll($conditions, false)) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + + //Blockデータ削除 + $this->deleteBlock($data[$this->alias]['key']); + + //トランザクションCommit + $this->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->rollback($ex); + } + + return true; + } + +} diff --git a/Model/LinkFrameSetting.php b/Model/LinkFrameSetting.php new file mode 100644 index 0000000..3ceb853 --- /dev/null +++ b/Model/LinkFrameSetting.php @@ -0,0 +1,313 @@ +<?php +/** + * LinkFrameSetting Model + * + * @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('LinksAppModel', 'Links.Model'); +App::uses('Folder', 'Utility'); + +/** + * LinkFrameSetting Model + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Model + */ +class LinkFrameSetting extends LinksAppModel { + +/** + * Type + * + * @var string + */ + const + TYPE_DROPDOWN = '1', + TYPE_LIST_ONLY_TITLE = '2', + TYPE_LIST_WITH_DESCRIPTION = '3'; + +/** + * categorySeparatorLine + * + * @var array + */ + public $categorySeparators = array(); + +/** + * categorySeparatorLine default + * + * @var string + */ + const CATEGORY_SEPARATOR_DEFAULT = 'default'; + +/** + * categorySeparatorLine default + * + * @var string + */ + const LINE_STYLE_NONE = 'none', + LINE_STYLE_DISC = 'disc', + LINE_STYLE_CIRCLE = 'circle', + LINE_STYLE_LOWER_ALPHA = 'lower-alpha', + LINE_STYLE_UPPER_ALPHA = 'upper-alpha'; + +/** + * listStyle + * + * @var array + */ + public $listStyles = array(); + +/** + * Validation rules + * + * @var array + */ + public $validate = array(); + +/** + * Constructor. Binds the model's database table to the object. + * + * @param bool|int|string|array $id Set this ID for this model on startup, + * can also be an array of options, see above. + * @param string $table Name of database table to use. + * @param string $ds DataSource connection name. + * @see Model::__construct() + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) + */ + public function __construct($id = false, $table = null, $ds = null) { + parent::__construct($id, $table, $ds); + $pluginDir = APP . 'Plugin' . DS . $this->plugin . DS . WEBROOT_DIR . DS . 'img' . DS; + + //カテゴリ間の区切り線 + $dir = new Folder($pluginDir . 'line'); + $files = $dir->find('.*\..*'); + $files = Hash::sort($files, '{n}', 'asc'); + + $this->categorySeparators = array( + null => array( + 'key' => null, + 'name' => __d('links', '(no line)'), + 'style' => null + ), + self::CATEGORY_SEPARATOR_DEFAULT => array( + 'key' => self::CATEGORY_SEPARATOR_DEFAULT, + 'name' => '', + 'style' => '' + ) + ); + foreach ($files as $file) { + $info = getimagesize($dir->pwd() . DS . $file); + $img = Router::url('/') . Inflector::underscore($this->plugin) . '/img/line/' . $file; + $this->categorySeparators[$file] = array( + 'key' => $file, + 'name' => '', + 'style' => 'background-image: url(' . $img . '); ' . + 'border-image: url(' . $img . '); ' . 'height: ' . $info[1] . 'px;', + ); + } + unset($dir); + + //線スタイル + $dir = new Folder($pluginDir . 'mark'); + $files = $dir->find('.*\..*'); + $files = Hash::sort($files, '{n}', 'asc'); + $this->listStyles = array( + null => array( + 'key' => null, + 'name' => '', + 'style' => 'list-style-type: ' . self::LINE_STYLE_NONE . ';' + ), + self::LINE_STYLE_DISC => array( + 'key' => self::LINE_STYLE_DISC, + 'name' => '', + 'style' => 'list-style-type: ' . self::LINE_STYLE_DISC . ';' + ), + self::LINE_STYLE_CIRCLE => array( + 'key' => self::LINE_STYLE_CIRCLE, + 'name' => '', + 'style' => 'list-style-type: ' . self::LINE_STYLE_CIRCLE . ';' + ), + self::LINE_STYLE_LOWER_ALPHA => array( + 'key' => self::LINE_STYLE_LOWER_ALPHA, + 'name' => '', + 'style' => 'list-style-type: ' . self::LINE_STYLE_LOWER_ALPHA . ';' + ), + self::LINE_STYLE_UPPER_ALPHA => array( + 'key' => self::LINE_STYLE_UPPER_ALPHA, + 'name' => '', + 'style' => 'list-style-type: ' . self::LINE_STYLE_UPPER_ALPHA . ';' + ), + ); + + foreach ($files as $file) { + $info = getimagesize($dir->pwd() . DS . $file); + $img = Router::url('/') . Inflector::underscore($this->plugin) . '/img/mark/' . $file; + $this->listStyles[$file] = array( + 'key' => $file, + 'name' => '', + 'style' => 'list-style-type: none; ' . 'list-style-image: url(' . $img . '); ' + ); + } + unset($dir); + } + +/** + * 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_merge($this->validate, array( + 'frame_key' => array( + 'notBlank' => array( + 'rule' => array('notBlank'), + 'message' => __d('net_commons', 'Invalid request.'), + 'allowEmpty' => false, + 'required' => true, + 'on' => 'update', // Limit validation to 'create' or 'update' operations + ), + ), + 'display_type' => array( + 'numeric' => array( + 'rule' => array('numeric'), + 'message' => __d('net_commons', 'Invalid request.'), + 'allowEmpty' => false, + 'required' => true, + ), + 'inList' => array( + 'rule' => array('inList', array( + self::TYPE_DROPDOWN, + self::TYPE_LIST_ONLY_TITLE, + self::TYPE_LIST_WITH_DESCRIPTION + )), + 'message' => __d('net_commons', 'Invalid request.'), + ) + ), + 'open_new_tab' => array( + 'boolean' => array( + 'rule' => array('boolean'), + 'message' => __d('net_commons', 'Invalid request.'), + ), + ), + 'display_click_count' => array( + 'boolean' => array( + 'rule' => array('boolean'), + 'message' => __d('net_commons', 'Invalid request.'), + ), + ), + 'category_separator_line' => array( + 'inList' => array( + 'rule' => array('inList', + array_keys($this->categorySeparators) + ), + 'message' => __d('net_commons', 'Invalid request.'), + 'allowEmpty' => true, + ) + ), + 'list_style' => array( + 'inList' => array( + 'rule' => array('inList', + array_keys($this->listStyles) + ), + 'message' => __d('net_commons', 'Invalid request.'), + 'allowEmpty' => true, + ) + ), + )); + + return parent::beforeValidate($options); + } + +/** + * LinkFrameSettingデータ取得 + * + * @param bool $created 作成フラグ + * @return array LinkFrameSettingデータ配列 + */ + public function getLinkFrameSetting($created) { + $conditions = array( + 'frame_key' => Current::read('Frame.key') + ); + + $linkFrameSetting = $this->find('first', array( + 'recursive' => -1, + 'conditions' => $conditions, + )); + + if (! $linkFrameSetting) { + if ($created) { + $linkFrameSetting = $this->create(array( + 'category_separator_line' => self::CATEGORY_SEPARATOR_DEFAULT + )); + } else { + return $linkFrameSetting; + } + } + + //カテゴリ間の区切り線 + $separatorLine = $linkFrameSetting['LinkFrameSetting']['category_separator_line']; + if (isset($this->categorySeparators[$separatorLine])) { + $style = $this->categorySeparators[$separatorLine]['style']; + } else { + $style = null; + } + $linkFrameSetting['LinkFrameSetting']['category_separator_line_css'] = $style; + + //リストマーク + $listStyle = $linkFrameSetting['LinkFrameSetting']['list_style']; + if (isset($this->listStyles[$listStyle])) { + $style = $this->listStyles[$listStyle]['style']; + } else { + $style = null; + } + $linkFrameSetting['LinkFrameSetting']['list_style_css'] = $style; + + return $linkFrameSetting; + } + +/** + * LinkFrameSettingデータ登録処理 + * + * @param array $data received post data + * @return bool True on success, false on failure + * @throws InternalErrorException + */ + public function saveLinkFrameSetting($data) { + $this->loadModels([ + 'LinkFrameSetting' => 'Links.LinkFrameSetting', + ]); + + //トランザクションBegin + $this->begin(); + + //バリデーション + $this->set($data); + if (! $this->validates()) { + return false; + } + + try { + if (! $this->save(null, false)) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + + //トランザクションCommit + $this->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->rollback($ex); + } + + return true; + } +} diff --git a/Model/LinkListsAppModel.php b/Model/LinkListsAppModel.php deleted file mode 100644 index d3679d3..0000000 --- a/Model/LinkListsAppModel.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -App::uses('AppModel', 'Model'); - -class LinkListsAppModel extends AppModel { - -} diff --git a/Model/LinkOrder.php b/Model/LinkOrder.php new file mode 100644 index 0000000..3c18220 --- /dev/null +++ b/Model/LinkOrder.php @@ -0,0 +1,197 @@ +<?php +/** + * LinkOrder Model + * + * @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('LinksAppModel', 'Links.Model'); + +/** + * LinkOrder Model + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Model + */ +class LinkOrder extends LinksAppModel { + +/** + * Validation rules + * + * @var array + */ + public $validate = array(); + +/** + * 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_merge($this->validate, array( + 'block_key' => array( + 'notBlank' => array( + 'rule' => array('notBlank'), + 'message' => __d('net_commons', 'Invalid request.'), + 'allowEmpty' => false, + 'required' => true, + 'on' => 'update', // Limit validation to 'create' or 'update' operations + ), + ), + 'link_key' => array( + 'notBlank' => array( + 'rule' => array('notBlank'), + 'message' => __d('net_commons', 'Invalid request.'), + 'allowEmpty' => false, + 'required' => true, + 'on' => 'update', // Limit validation to 'create' or 'update' operations + ), + ), + 'weight' => array( + 'numeric' => array( + 'rule' => array('numeric'), + 'message' => __d('net_commons', 'Invalid request.'), + 'allowEmpty' => false, + ), + ), + )); + + return parent::beforeValidate($options); + } + +/** + * Called before each save operation, after validation. Return a non-true result + * to halt the save. + * + * @param array $options Options passed from Model::save(). + * @return bool True if the operation should continue, false if it should abort + * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforesave + * @see Model::save() + */ + public function beforeSave($options = array()) { + if (isset($this->data[$this->alias]['link_key']) && + ! isset($this->data[$this->alias]['weight']) && + array_key_exists('category_key', $this->data[$this->alias])) { + + $before = $this->find('first', array( + 'recursive' => -1, + 'fields' => array('category_key', 'weight'), + 'conditions' => array('link_key' => $this->data[$this->alias]['link_key']), + )); + + if ($before) { + if ($before[$this->alias]['category_key'] !== $this->data[$this->alias]['category_key']) { + $this->updateAll( + array($this->alias . '.weight' => $this->alias . '.weight - 1'), + array( + $this->alias . '.weight > ' => $before[$this->alias]['weight'], + $this->alias . '.block_key' => Current::read('Block.key'), + $this->alias . '.category_key' => $before[$this->alias]['category_key'], + ) + ); + $this->data[$this->alias]['weight'] = $this->getMaxWeight( + $this->data[$this->alias]['category_key']) + 1; + } + } elseif (! $this->id) { + $this->data[$this->alias]['weight'] = $this->getMaxWeight( + $this->data[$this->alias]['category_key']) + 1; + } + } + + return true; + } + +/** + * Called before every deletion operation. + * + * @param bool $cascade If true records that depend on this record will also be deleted + * @return bool True if the operation should continue, false if it should abort + * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforedelete + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) + */ + public function beforeDelete($cascade = true) { + if ($this->id) { + $before = $this->find('first', array( + 'recursive' => -1, + 'fields' => array('block_key', 'category_key', 'weight'), + 'conditions' => array('id' => $this->id), + )); + + $this->updateAll( + array($this->alias . '.weight' => $this->alias . '.weight - 1'), + array( + $this->alias . '.weight > ' => $before[$this->alias]['weight'], + $this->alias . '.block_key' => $before[$this->alias]['block_key'], + $this->alias . '.category_key' => $before[$this->alias]['category_key'], + ) + ); + } + return true; + } + +/** + * Category毎の表示順序 + * + * @param string $categoryKey Category.key + * @return int $weight LinkOrders.weight + */ + public function getMaxWeight($categoryKey) { + $order = $this->find('first', array( + 'recursive' => -1, + 'fields' => array('weight'), + 'conditions' => array( + 'block_key' => Current::read('Block.key'), + 'category_key' => $categoryKey + ), + 'order' => array('weight' => 'DESC') + )); + + if (isset($order[$this->alias]['weight'])) { + $weight = (int)$order[$this->alias]['weight']; + } else { + $weight = 0; + } + return $weight; + } + +/** + * Save LinkOrder + * + * @param array $data received post data + * @return bool True on success, false on validation errors + * @throws InternalErrorException + */ + public function saveLinkOrders($data) { + //トランザクションBegin + $this->begin(); + + //バリデーション + if (! $this->validateMany($data['LinkOrders'])) { + return false; + } + + try { + //登録処理 + if (! $this->saveMany($data['LinkOrders'], ['validate' => false])) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + + //トランザクションCommit + $this->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->rollback($ex); + } + + return true; + } +} diff --git a/Model/LinkSetting.php b/Model/LinkSetting.php new file mode 100644 index 0000000..448b34e --- /dev/null +++ b/Model/LinkSetting.php @@ -0,0 +1,93 @@ +<?php +/** + * LinkSetting Model + * + * @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('BlockSettingBehavior', 'Blocks.Model/Behavior'); +App::uses('BlockBaseModel', 'Blocks.Model'); + +/** + * LinkSetting Model + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Model + */ +class LinkSetting extends BlockBaseModel { + +/** + * Custom database table name + * + * @var string + */ + public $useTable = false; + +/** + * Validation rules + * + * @var array + */ + public $validate = array(); + +/** + * use behaviors + * + * @var array + */ + public $actsAs = array( + 'Blocks.BlockRolePermission', + 'Blocks.BlockSetting' => array( + BlockSettingBehavior::FIELD_USE_WORKFLOW, + ), + ); + +/** + * LinkSettingデータ取得 + * + * @return array + * @see BlockSettingBehavior::getBlockSetting() 取得 + */ + public function getLinkSetting() { + return $this->getBlockSetting(); + } + +/** + * Save link settings + * + * @param array $data received post data + * @return bool True on success, false on failure + * @throws InternalErrorException + */ + public function saveLinkSetting($data) { + //トランザクションBegin + $this->begin(); + + //バリデーション + $this->set($data); + if (! $this->validates()) { + return false; + } + + try { + // useTable = falseでsaveすると必ずfalseになるので、throwさせない + // BlockBaseModel継承によりuseTable = falseでも beforeSave(), afterSave()が実行されるため、 + // behaviorsのbeforeSave(), afterSave()も実行される + $this->save(null, false); + + //トランザクションCommit + $this->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $this->rollback($ex); + } + + return true; + } + +} diff --git a/Model/Linklist.php b/Model/Linklist.php deleted file mode 100644 index 37e50b9..0000000 --- a/Model/Linklist.php +++ /dev/null @@ -1,139 +0,0 @@ -<?php -/** - * Linklist Model - * - * @property LinklistsBlock $LinklistsBlock - * @property Language $Language - * @property LinklistsCategory $LinklistsCategory - * @property Block $Block - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -App::uses('LinkListsAppModel', 'LinkLists.Model'); - -/** - * Summary for Linklist Model - */ -class Linklist extends LinkListsAppModel { - -/** - * Use database config - * - * @var string - */ - public $useDbConfig = 'master'; - -/** - * Validation rules - * - * @var array - */ - public $validate = array( - 'linklists_block_id' => array( - 'numeric' => array( - 'rule' => array('numeric'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - 'status' => array( - 'numeric' => array( - 'rule' => array('numeric'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - 'language_id' => array( - 'numeric' => array( - 'rule' => array('numeric'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - 'is_auto_translated' => array( - 'boolean' => array( - 'rule' => array('boolean'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - 'url' => array( - 'notEmpty' => array( - 'rule' => array('notEmpty'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - ); - - //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( - 'LinklistsBlock' => array( - 'className' => 'LinklistsBlock', - 'foreignKey' => 'linklists_block_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ), - 'Language' => array( - 'className' => 'Language', - 'foreignKey' => 'language_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ), - 'LinklistsCategory' => array( - 'className' => 'LinklistsCategory', - 'foreignKey' => 'linklists_category_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ) - ); - -/** - * hasAndBelongsToMany associations - * - * @var array - */ - public $hasAndBelongsToMany = array( - 'Block' => array( - 'className' => 'Block', - 'joinTable' => 'linklists_blocks', - 'foreignKey' => 'linklist_id', - 'associationForeignKey' => 'block_id', - 'unique' => 'keepExisting', - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'limit' => '', - 'offset' => '', - 'finderQuery' => '', - ) - ); - -} diff --git a/Model/LinklistPartSetting.php b/Model/LinklistPartSetting.php deleted file mode 100644 index 870aacc..0000000 --- a/Model/LinklistPartSetting.php +++ /dev/null @@ -1,118 +0,0 @@ -<?php -/** - * LinklistPartSetting Model - * - * @property LinklistBlock $LinklistBlock - * @property Part $Part - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -App::uses('LinkListsAppModel', 'LinkLists.Model'); - -/** - * Summary for LinklistPartSetting Model - */ -class LinklistPartSetting extends LinkListsAppModel { - -/** - * Use database config - * - * @var string - */ - public $useDbConfig = 'master'; - -/** - * Validation rules - * - * @var array - */ - public $validate = array( - 'linklist_block_id' => array( - 'numeric' => array( - 'rule' => array('numeric'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - 'part_id' => array( - 'numeric' => array( - 'rule' => array('numeric'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - 'readable_content' => array( - 'boolean' => array( - 'rule' => array('boolean'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - 'editable_content' => array( - 'boolean' => array( - 'rule' => array('boolean'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - 'creatable_content' => array( - 'boolean' => array( - 'rule' => array('boolean'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - 'publishable_content' => array( - 'boolean' => array( - 'rule' => array('boolean'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - ); - - //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( - 'LinklistBlock' => array( - 'className' => 'LinklistBlock', - 'foreignKey' => 'linklist_block_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ), - 'Part' => array( - 'className' => 'Part', - 'foreignKey' => 'part_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ) - ); -} diff --git a/Model/LinklistSetting.php b/Model/LinklistSetting.php deleted file mode 100644 index e44285c..0000000 --- a/Model/LinklistSetting.php +++ /dev/null @@ -1,60 +0,0 @@ -<?php -/** - * LinklistSetting Model - * - * @property LinklistBlock $LinklistBlock - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -App::uses('LinkListsAppModel', 'LinkLists.Model'); - -/** - * Summary for LinklistSetting Model - */ -class LinklistSetting extends LinkListsAppModel { - -/** - * Use database config - * - * @var string - */ - public $useDbConfig = 'master'; - -/** - * Validation rules - * - * @var array - */ - public $validate = array( - 'linklist_block_id' => array( - 'numeric' => array( - 'rule' => array('numeric'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - ); - - //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( - 'LinklistBlock' => array( - 'className' => 'LinklistBlock', - 'foreignKey' => 'linklist_block_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ) - ); -} diff --git a/Model/LinklistsBlock.php b/Model/LinklistsBlock.php deleted file mode 100644 index f047f9b..0000000 --- a/Model/LinklistsBlock.php +++ /dev/null @@ -1,97 +0,0 @@ -<?php -/** - * LinklistsBlock Model - * - * @property Block $Block - * @property Linklist $Linklist - * @property LinklistsCategory $LinklistsCategory - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -App::uses('LinkListsAppModel', 'LinkLists.Model'); - -/** - * Summary for LinklistsBlock Model - */ -class LinklistsBlock extends LinkListsAppModel { - -/** - * Use database config - * - * @var string - */ - public $useDbConfig = 'master'; - -/** - * Validation rules - * - * @var array - */ - public $validate = array( - 'block_id' => array( - 'numeric' => array( - 'rule' => array('numeric'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - ); - - //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( - 'Block' => array( - 'className' => 'Block', - 'foreignKey' => 'block_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ) - ); - -/** - * hasMany associations - * - * @var array - */ - public $hasMany = array( - 'Linklist' => array( - 'className' => 'Linklist', - 'foreignKey' => 'linklists_block_id', - 'dependent' => false, - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'limit' => '', - 'offset' => '', - 'exclusive' => '', - 'finderQuery' => '', - 'counterQuery' => '' - ), - 'LinklistsCategory' => array( - 'className' => 'LinklistsCategory', - 'foreignKey' => 'linklists_block_id', - 'dependent' => false, - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'limit' => '', - 'offset' => '', - 'exclusive' => '', - 'finderQuery' => '', - 'counterQuery' => '' - ) - ); - -} diff --git a/Model/LinklistsCategory.php b/Model/LinklistsCategory.php deleted file mode 100644 index 9405527..0000000 --- a/Model/LinklistsCategory.php +++ /dev/null @@ -1,121 +0,0 @@ -<?php -/** - * LinklistsCategory Model - * - * @property LinklistsBlock $LinklistsBlock - * @property Language $Language - * @property Linklist $Linklist - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -App::uses('LinkListsAppModel', 'LinkLists.Model'); - -/** - * Summary for LinklistsCategory Model - */ -class LinklistsCategory extends LinkListsAppModel { - -/** - * Use database config - * - * @var string - */ - public $useDbConfig = 'master'; - -/** - * Validation rules - * - * @var array - */ - public $validate = array( - 'linklists_block_id' => array( - 'numeric' => array( - 'rule' => array('numeric'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - 'status' => array( - 'numeric' => array( - 'rule' => array('numeric'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - 'language_id' => array( - 'numeric' => array( - 'rule' => array('numeric'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - 'is_auto_translated' => array( - 'boolean' => array( - 'rule' => array('boolean'), - //'message' => 'Your custom message here', - //'allowEmpty' => false, - //'required' => false, - //'last' => false, // Stop validation after this rule - //'on' => 'create', // Limit validation to 'create' or 'update' operations - ), - ), - ); - - //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( - 'LinklistsBlock' => array( - 'className' => 'LinklistsBlock', - 'foreignKey' => 'linklists_block_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ), - 'Language' => array( - 'className' => 'Language', - 'foreignKey' => 'language_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ) - ); - -/** - * hasMany associations - * - * @var array - */ - public $hasMany = array( - 'Linklist' => array( - 'className' => 'Linklist', - 'foreignKey' => 'linklists_category_id', - 'dependent' => false, - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'limit' => '', - 'offset' => '', - 'exclusive' => '', - 'finderQuery' => '', - 'counterQuery' => '' - ) - ); - -} diff --git a/Model/LinksAppModel.php b/Model/LinksAppModel.php new file mode 100644 index 0000000..565806f --- /dev/null +++ b/Model/LinksAppModel.php @@ -0,0 +1,22 @@ +<?php +/** + * LinkApp Model + * + * @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('AppModel', 'Model'); + +/** + * LinkApp Model + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Model + */ +class LinksAppModel extends AppModel { + +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..c94eec2 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +Links +============== + +[![Tests Status](https://github.com/NetCommons3/Links/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/NetCommons3/Links/actions/workflows/tests.yml) +[![Coverage Status](https://coveralls.io/repos/NetCommons3/Links/badge.svg?branch=master)](https://coveralls.io/r/NetCommons3/Links?branch=master) +[![Stable Version](https://img.shields.io/packagist/v/netcommons/links.svg?label=stable)](https://packagist.org/packages/netcommons/links) diff --git a/Test/Case/AllLinksTest.php b/Test/Case/AllLinksTest.php new file mode 100644 index 0000000..96a353a --- /dev/null +++ b/Test/Case/AllLinksTest.php @@ -0,0 +1,33 @@ +<?php +/** + * Links All Test Suite + * + * @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('NetCommonsTestSuite', 'NetCommons.TestSuite'); + +/** + * Links All Test Suite + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case + * @codeCoverageIgnore + */ +class AllLinksTest extends NetCommonsTestSuite { + +/** + * All test suite + * + * @return NetCommonsTestSuite + */ + public static function suite() { + $plugin = preg_replace('/^All([\w]+)Test$/', '$1', __CLASS__); + $suite = new NetCommonsTestSuite(sprintf('All %s Plugin tests', $plugin)); + $suite->addTestDirectoryRecursive(CakePlugin::path($plugin) . 'Test' . DS . 'Case'); + return $suite; + } +} diff --git a/Test/Case/Controller/Component/empty b/Test/Case/Controller/Component/empty deleted file mode 100644 index e69de29..0000000 diff --git a/Test/Case/Controller/LinkBlockRolePermissionsController/EditTest.php b/Test/Case/Controller/LinkBlockRolePermissionsController/EditTest.php new file mode 100644 index 0000000..cc49d93 --- /dev/null +++ b/Test/Case/Controller/LinkBlockRolePermissionsController/EditTest.php @@ -0,0 +1,154 @@ +<?php +/** + * LinkBlockRolePermissionsController::edit()のテスト + * + * @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('BlockRolePermissionsControllerEditTest', 'Blocks.TestSuite'); + +/** + * LinkBlockRolePermissionsController::edit()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinkBlockRolePermissionsController + */ +class LinkBlockRolePermissionsControllerEditTest extends BlockRolePermissionsControllerEditTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'link_block_role_permissions'; + +/** + * 権限設定で使用するFieldsの取得 + * + * @return array + */ + private function __approvalFields() { + $data = array( + 'LinkSetting' => array( + 'use_workflow', + 'approval_type', + ) + ); + + return $data; + } + +/** + * テストDataの取得 + * + * @return array + */ + private function __data() { + $data = array( + 'LinkSetting' => array( + 'id' => 2, + 'block_key' => 'block_2', + 'use_workflow' => '1', + 'approval_type' => '1', + ) + ); + + return $data; + } + +/** + * edit()アクションDataProvider + * + * ### 戻り値 + * - approvalFields コンテンツ承認の利用有無のフィールド + * - exception Exception + * - return testActionの実行後の結果 + * + * @return array + */ + public function dataProviderEditGet() { + return array( + array('approvalFields' => $this->__approvalFields()) + ); + } + +/** + * 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('Links.LinkBlock', 'getLinkBlock'); + + $exception = 'BadRequestException'; + $this->testEditGet($approvalFields, $exception, $return); + } + +/** + * edit()アクションDataProvider + * + * ### 戻り値 + * - data POSTデータ + * - exception Exception + * - return testActionの実行後の結果 + * + * @return array + */ + public function dataProviderEditPost() { + return array( + array('data' => $this->__data()) + ); + } + +/** + * 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'; + + //テスト実施 + $result = $this->testEditPost($data, false, $return); + + $approvalFields = $this->__approvalFields(); + $this->_assertEditGetPermission($approvalFields, $result); + } + +} diff --git a/Test/Case/Controller/LinkBlocksController/BeforeFilterTest.php b/Test/Case/Controller/LinkBlocksController/BeforeFilterTest.php new file mode 100644 index 0000000..c64f7ae --- /dev/null +++ b/Test/Case/Controller/LinkBlocksController/BeforeFilterTest.php @@ -0,0 +1,94 @@ +<?php +/** + * LinkBlocksController::beforeFilter()のテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * LinkBlocksController::beforeFilter()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinkBlocksController + */ +class LinkBlocksControllerBeforeFilterTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'link_blocks'; + +/** + * index()アクションのテスト + * + * @return void + */ + public function testBeforeFilterIndex() { + //ログイン + TestAuthGeneral::login($this); + + //テスト実行 + $this->_testGetAction(array('action' => 'index', 'block_id' => '2', 'frame_id' => '6'), + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $this->assertFalse($this->controller->Components->loaded('Categories.CategoryEdit')); + $this->assertNotEmpty($this->view); + + //ログアウト + TestAuthGeneral::logout($this); + } + +/** + * index()アクションのテスト + * + * @return void + */ + public function testBeforeFilterEdit() { + //ログイン + TestAuthGeneral::login($this); + + //テスト実行 + $this->_testGetAction(array('action' => 'edit', 'block_id' => '2', 'frame_id' => '6'), + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $this->assertTrue($this->controller->Components->loaded('Categories.CategoryEdit')); + $this->assertNotEmpty($this->view); + + //ログアウト + TestAuthGeneral::logout($this); + } + +} diff --git a/Test/Case/Controller/LinkBlocksController/EditTest.php b/Test/Case/Controller/LinkBlocksController/EditTest.php new file mode 100644 index 0000000..4e49383 --- /dev/null +++ b/Test/Case/Controller/LinkBlocksController/EditTest.php @@ -0,0 +1,230 @@ +<?php +/** + * LinkBlocksController::edit()のテスト + * + * @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('BlocksControllerEditTest', 'Blocks.TestSuite'); + +/** + * LinkBlocksController::edit()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinkBlocksController + */ +class LinkBlocksControllerEditTest extends BlocksControllerEditTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'link_blocks'; + +/** + * Edit controller name + * + * @var string + */ + protected $_editController = 'link_blocks'; + +/** + * テストDataの取得 + * + * @param bool $isEdit 編集かどうか + * @return array + */ + private function __data($isEdit) { + $frameId = '6'; + if ($isEdit) { + $blockId = '2'; + $blockKey = 'block_2'; + $linkId = '3'; + $linkKey = $blockKey; + } else { + $blockId = null; + $blockKey = null; + $linkId = null; + $linkKey = $blockKey; + } + + $data = array( + 'Frame' => array( + 'id' => $frameId + ), + 'Block' => array( + 'id' => $blockId, + 'key' => $blockKey, + 'language_id' => '2', + 'room_id' => '2', + 'plugin_key' => $this->plugin, + 'public_type' => '1', + 'from' => null, + 'to' => null, + ), + 'LinkSetting' => array( + 'id' => $linkId, + 'block_key' => $linkKey, + ), + 'LinkBlock' => array( + 'id' => $blockId, + 'key' => $blockKey, + 'name' => 'Link name', + ), + ); + + return $data; + } + +/** + * add()アクションDataProvider + * + * ### 戻り値 + * - method: リクエストメソッド(get or post or put) + * - data: 登録データ + * - validationError: バリデーションエラー + * + * @return array + */ + public function dataProviderAdd() { + $data = $this->__data(false); + + //テストデータ + $results = array(); + $results[0] = array('method' => 'get'); + $results[1] = array('method' => 'put'); + $results[2] = array('method' => 'post', 'data' => $data, 'validationError' => false); + $results[3] = array('method' => 'post', 'data' => $data, + 'validationError' => array( + 'field' => 'LinkBlock.name', + 'value' => '', + 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('links', 'Link list Title')), + ) + ); + + return $results; + } + +/** + * edit()アクションDataProvider + * + * ### 戻り値 + * - method: リクエストメソッド(get or post or put) + * - data: 登録データ + * - validationError: バリデーションエラー + * + * @return array + */ + public function dataProviderEdit() { + $data = $this->__data(true); + + //テストデータ + $results = array(); + $results[0] = array('method' => 'get'); + $results[1] = array('method' => 'post'); + $results[2] = array('method' => 'put', 'data' => $data, 'validationError' => false); + $results[3] = array('method' => 'put', 'data' => $data, + 'validationError' => array( + 'field' => 'LinkBlock.name', + 'value' => '', + 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('links', 'Link list Title')), + ) + ); + + return $results; + } + +/** + * edit()アクションのExceptionErrorテスト + * + * @return void + */ + public function testEditGetOnExceptionError() { + //ログイン + TestAuthGeneral::login($this); + + //テストデータ + $this->_mockForReturnFalse('Links.LinkBlock', 'getLinkBlock'); + + //テスト実行 + $this->_testGetAction(array('action' => 'edit', 'block_id' => '2', 'frame_id' => '6'), null, 'BadRequestException'); + + //ログアウト + TestAuthGeneral::logout($this); + } + +/** + * delete()アクションDataProvider + * + * ### 戻り値 + * - data 削除データ + * + * @return array + */ + public function dataProviderDelete() { + $data = array( + 'Block' => array( + 'id' => '4', + 'key' => 'block_2', + ), + 'LinkBlock' => array( + 'key' => 'block_2', + ), + ); + + //テストデータ + $results = array(); + $results[0] = array('data' => $data); + + return $results; + } + +/** + * delete()アクションのExceptionErrorテスト + * + * @return void + */ + public function testDeleteOnExceptionError() { + //ログイン + TestAuthGeneral::login($this); + + //テストデータ + $this->_mockForReturnFalse('Links.LinkBlock', 'deleteLinkBlock'); + + //テスト実行 + $data = $this->dataProviderDelete()[0]['data']; + $this->_testPostAction('delete', $data, array('action' => 'delete', 'block_id' => '2', 'frame_id' => '6'), 'BadRequestException'); + + //ログアウト + TestAuthGeneral::logout($this); + } + +} diff --git a/Test/Case/Controller/LinkBlocksController/IndexPaginatorTest.php b/Test/Case/Controller/LinkBlocksController/IndexPaginatorTest.php new file mode 100644 index 0000000..5596f34 --- /dev/null +++ b/Test/Case/Controller/LinkBlocksController/IndexPaginatorTest.php @@ -0,0 +1,59 @@ +<?php +/** + * LinkBlocksController::index()のPaginatorテスト + * + * @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('BlocksControllerPaginatorTest', 'Blocks.TestSuite'); + +/** + * LinkBlocksController::index()のPaginatorテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinkBlocksController + */ +class LinkBlocksControllerIndexPaginatorTest extends BlocksControllerPaginatorTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'link_blocks'; + +/** + * Edit controller name + * + * @var string + */ + protected $_editController = 'link_blocks'; + +} diff --git a/Test/Case/Controller/LinkBlocksController/IndexTest.php b/Test/Case/Controller/LinkBlocksController/IndexTest.php new file mode 100644 index 0000000..c14f6a8 --- /dev/null +++ b/Test/Case/Controller/LinkBlocksController/IndexTest.php @@ -0,0 +1,59 @@ +<?php +/** + * LinkBlocksController::index()のテスト + * + * @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('BlocksControllerTest', 'Blocks.TestSuite'); + +/** + * LinkBlocksController::index()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinkBlocksController + */ +class LinkBlocksControllerIndexTest extends BlocksControllerTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'link_blocks'; + +/** + * Edit controller name + * + * @var string + */ + protected $_editController = 'link_blocks'; + +} diff --git a/Test/Case/Controller/LinkFrameSettingsController/EditTest.php b/Test/Case/Controller/LinkFrameSettingsController/EditTest.php new file mode 100644 index 0000000..de99a90 --- /dev/null +++ b/Test/Case/Controller/LinkFrameSettingsController/EditTest.php @@ -0,0 +1,105 @@ +<?php +/** + * LinkFrameSettingsController::edit()のテスト + * + * @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('FrameSettingsControllerTest', 'Frames.TestSuite'); + +/** + * LinkFrameSettingsController::edit()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinkFrameSettingsController + */ +class LinkFrameSettingsControllerEditTest extends FrameSettingsControllerTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'link_frame_settings'; + +/** + * テストDataの取得 + * + * @return array + */ + private function __data() { + $frameId = '6'; + $frameKey = 'frame_3'; + $linkFrameId = '6'; + + $data = array( + 'Frame' => array( + 'id' => $frameId, + 'key' => $frameKey, + ), + 'LinkFrameSetting' => array( + 'id' => $linkFrameId, + 'frame_key' => $frameKey, + 'display_type' => '1', + 'category_separator_line' => '', + 'list_style' => '', + ), + ); + + return $data; + } + +/** + * edit()アクションDataProvider + * + * ### 戻り値 + * - method: リクエストメソッド(get or post or put) + * - data: 登録データ + * - validationError: バリデーションエラー(省略可) + * - exception: Exception Error(省略可) + * + * @return array + */ + public function dataProviderEdit() { + $data = $this->__data(); + + //テストデータ + $results = array(); + $results[0] = array('method' => 'get'); + $results[1] = array('method' => 'post', 'data' => $data, 'validationError' => false); + $results[2] = array('method' => 'put', 'data' => $data, 'validationError' => false); + $results[3] = array('method' => 'put', 'data' => $data, + 'validationError' => array( + 'field' => 'LinkFrameSetting.frame_key', + 'value' => null, + ), + 'BadRequestException' + ); + + return $results; + } + +} diff --git a/Test/Case/Controller/LinkListsCategoriesControllerTest.php b/Test/Case/Controller/LinkListsCategoriesControllerTest.php deleted file mode 100644 index 2e7b1c3..0000000 --- a/Test/Case/Controller/LinkListsCategoriesControllerTest.php +++ /dev/null @@ -1,71 +0,0 @@ -<?php -/** - * LinkListsCategoriesController Test Case - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -App::uses('LinkListsCategoriesController', 'LinkLists.Controller'); - -/** - * Summary for LinkListsCategoriesController Test Case - */ -class LinkListsCategoriesControllerTest extends ControllerTestCase { - -/** - * Fixtures - * - * @var array - */ - public $fixtures = array( - 'plugin.link_lists.linklists_category', - 'plugin.link_lists.linklists_block', - 'plugin.link_lists.language', - 'plugin.link_lists.linklist', - 'plugin.link_lists.site_setting', - 'plugin.link_lists.site_setting_value' - ); - -/** - * testIndex method - * - * @return void - */ - public function testIndex() { - } - -/** - * testView method - * - * @return void - */ - public function testView() { - } - -/** - * testAdd method - * - * @return void - */ - public function testAdd() { - } - -/** - * testEdit method - * - * @return void - */ - public function testEdit() { - } - -/** - * testDelete method - * - * @return void - */ - public function testDelete() { - } - -} diff --git a/Test/Case/Controller/LinkListsControllerTest.php b/Test/Case/Controller/LinkListsControllerTest.php deleted file mode 100644 index 5c62fb0..0000000 --- a/Test/Case/Controller/LinkListsControllerTest.php +++ /dev/null @@ -1,73 +0,0 @@ -<?php -/** - * LinkListsController Test Case - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -App::uses('LinkListsController', 'LinkLists.Controller'); - -/** - * Summary for LinkListsController Test Case - */ -class LinkListsControllerTest extends ControllerTestCase { - -/** - * Fixtures - * - * @var array - */ - public $fixtures = array( - 'plugin.link_lists.linklist', - 'plugin.link_lists.linklists_block', - 'plugin.link_lists.language', - 'plugin.link_lists.linklists_category', - 'plugin.link_lists.block', - 'plugin.link_lists.blocks_language', - 'plugin.link_lists.site_setting', - 'plugin.link_lists.site_setting_value' - ); - -/** - * testIndex method - * - * @return void - */ - public function testIndex() { - } - -/** - * testView method - * - * @return void - */ - public function testView() { - } - -/** - * testAdd method - * - * @return void - */ - public function testAdd() { - } - -/** - * testEdit method - * - * @return void - */ - public function testEdit() { - } - -/** - * testDelete method - * - * @return void - */ - public function testDelete() { - } - -} diff --git a/Test/Case/Controller/LinkMailSettingsController/EditTest.php b/Test/Case/Controller/LinkMailSettingsController/EditTest.php new file mode 100644 index 0000000..f4ba6f6 --- /dev/null +++ b/Test/Case/Controller/LinkMailSettingsController/EditTest.php @@ -0,0 +1,95 @@ +<?php +/** + * LinkMailSettingsController::edit()のテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * LinkMailSettingsController::edit()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinkMailSettingsController + */ +class LinkMailSettingsControllerEditTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.mails.mail_setting_fixed_phrase', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'link_mail_settings'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //ログイン + TestAuthGeneral::login($this); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + //ログアウト + TestAuthGeneral::logout($this); + + parent::tearDown(); + } + +/** + * edit()アクションのGetリクエストテスト + * + * @return void + */ + public function testEditGet() { + //テストデータ + $frameId = '6'; + $blockId = '2'; + + //テスト実行 + $this->_testGetAction(array('action' => 'edit', 'block_id' => $blockId, 'frame_id' => $frameId), + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $this->assertInput('form', null, 'links/link_mail_settings/edit/' . $blockId, $this->view); + } + +} diff --git a/Test/Case/Controller/LinkOrdersController/EditTest.php b/Test/Case/Controller/LinkOrdersController/EditTest.php new file mode 100644 index 0000000..26463c4 --- /dev/null +++ b/Test/Case/Controller/LinkOrdersController/EditTest.php @@ -0,0 +1,291 @@ +<?php +/** + * LinkOrdersController::edit()のテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); +App::uses('LinkOrderFixture', 'Links.Test/Fixture'); + +/** + * LinkOrdersController::edit()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinkOrdersController + */ +class LinkOrdersControllerEditTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'link_orders'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //ログイン + TestAuthGeneral::login($this); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + //ログアウト + TestAuthGeneral::logout($this); + + parent::tearDown(); + } + +/** + * edit()アクションのGetリクエストテスト + * + * @return void + */ + public function testEditGet() { + //テストデータ + $frameId = '6'; + $blockId = '2'; + $blockKey = 'block_1'; + + //テスト実行 + $this->_testGetAction(array('action' => 'edit', 'block_id' => $blockId, 'frame_id' => $frameId), + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $this->__assertEditGet($frameId, $blockId, $blockKey); + } + +/** + * edit()のチェック + * + * @param int $frameId フレームID + * @param int $blockId ブロックID + * @param string $blockKey ブロックKey + * @return void + */ + private function __assertEditGet($frameId, $blockId, $blockKey) { + $this->assertInput('form', null, 'links/link_orders/edit/' . $blockId, $this->view); + $this->assertInput('input', '_method', 'PUT', $this->view); + $this->assertInput('input', 'data[Frame][id]', $frameId, $this->view); + $this->assertInput('input', 'data[Block][id]', $blockId, $this->view); + $this->assertInput('input', 'data[Block][key]', $blockKey, $this->view); + + $this->assertEquals($frameId, Hash::get($this->controller->request->data, 'Frame.id')); + $this->assertEquals($blockId, Hash::get($this->controller->request->data, 'Block.id')); + $this->assertEquals($blockKey, Hash::get($this->controller->request->data, 'Block.key')); + $this->assertCount(5, Hash::get($this->controller->request->data, 'LinkOrders')); + + $this->__assertRequestData($blockId, $blockKey, array( + 'Link' => array('id' => '5', 'key' => 'content_key_3'), + 'LinkOrder' => array('id' => '3', 'weight' => '1'), + 'Category' => array('id' => null, 'key' => null), + 'CategoryOrder' => array('id' => null, 'weight' => null), + )); + $this->__assertRequestData($blockId, $blockKey, array( + 'Link' => array('id' => '2', 'key' => 'content_key_1'), + 'LinkOrder' => array('id' => '1', 'weight' => '1'), + 'Category' => array('id' => '1', 'key' => 'category_1'), + 'CategoryOrder' => array('id' => '1', 'weight' => '1'), + )); + $this->__assertRequestData($blockId, $blockKey, array( + 'Link' => array('id' => '3', 'key' => 'content_key_2'), + 'LinkOrder' => array('id' => '2', 'weight' => '2'), + 'Category' => array('id' => '1', 'key' => 'category_1'), + 'CategoryOrder' => array('id' => '1', 'weight' => '1'), + )); + $this->__assertRequestData($blockId, $blockKey, array( + 'Link' => array('id' => '7', 'key' => 'content_key_4'), + 'LinkOrder' => array('id' => '4', 'weight' => '3'), + 'Category' => array('id' => '1', 'key' => 'category_1'), + 'CategoryOrder' => array('id' => '1', 'weight' => '1'), + )); + $this->__assertRequestData($blockId, $blockKey, array( + 'Link' => array('id' => '8', 'key' => 'content_key_5'), + 'LinkOrder' => array('id' => '5', 'weight' => '4'), + 'Category' => array('id' => '1', 'key' => 'category_1'), + 'CategoryOrder' => array('id' => '1', 'weight' => '1'), + )); + } + +/** + * edit()アクションの評価 + * + * @param int $blockId ブロックID + * @param string $blockKey ブロックKey + * @param array $expected 期待値 + * @return void + */ + private function __assertRequestData($blockId, $blockKey, $expected) { + $actual = $this->controller->request->data; + $linkOrderId = Hash::get($expected, 'LinkOrder.id'); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.Link.id'; + $this->assertEquals(Hash::get($expected, 'Link.id'), Hash::get($actual, $pathKey)); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.Link.key'; + $this->assertEquals(Hash::get($expected, 'Link.key'), Hash::get($actual, $pathKey)); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.Link.category_id'; + $this->assertEquals(Hash::get($expected, 'Category.id'), Hash::get($actual, $pathKey)); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.Link.block_id'; + $this->assertEquals($blockId, Hash::get($actual, $pathKey)); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.LinkOrder.id'; + $this->assertEquals($linkOrderId, Hash::get($actual, $pathKey)); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.LinkOrder.block_key'; + $this->assertEquals($blockKey, Hash::get($actual, $pathKey)); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.LinkOrder.category_key'; + $this->assertEquals(Hash::get($expected, 'Category.key'), Hash::get($actual, $pathKey)); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.LinkOrder.link_key'; + $this->assertEquals(Hash::get($expected, 'Link.key'), Hash::get($actual, $pathKey)); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.LinkOrder.weight'; + $this->assertEquals(Hash::get($expected, 'LinkOrder.weight'), Hash::get($actual, $pathKey)); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.Category.id'; + $this->assertEquals(Hash::get($expected, 'Category.id'), Hash::get($actual, $pathKey)); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.Category.key'; + $this->assertEquals(Hash::get($expected, 'Category.key'), Hash::get($actual, $pathKey)); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.CategoryOrder.id'; + $this->assertEquals(Hash::get($expected, 'CategoryOrder.id'), Hash::get($actual, $pathKey)); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.CategoryOrder.category_key'; + $this->assertEquals(Hash::get($expected, 'Category.key'), Hash::get($actual, $pathKey)); + + $pathKey = 'LinkOrders.' . $linkOrderId . '.CategoryOrder.weight'; + $this->assertEquals(Hash::get($expected, 'CategoryOrder.weight'), Hash::get($actual, $pathKey)); + } + +/** + * POSTリクエストデータ生成 + * + * @return array リクエストデータ + */ + private function __data() { + $data = array( + 'Frame' => array( + 'id' => '6' + ), + 'Block' => array( + 'id' => '2', 'key' => 'block_1' + ), + ); + $data['LinkOrders'] = array(); + $data['LinkOrders'][] = array('LinkOrder' => Hash::insert((new LinkOrderFixture())->records[2], 'weight', '1')); + $data['LinkOrders'][] = array('LinkOrder' => Hash::insert((new LinkOrderFixture())->records[4], 'weight', '1')); + $data['LinkOrders'][] = array('LinkOrder' => Hash::insert((new LinkOrderFixture())->records[3], 'weight', '2')); + $data['LinkOrders'][] = array('LinkOrder' => Hash::insert((new LinkOrderFixture())->records[1], 'weight', '3')); + $data['LinkOrders'][] = array('LinkOrder' => Hash::insert((new LinkOrderFixture())->records[0], 'weight', '4')); + $data['LinkOrders'] = Hash::combine($data['LinkOrders'], '{n}.LinkOrder.id', '{n}'); + + return $data; + } + +/** + * edit()アクションのPOSTリクエストテスト + * + * @return void + */ + public function testEditPost() { + //テストデータ + $frameId = '6'; + $blockId = '2'; + + //テスト実行 + $this->_testPostAction('put', $this->__data(), + array('action' => 'edit', 'block_id' => $blockId, 'frame_id' => $frameId), null, 'view'); + + //チェック + $header = $this->controller->response->header(); + $pattern = '/' . preg_quote('/', '/') . '/'; + $this->assertRegExp($pattern, $header['Location']); + } + +/** + * ValidationErrorテスト + * + * @return void + */ + public function testEditPostValidationError() { + $this->generateNc(Inflector::camelize($this->_controller), array('components' => array( + 'Flash' => array('set') + ))); + + //ログイン + TestAuthGeneral::login($this); + + //テストデータ + $frameId = '6'; + $blockId = '2'; + + //テスト実行 + $this->controller->Flash->expects($this->once()) + ->method('set') + ->will($this->returnValue(null)); + + $this->_testPostAction('put', Hash::insert($this->__data(), 'LinkOrders.{n}.LinkOrder.weight', 'aaaa'), + array('action' => 'edit', 'block_id' => $blockId, 'frame_id' => $frameId), null, 'view'); + } + +/** + * ExceptionErrorテスト + * + * @return void + */ + public function testEditPostOnExceptionError() { + $this->_mockForReturnFalse('Links.LinkBlock', 'getLinkBlock'); + + //テストデータ + $frameId = '6'; + $blockId = '2'; + + //テスト実行 + $this->_testPostAction('put', $this->__data(), + array('action' => 'edit', 'block_id' => $blockId, 'frame_id' => $frameId), 'BadRequestException', 'view'); + } + +} diff --git a/Test/Case/Controller/LinksController/AddTest.php b/Test/Case/Controller/LinksController/AddTest.php new file mode 100644 index 0000000..87bc0c7 --- /dev/null +++ b/Test/Case/Controller/LinksController/AddTest.php @@ -0,0 +1,336 @@ +<?php +/** + * LinksController::add()のテスト + * + * @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('WorkflowControllerAddTest', 'Workflow.TestSuite'); + +/** + * LinksController::add()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinksController + */ +class LinksControllerAddTest extends WorkflowControllerAddTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'links'; + +/** + * テストDataの取得 + * + * @return array + */ + private function __data() { + $frameId = '6'; + $blockId = '2'; + $blockKey = 'block_1'; + + $data = array( + 'save_' . WorkflowComponent::STATUS_IN_DRAFT => null, + 'Frame' => array( + 'id' => $frameId, + ), + 'Block' => array( + 'id' => $blockId, + 'key' => $blockKey, + 'language_id' => '2', + 'room_id' => '2', + 'plugin_key' => $this->plugin, + ), + 'Link' => array( + 'id' => null, + 'key' => null, + 'language_id' => '2', + 'status' => null, + 'url' => 'http://www.netcommons.org', + 'title' => 'Lorem ipsum dolor sit amet', + 'description' => '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.', + ), + 'LinkOrder' => array( + 'id' => null, + 'block_key' => 'block_1', + 'category_key' => 'category_1', + 'link_key' => null, + ), + 'WorkflowComment' => array( + 'comment' => 'WorkflowComment save test', + ), + ); + + return $data; + } + +/** + * addアクションのGETテスト(ログインなし)用DataProvider + * + * ### 戻り値 + * - urlOptions: URLオプション + * - assert: テストの期待値 + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderAddGet() { + $data = $this->__data(); + + //テストデータ + $results = array(); + // * ログインなし + $results[0] = array( + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'] + ), + 'assert' => null, 'exception' => 'ForbiddenException', + ); + + return $results; + } + +/** + * addアクションのGETテスト(作成権限あり)用DataProvider + * + * ### 戻り値 + * - urlOptions: URLオプション + * - assert: テストの期待値 + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderAddGetByCreatable() { + $data = $this->__data(); + + //テストデータ + $results = array(); + $results[0] = array( + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + ), + 'assert' => array('method' => 'assertNotEmpty'), + ); + + // * フレームID指定なしテスト + array_push($results, Hash::merge($results[0], array( + 'urlOptions' => array('frame_id' => null, 'block_id' => $data['Block']['id']), + 'assert' => array('method' => 'assertNotEmpty'), + ))); + + return $results; + } + +/** + * addアクションのPOSTテスト用DataProvider + * + * ### 戻り値 + * - data: 登録データ + * - role: ロール + * - urlOptions: URLオプション + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderAddPost() { + $data = $this->__data(); + + //テストデータ + $results = array(); + // * ログインなし + $results[0] = array( + 'data' => $data, 'role' => null, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'] + ), + 'exception' => 'ForbiddenException' + ); + // * 作成権限あり + $results[1] = array( + 'data' => $data, 'role' => Role::ROOM_ROLE_KEY_GENERAL_USER, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'] + ), + ); + // * フレームID指定なしテスト + $results[2] = array( + 'data' => $data, 'role' => Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR, + 'urlOptions' => array( + 'frame_id' => null, + 'block_id' => $data['Block']['id']), + ); + + return $results; + } + +/** + * addアクションのValidationErrorテスト用DataProvider + * + * ### 戻り値 + * - data: 登録データ + * - urlOptions: URLオプション + * - validationError: バリデーションエラー + * + * @return array + */ + public function dataProviderAddValidationError() { + $data = $this->__data(); + $result = array( + 'data' => $data, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'] + ), + 'validationError' => array(), + ); + + //テストデータ + $results = array(); + array_push($results, Hash::merge($result, array( + 'validationError' => array( + 'field' => 'Link.url', + 'value' => 'aaaa', + 'message' => sprintf(__d('net_commons', 'Unauthorized pattern for %s. Please input the data in %s format.'), __d('links', 'URL'), __d('links', 'URL')), + ) + ))); + array_push($results, Hash::merge($result, array( + 'validationError' => array( + 'field' => 'Link.title', + 'value' => '', + 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('links', 'Title')), + ) + ))); + + return $results; + } + +/** + * Viewのアサーション + * + * @param array $data テストデータ + * @return void + */ + private function __assertAddGet($data) { + $this->assertInput( + 'input', 'data[Frame][id]', $data['Frame']['id'], $this->view + ); + $this->assertInput( + 'input', 'data[Block][id]', $data['Block']['id'], $this->view + ); + $this->assertInput( + 'input', 'data[Link][id]', null, $this->view + ); + $this->assertInput( + 'input', 'data[Link][key]', null, $this->view + ); + $this->assertInput( + 'input', 'data[Link][url]', null, $this->view + ); + $this->assertInput( + 'input', 'data[Link][title]', null, $this->view + ); + $this->assertInput( + 'input', 'data[Link][description]', null, $this->view + ); + $this->assertInput( + 'input', 'data[LinkOrder][id]', null, $this->view + ); + $this->assertInput( + 'input', 'data[LinkOrder][link_key]', null, $this->view + ); + } + +/** + * view(ctp)ファイルのテスト(公開権限なし) + * + * @return void + */ + public function testViewFileByCreatable() { + TestAuthGeneral::login($this, Role::ROOM_ROLE_KEY_GENERAL_USER); + + //テスト実行 + $data = $this->__data(); + $this->_testGetAction( + array( + 'action' => 'add', + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + ), + array('method' => 'assertNotEmpty') + ); + + //チェック + $this->__assertAddGet($data); + $this->assertInput('button', 'save_' . WorkflowComponent::STATUS_IN_DRAFT, null, $this->view); + $this->assertInput('button', 'save_' . WorkflowComponent::STATUS_APPROVAL_WAITING, null, $this->view); + + TestAuthGeneral::logout($this); + } + +/** + * view(ctp)ファイルのテスト(公開権限あり) + * + * @return void + */ + public function testViewFileByPublishable() { + //ログイン + TestAuthGeneral::login($this); + + //テスト実行 + $data = $this->__data(); + $this->_testGetAction( + array( + 'action' => 'add', + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + ), + array('method' => 'assertNotEmpty') + ); + + //チェック + $this->__assertAddGet($data); + $this->assertInput('button', 'save_' . WorkflowComponent::STATUS_IN_DRAFT, null, $this->view); + $this->assertInput('button', 'save_' . WorkflowComponent::STATUS_PUBLISHED, null, $this->view); + + //ログアウト + TestAuthGeneral::logout($this); + } + +} diff --git a/Test/Case/Controller/LinksController/BeforeFilterTest.php b/Test/Case/Controller/LinksController/BeforeFilterTest.php new file mode 100644 index 0000000..8fdd356 --- /dev/null +++ b/Test/Case/Controller/LinksController/BeforeFilterTest.php @@ -0,0 +1,109 @@ +<?php +/** + * LinksController::beforeFilter()のテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * LinksController::beforeFilter()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinksController + */ +class LinksControllerBeforeFilterTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'links'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + //ログイン + TestAuthGeneral::login($this); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + //ログアウト + TestAuthGeneral::logout($this); + parent::tearDown(); + } + +/** + * index()アクションのテスト + * + * @return void + */ + public function testBeforeFilter() { + //テスト実行 + $this->_testGetAction(array('action' => 'index', 'frame_id' => '6'), + array('method' => 'assertNotEmpty'), null, 'view'); + } + +/** + * index()アクションのテスト(ブロックIDなし) + * + * @return void + */ + public function testBeforeFilterWOBlockId() { + //テスト実行 + $this->_testGetAction(array('action' => 'index', 'frame_id' => '13'), + array('method' => 'assertEmpty'), null, 'view'); + } + +/** + * index()アクションのテスト(ブロックデータなし) + * + * @return void + */ + public function testBeforeFilterWOBlockData() { + $this->_mockForReturnFalse('Links.LinkBlock', 'getLinkBlock'); + + //テスト実行 + $this->_testGetAction(array('action' => 'index', 'frame_id' => '6'), + null, 'BadRequestException', 'view'); + } + +} diff --git a/Test/Case/Controller/LinksController/DeleteTest.php b/Test/Case/Controller/LinksController/DeleteTest.php new file mode 100644 index 0000000..1cbe350 --- /dev/null +++ b/Test/Case/Controller/LinksController/DeleteTest.php @@ -0,0 +1,279 @@ +<?php +/** + * LinksController::delete()のテスト + * + * @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('WorkflowControllerDeleteTest', 'Workflow.TestSuite'); + +/** + * LinksController::delete()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinksController + */ +class LinksControllerDeleteTest extends WorkflowControllerDeleteTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'links'; + +/** + * テストDataの取得 + * + * @param string $contentKey キー + * @return array + */ + private function __data($contentKey = null) { + $frameId = '6'; + $blockId = '2'; + $blockKey = 'block_1'; + if ($contentKey === 'content_key_2') { + $contentId = '3'; + $contentOrderId = '2'; + } elseif ($contentKey === 'content_key_4') { + $contentId = '5'; + $contentOrderId = '4'; + } else { + $contentId = '2'; + $contentOrderId = '1'; + } + + $data = array( + 'delete' => null, + 'Frame' => array( + 'id' => $frameId, + ), + 'Block' => array( + 'id' => $blockId, + 'key' => $blockKey, + ), + 'Link' => array( + 'id' => $contentId, + 'key' => $contentKey, + ), + 'LinkOrder' => array( + 'id' => $contentOrderId, + ), + ); + + return $data; + } + +/** + * deleteアクションのGETテスト用DataProvider + * + * ### 戻り値 + * - role: ロール + * - urlOptions: URLオプション + * - assert: テストの期待値 + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderDeleteGet() { + $data = $this->__data(); + + //テストデータ + $results = array(); + // * ログインなし + $results[0] = array('role' => null, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => 'content_key_1', + ), + 'assert' => null, 'exception' => 'ForbiddenException' + ); + // * 作成権限のみ(自分自身) + array_push($results, Hash::merge($results[0], array( + 'role' => Role::ROOM_ROLE_KEY_GENERAL_USER, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => 'content_key_2', + ), + 'assert' => null, 'exception' => 'BadRequestException' + ))); + // * 編集権限、公開権限なし + array_push($results, Hash::merge($results[0], array( + 'role' => Role::ROOM_ROLE_KEY_EDITOR, + 'assert' => null, 'exception' => 'BadRequestException' + ))); + // * 公開権限あり + array_push($results, Hash::merge($results[0], array( + 'role' => Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR, + 'assert' => null, 'exception' => 'BadRequestException' + ))); + + return $results; + } + +/** + * deleteアクションのPOSTテスト用DataProvider + * + * ### 戻り値 + * - data: 登録データ + * - role: ロール + * - urlOptions: URLオプション + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderDeletePost() { + $data = $this->__data(); + $contentKey1 = 'content_key_1'; + $contentKey2 = 'content_key_2'; + $contentKey4 = 'content_key_4'; + + //テストデータ + $results = array(); + // * ログインなし + array_push($results, array( + 'data' => $this->__data($contentKey1), + 'role' => null, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => $contentKey1 + ), + 'exception' => 'ForbiddenException' + )); + // * 作成権限のみ + // ** 他人の記事 + array_push($results, array( + 'data' => $this->__data($contentKey1), + 'role' => Role::ROOM_ROLE_KEY_GENERAL_USER, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => $contentKey1 + ), + 'exception' => 'BadRequestException' + )); + // ** 自分の記事&一度も公開されていない + array_push($results, array( + 'data' => $this->__data($contentKey2), + 'role' => Role::ROOM_ROLE_KEY_GENERAL_USER, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => $contentKey2 + ), + )); + // ** 自分の記事&一度公開している + array_push($results, array( + 'data' => $this->__data($contentKey4), + 'role' => Role::ROOM_ROLE_KEY_GENERAL_USER, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => $contentKey4 + ), + 'exception' => 'BadRequestException' + )); + // * 編集権限あり + // ** 公開していない + array_push($results, array( + 'data' => $this->__data($contentKey2), + 'role' => Role::ROOM_ROLE_KEY_EDITOR, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => $contentKey2 + ), + )); + // ** 公開している + array_push($results, array( + 'data' => $this->__data($contentKey4), + 'role' => Role::ROOM_ROLE_KEY_EDITOR, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => $contentKey4 + ), + 'exception' => 'BadRequestException' + )); + // * 公開権限あり + // ** フレームID指定なしテスト + array_push($results, array( + 'data' => $this->__data($contentKey1), + 'role' => Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR, + 'urlOptions' => array( + 'frame_id' => null, + 'block_id' => $data['Block']['id'], + 'key' => $contentKey1 + ), + )); + + return $results; + } + +/** + * deleteアクションのExceptionErrorテスト用DataProvider + * + * ### 戻り値 + * - mockModel: Mockのモデル + * - mockMethod: Mockのメソッド + * - data: 登録データ + * - urlOptions: URLオプション + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderDeleteExceptionError() { + $data = $this->__data(); + + //テストデータ + $results = array(); + $results[0] = array( + 'mockModel' => 'Links.Link', + 'mockMethod' => 'deleteLink', + 'data' => $data, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => 'content_key_1', + ), + 'exception' => 'BadRequestException', + 'return' => 'view' + ); + + return $results; + } + +} diff --git a/Test/Case/Controller/LinksController/EditTest.php b/Test/Case/Controller/LinksController/EditTest.php new file mode 100644 index 0000000..b5f0db6 --- /dev/null +++ b/Test/Case/Controller/LinksController/EditTest.php @@ -0,0 +1,448 @@ +<?php +/** + * LinksController::edit()のテスト + * + * @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('WorkflowControllerEditTest', 'Workflow.TestSuite'); +App::uses('LinkFixture', 'Links.Test/Fixture'); +App::uses('LinkOrderFixture', 'Links.Test/Fixture'); + +/** + * LinksController::edit()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinksController + */ +class LinksControllerEditTest extends WorkflowControllerEditTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'links'; + +/** + * テストDataの取得 + * + * @param string $role ロール + * @return array + */ + private function __data($role = null) { + $frameId = '6'; + $blockId = '2'; + $blockKey = 'block_1'; + if ($role === Role::ROOM_ROLE_KEY_GENERAL_USER) { + $contentId = '3'; + $contentKey = 'content_key_2'; + } else { + $contentId = '2'; + $contentKey = 'content_key_1'; + } + + $data = array( + 'save_' . WorkflowComponent::STATUS_IN_DRAFT => null, + 'Frame' => array( + 'id' => $frameId, + ), + 'Block' => array( + 'id' => $blockId, + 'key' => $blockKey, + 'language_id' => '2', + 'room_id' => '2', + 'plugin_key' => $this->plugin, + ), + 'Link' => Hash::get(Hash::extract((new LinkFixture())->records, '{n}[id=' . $contentId . ']'), '0'), + 'LinkOrder' => Hash::get(Hash::extract((new LinkOrderFixture())->records, '{n}[link_key=' . $contentKey . ']'), '0'), + 'WorkflowComment' => array( + 'comment' => 'WorkflowComment save test', + ), + ); + + return $data; + } + +/** + * editアクションのGETテスト(ログインなし)用DataProvider + * + * ### 戻り値 + * - urlOptions: URLオプション + * - assert: テストの期待値 + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderEditGet() { + $data = $this->__data(); + + //テストデータ + $results = array(); + // * ログインなし + $results[0] = array( + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => 'content_key_1' + ), + 'assert' => null, 'exception' => 'ForbiddenException' + ); + + return $results; + } + +/** + * editアクションのGETテスト(作成権限のみ)用DataProvider + * + * ### 戻り値 + * - urlOptions: URLオプション + * - assert: テストの期待値 + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderEditGetByCreatable() { + $data = $this->__data(); + + //テストデータ + // * 作成権限のみ + $results = array(); + // ** 他人の記事 + $results[0] = array( + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => 'content_key_1' + ), + 'assert' => null, 'exception' => 'BadRequestException' + ); + // ** 自分の記事 + $results[1] = array( + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => 'content_key_2' + ), + 'assert' => array('method' => 'assertNotEmpty'), + ); + + return $results; + } + +/** + * editアクションのGETテスト(編集権限あり、公開権限なし)用DataProvider + * + * ### 戻り値 + * - urlOptions: URLオプション + * - assert: テストの期待値 + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderEditGetByEditable() { + $data = $this->__data(); + + //テストデータ + // * 編集権限あり + $results = array(); + // ** コンテンツあり + $results[0] = array( + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => 'content_key_1' + ), + 'assert' => array('method' => 'assertNotEmpty'), + ); + + // ** コンテンツなし + $results[count($results)] = array( + 'urlOptions' => array( + 'frame_id' => '14', + 'block_id' => null, + 'key' => null + ), + 'assert' => array('method' => 'assertEquals', 'expected' => 'emptyRender'), + 'exception' => null, 'return' => 'viewFile' + ); + + return $results; + } + +/** + * editアクションのGETテスト(公開権限あり)用DataProvider + * + * ### 戻り値 + * - urlOptions: URLオプション + * - assert: テストの期待値 + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderEditGetByPublishable() { + $data = $this->__data(); + + //テストデータ + // * フレームID指定なしテスト + $results = array(); + $results[0] = array( + 'urlOptions' => array( + 'frame_id' => null, + 'block_id' => $data['Block']['id'], + 'key' => 'content_key_1' + ), + 'assert' => array('method' => 'assertNotEmpty'), + ); + + return $results; + } + +/** + * editアクションのPOSTテスト用DataProvider + * + * ### 戻り値 + * - data: 登録データ + * - role: ロール + * - urlOptions: URLオプション + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderEditPost() { + $data = $this->__data(); + + //テストデータ + $results = array(); + // * ログインなし + $contentKey = 'content_key_1'; + array_push($results, array( + 'data' => $data, + 'role' => null, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => $contentKey, + ), + 'exception' => 'ForbiddenException' + )); + // * 作成権限のみ + // ** 他人の記事 + $contentKey = 'content_key_1'; + array_push($results, array( + 'data' => $data, + 'role' => Role::ROOM_ROLE_KEY_GENERAL_USER, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => $contentKey, + ), + 'exception' => 'BadRequestException' + )); + // ** 自分の記事 + $contentKey = 'content_key_2'; + array_push($results, array( + 'data' => $this->__data(Role::ROOM_ROLE_KEY_GENERAL_USER), + 'role' => Role::ROOM_ROLE_KEY_GENERAL_USER, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => $contentKey, + ), + )); + // * 編集権限あり + // ** コンテンツあり + $contentKey = 'content_key_1'; + array_push($results, array( + 'data' => $data, + 'role' => Role::ROOM_ROLE_KEY_EDITOR, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => $contentKey, + ), + )); + // ** フレームID指定なしテスト + $contentKey = 'content_key_1'; + array_push($results, array( + 'data' => $data, + 'role' => Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR, + 'urlOptions' => array( + 'frame_id' => null, + 'block_id' => $data['Block']['id'], + 'key' => $contentKey, + ), + )); + + return $results; + } + +/** + * editアクションのValidationErrorテスト用DataProvider + * + * ### 戻り値 + * - data: 登録データ + * - urlOptions: URLオプション + * - validationError: バリデーションエラー + * + * @return array + */ + public function dataProviderEditValidationError() { + $data = $this->__data(); + $result = array( + 'data' => $data, + 'urlOptions' => array( + 'frame_id' => $data['Frame']['id'], + 'block_id' => $data['Block']['id'], + 'key' => 'content_key_1', + ), + 'validationError' => array(), + ); + + //テストデータ + $results = array(); + array_push($results, Hash::merge($result, array( + 'validationError' => array( + 'field' => 'Link.url', + 'value' => 'aaaa', + 'message' => sprintf(__d('net_commons', 'Unauthorized pattern for %s. Please input the data in %s format.'), __d('links', 'URL'), __d('links', 'URL')), + ) + ))); + array_push($results, Hash::merge($result, array( + 'validationError' => array( + 'field' => 'Link.title', + 'value' => '', + 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('links', 'Title')), + ) + ))); + + return $results; + } + +/** + * Viewのアサーション + * + * @param array $data テストデータ + * @return void + */ + private function __assertEditGet($data) { + $this->assertInput( + 'input', 'data[Frame][id]', $data['Frame']['id'], $this->view + ); + $this->assertInput( + 'input', 'data[Block][id]', $data['Block']['id'], $this->view + ); + $this->assertInput( + 'input', 'data[Link][id]', $data['Link']['id'], $this->view + ); + $this->assertInput( + 'input', 'data[Link][key]', $data['Link']['key'], $this->view + ); + $this->assertInput( + 'input', 'data[Link][url]', null, $this->view + ); + $this->assertInput( + 'input', 'data[Link][title]', null, $this->view + ); + $this->assertInput( + 'input', 'data[Link][description]', null, $this->view + ); + $this->assertInput( + 'input', 'data[LinkOrder][id]', $data['LinkOrder']['id'], $this->view + ); + $this->assertInput( + 'input', 'data[LinkOrder][link_key]', $data['LinkOrder']['link_key'], $this->view + ); + } + +/** + * view(ctp)ファイルのテスト(公開権限なし) + * + * @return void + */ + public function testViewFileByEditable() { + TestAuthGeneral::login($this, Role::ROOM_ROLE_KEY_EDITOR); + + //テスト実行 + $data = $this->__data(); + $this->_testGetAction( + array( + 'action' => 'edit', + 'block_id' => $data['Block']['id'], + 'frame_id' => $data['Frame']['id'], + 'key' => 'content_key_1', + ), + array('method' => 'assertNotEmpty') + ); + + //チェック + $this->__assertEditGet($data); + $this->assertInput('button', 'save_' . WorkflowComponent::STATUS_IN_DRAFT, null, $this->view); + $this->assertInput('button', 'save_' . WorkflowComponent::STATUS_APPROVAL_WAITING, null, $this->view); + $this->assertNotRegExp('/<input.*?name="_method" value="DELETE".*?>/', $this->view); + + TestAuthGeneral::logout($this); + } + +/** + * view(ctp)ファイルのテスト(公開権限あり) + * + * @return void + */ + public function testViewFileByPublishable() { + //ログイン + TestAuthGeneral::login($this); + + //テスト実行 + $data = $this->__data(); + $urlOptions = array( + 'action' => 'edit', + 'block_id' => $data['Block']['id'], + 'frame_id' => $data['Frame']['id'], + 'key' => 'content_key_1', + ); + $this->_testGetAction($urlOptions, array('method' => 'assertNotEmpty')); + + //チェック + $this->__assertEditGet($data); + $this->assertInput('button', 'save_' . WorkflowComponent::STATUS_IN_DRAFT, null, $this->view); + $this->assertInput('button', 'save_' . WorkflowComponent::STATUS_PUBLISHED, null, $this->view); + $this->assertInput('input', '_method', 'DELETE', $this->view); + + //ログアウト + TestAuthGeneral::logout($this); + } + +} diff --git a/Test/Case/Controller/LinksController/GetTest.php b/Test/Case/Controller/LinksController/GetTest.php new file mode 100644 index 0000000..8d85673 --- /dev/null +++ b/Test/Case/Controller/LinksController/GetTest.php @@ -0,0 +1,145 @@ +<?php +/** + * LinksController::get()のテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * LinksController::get()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinksController + */ +class LinksControllerGetTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'links'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //テストプラグインのロード + NetCommonsCakeTestCase::loadTestPlugin($this, 'Links', 'TestLinks'); + //テストコントローラ生成 + $this->generateNc('TestLinks.TestControllerLinksControllerGet'); + //ログイン + TestAuthGeneral::login($this); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + //ログアウト + TestAuthGeneral::logout($this); + + parent::tearDown(); + } + +/** + * get()アクションのテスト + * + * @return void + */ + public function testGet() { + //テスト実行 + $actionUrl = array( + 'plugin' => 'test_links', 'controller' => 'test_controller_links_controller_get', + 'action' => 'get', 'frame_id' => '6' + ); + $paramUrl = 'success'; + + $result = $this->_testGetAction(NetCommonsUrl::actionUrl($actionUrl) . '&url=' . $paramUrl, + array('method' => 'assertNotEmpty'), null, 'json'); + + //チェック + $this->assertEquals('OK', $result['name']); + $this->assertEquals(200, $result['code']); + $this->assertNotEmpty($result['title']); + $this->assertNotEmpty($result['description']); + } + +/** + * get()アクションのテスト(URLが空値) + * + * @return void + */ + public function testGetWOUrl() { + //テスト実行 + $actionUrl = array( + 'plugin' => 'test_links', 'controller' => 'test_controller_links_controller_get', + 'action' => 'get', 'frame_id' => '6' + ); + $paramUrl = ''; + + $result = $this->_testGetAction(NetCommonsUrl::actionUrl($actionUrl) . '&url=' . $paramUrl, + null, 'BadRequestException', 'json'); + + //チェック + $this->assertEquals('Bad Request', $result['name']); + $this->assertEquals(sprintf(__d('net_commons', 'Please input %s.'), __d('links', 'URL')), $result['error']); + } + +/** + * get()アクションのテスト(URLが不正) + * + * @return void + */ + public function testGetOnBadUrl() { + //テスト実行 + $actionUrl = array( + 'plugin' => 'test_links', 'controller' => 'test_controller_links_controller_get', + 'action' => 'get', 'frame_id' => '6' + ); + $paramUrl = 'failure'; + + $result = $this->_testGetAction(NetCommonsUrl::actionUrl($actionUrl) . '&url=' . $paramUrl, + null, 'BadRequestException', 'json'); + + //チェック + $this->assertEquals('Bad Request', $result['name']); + $this->assertEquals(__d('links', 'Failed to obtain the title for this page.'), $result['error']); + } + +} diff --git a/Test/Case/Controller/LinksController/IndexTest.php b/Test/Case/Controller/LinksController/IndexTest.php new file mode 100644 index 0000000..181227f --- /dev/null +++ b/Test/Case/Controller/LinksController/IndexTest.php @@ -0,0 +1,220 @@ +<?php +/** + * LinksController::index()のテスト + * + * @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('WorkflowControllerIndexTest', 'Workflow.TestSuite'); + +/** + * LinksController::index()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinksController + */ +class LinksControllerIndexTest extends WorkflowControllerIndexTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.frame4link', + 'plugin.links.frame_public_language4link', + 'plugin.links.frames_language4link', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'links'; + +/** + * テストDataの取得 + * + * @param int $frameId フレームID + * @return array + */ + private function __data($frameId) { + $blockId = '2'; + + $data = array( + 'action' => 'index', + 'frame_id' => $frameId, + 'block_id' => $blockId, + ); + + return $data; + } + +/** + * indexアクションのテスト(ログインなし)用DataProvider + * + * ### 戻り値 + * - urlOptions: URLオプション + * - assert: テストの期待値 + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderIndex() { + //テストデータ + $results = array(); + $results[0] = array( + 'urlOptions' => $this->__data('6'), + 'assert' => array( + array('method' => 'assertTextContains', 'assert' => '<ul class="list-group'), + array('method' => 'assertTextContains', 'assert' => 'Description 1'), + ), + ); + $results[1] = array( + 'urlOptions' => $this->__data('7'), + 'assert' => array( + array('method' => 'assertTextContains', 'assert' => '<ul class="list-group'), + array('method' => 'assertTextNotContains', 'assert' => 'Description 1'), + ), + ); + $results[2] = array( + 'urlOptions' => $this->__data('8'), + 'assert' => array( + array('method' => 'assertTextContains', 'assert' => '<ul class="dropdown-menu"'), + array('method' => 'assertTextContains', 'assert' => 'Title 1'), + ), + ); + + return $results; + } + +/** + * indexアクションのテスト + * + * @param array $urlOptions URLオプション + * @param string $assert テストの期待値 + * @param string|null $exception Exception + * @param string $return testActionの実行後の結果 + * @dataProvider dataProviderIndex + * @return void + */ + public function testIndex($urlOptions, $assert, $exception = null, $return = 'view') { + //テスト実行 + parent::testIndex($urlOptions, array('method' => 'assertNotEmpty'), $exception, $return); + + //チェック + $method = $assert[0]['method']; + $this->$method($assert[0]['assert'], $this->view); + + $method = $assert[1]['method']; + $this->$method($assert[1]['assert'], $this->view); + } + +/** + * indexアクションのテスト(作成権限あり)用DataProvider + * + * ### 戻り値 + * - urlOptions: URLオプション + * - assert: テストの期待値 + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderIndexByCreatable() { + return array($this->dataProviderIndex()[0]); + } + +/** + * indexアクションのテスト(作成権限のみ) + * + * @param array $urlOptions URLオプション + * @param array $assert テストの期待値 + * @param string|null $exception Exception + * @param string $return testActionの実行後の結果 + * @dataProvider dataProviderIndexByCreatable + * @return void + */ + public function testIndexByCreatable($urlOptions, $assert, $exception = null, $return = 'view') { + //テスト実行 + parent::testIndexByCreatable($urlOptions, array('method' => 'assertNotEmpty'), $exception, $return); + + //チェック + $method = $assert[0]['method']; + $this->$method($assert[0]['assert'], $this->view); + + $this->assertTextContains('/links/links/add/2', $this->view); + $this->assertTextNotContains('/links/link_orders/edit/2', $this->view); + } + +/** + * indexアクションのテスト(編集権限あり)用DataProvider + * + * ### 戻り値 + * - urlOptions: URLオプション + * - assert: テストの期待値 + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderIndexByEditable() { + return array($this->dataProviderIndex()[0]); + } + +/** + * indexアクションのテスト(編集権限あり) + * + * @param array $urlOptions URLオプション + * @param array $assert テストの期待値 + * @param string|null $exception Exception + * @param string $return testActionの実行後の結果 + * @dataProvider dataProviderIndexByEditable + * @return void + */ + public function testIndexByEditable($urlOptions, $assert, $exception = null, $return = 'view') { + //テスト実行 + parent::testIndexByEditable($urlOptions, array('method' => 'assertNotEmpty'), $exception, $return); + + //チェック + $method = $assert[0]['method']; + $this->$method($assert[0]['assert'], $this->view); + + $this->assertTextContains('/links/links/add/2', $this->view); + $this->assertTextContains('/links/link_orders/edit/2', $this->view); + } + +/** + * ExceptionErrorテスト + * + * @return void + */ + public function testIndexOnExceptionError() { + $this->_mockForReturnFalse('Links.LinkFrameSetting', 'getLinkFrameSetting'); + + //テスト実行 + $this->_testGetAction($this->__data('6'), null, 'BadRequestException'); + } + +} diff --git a/Test/Case/Controller/LinksController/LinkTest.php b/Test/Case/Controller/LinksController/LinkTest.php new file mode 100644 index 0000000..3b74d2b --- /dev/null +++ b/Test/Case/Controller/LinksController/LinkTest.php @@ -0,0 +1,147 @@ +<?php +/** + * LinksController::link()のテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * LinksController::link()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinksController + */ +class LinksControllerLinkTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'links'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //ログイン + TestAuthGeneral::login($this); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + //ログアウト + TestAuthGeneral::logout($this); + + parent::tearDown(); + } + +/** + * link()アクションのGetリクエストテスト + * + * @return void + */ + public function testLinkGet() { + //テスト実行 + $this->_testGetAction(array('action' => 'link', 'frame_id' => '6'), + null, 'BadRequestException', 'json'); + } + +/** + * テストDataの取得 + * + * @return array + */ + private function __data() { + $data = array( + 'Frame' => array( + 'id' => '6', + ), + 'Block' => array( + 'id' => '2', + ), + 'Link' => array( + 'id' => '2', + 'key' => 'content_key_1', + ), + ); + return $data; + } + +/** + * link()アクションのテスト + * + * @return void + */ + public function testLinkPost() { + //テスト実行 + $data = $this->__data(); + $result = $this->_testPostAction('put', $data, array('action' => 'link'), null, 'json'); + + //チェック + $this->assertEquals('OK', $result['name']); + $this->assertEquals(200, $result['code']); + } + +/** + * viewアクションのテスト + * + * @return void + */ + public function testViewBadLinkId() { + //テスト実行 + $data = Hash::insert($this->__data(), 'Link.id', '999'); + $this->_testPostAction('put', $data, array('action' => 'link'), 'BadRequestException', 'json'); + } + +/** + * viewアクションのテスト + * + * @return void + */ + public function testViewOnLinkUpdateCountError() { + //テストデータ + $this->_mockForReturnFalse('Links.Link', 'updateCount'); + //テスト実行 + $data = $this->__data(); + $this->_testPostAction('put', $data, array('action' => 'link'), 'BadRequestException', 'json'); + } + +} diff --git a/Test/Case/Controller/LinksController/ViewTest.php b/Test/Case/Controller/LinksController/ViewTest.php new file mode 100644 index 0000000..1695794 --- /dev/null +++ b/Test/Case/Controller/LinksController/ViewTest.php @@ -0,0 +1,359 @@ +<?php +/** + * LinksController::view()のテスト + * + * @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('WorkflowControllerViewTest', 'Workflow.TestSuite'); + +/** + * LinksController::view()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Controller\LinksController + */ +class LinksControllerViewTest extends WorkflowControllerViewTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Controller name + * + * @var string + */ + protected $_controller = 'links'; + +/** + * テストDataの取得 + * + * @return array + */ + private function __data() { + $frameId = '6'; + $blockId = '2'; + $contentKey = 'content_key_1'; + + $data = array( + 'action' => 'view', + 'frame_id' => $frameId, + 'block_id' => $blockId, + 'key' => $contentKey, + ); + + return $data; + } + +/** + * viewアクションのテスト用DataProvider + * + * ### 戻り値 + * - urlOptions: URLオプション + * - assert: テストの期待値 + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderView() { + $data = $this->__data(); + + //テストデータ + $results = array(); + $results[0] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_1'), + 'assert' => array('method' => 'assertNotEmpty'), + ); + $results[1] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_2'), + 'assert' => null, 'exception' => 'BadRequestException' + ); + $results[2] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_3'), + 'assert' => array('method' => 'assertNotEmpty'), + ); + $results[3] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_4'), + 'assert' => array('method' => 'assertNotEmpty'), + ); + $results[4] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_5'), + 'assert' => null, 'exception' => 'BadRequestException' + ); + $results[5] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_999'), + 'assert' => null, 'exception' => 'BadRequestException' + ); + + return $results; + } + +/** + * viewアクションのテスト + * + * @param array $urlOptions URLオプション + * @param array $assert テストの期待値 + * @param string|null $exception Exception + * @param string $return testActionの実行後の結果 + * @dataProvider dataProviderView + * @return void + */ + public function testView($urlOptions, $assert, $exception = null, $return = 'view') { + //テスト実行 + parent::testView($urlOptions, $assert, $exception, $return); + if ($exception) { + return; + } + + //チェック + $this->__assertView($urlOptions['key'], false); + } + +/** + * viewアクションのテスト(作成権限のみ)用DataProvider + * + * ### 戻り値 + * - urlOptions: URLオプション + * - assert: テストの期待値 + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderViewByCreatable() { + $data = $this->__data(); + + //テストデータ + $results = array(); + $results[0] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_1'), + 'assert' => array('method' => 'assertNotEmpty'), + ); + $results[1] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_2'), + 'assert' => array('method' => 'assertNotEmpty'), + ); + $results[2] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_3'), + 'assert' => array('method' => 'assertNotEmpty'), + ); + $results[3] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_4'), + 'assert' => array('method' => 'assertNotEmpty'), + ); + $results[4] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_5'), + 'assert' => null, 'exception' => 'BadRequestException' + ); + $results[5] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_999'), + 'assert' => null, 'exception' => 'BadRequestException' + ); + + return $results; + } + +/** + * viewアクションのテスト(作成権限のみ) + * + * @param array $urlOptions URLオプション + * @param array $assert テストの期待値 + * @param string|null $exception Exception + * @param string $return testActionの実行後の結果 + * @dataProvider dataProviderViewByCreatable + * @return void + */ + public function testViewByCreatable($urlOptions, $assert, $exception = null, $return = 'view') { + //テスト実行 + parent::testViewByCreatable($urlOptions, $assert, $exception, $return); + if ($exception) { + return; + } + + //チェック + if ($urlOptions['key'] === 'content_key_1') { + $this->__assertView($urlOptions['key'], false); + + } elseif ($urlOptions['key'] === 'content_key_3') { + $this->__assertView($urlOptions['key'], true); + + } elseif ($urlOptions['key'] === 'content_key_4') { + $this->__assertView($urlOptions['key'], false); + + } else { + $this->__assertView($urlOptions['key'], false); + } + } + +/** + * viewアクションのテスト用DataProvider + * + * ### 戻り値 + * - urlOptions: URLオプション + * - assert: テストの期待値 + * - exception: Exception + * - return: testActionの実行後の結果 + * + * @return array + */ + public function dataProviderViewByEditable() { + $data = $this->__data(); + + //テストデータ + $results = array(); + $results[0] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_1'), + 'assert' => array('method' => 'assertNotEmpty'), + ); + $results[1] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_2'), + 'assert' => array('method' => 'assertNotEmpty'), + ); + $results[2] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_3'), + 'assert' => array('method' => 'assertNotEmpty'), + ); + $results[3] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_4'), + 'assert' => array('method' => 'assertNotEmpty'), + ); + $results[4] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_5'), + 'assert' => array('method' => 'assertNotEmpty'), + ); + $results[5] = array( + 'urlOptions' => Hash::insert($data, 'key', 'content_key_999'), + 'assert' => null, 'exception' => 'BadRequestException' + ); + + return $results; + } + +/** + * viewアクションのテスト(編集権限あり) + * + * @param array $urlOptions URLオプション + * @param array $assert テストの期待値 + * @param string|null $exception Exception + * @param string $return testActionの実行後の結果 + * @dataProvider dataProviderViewByEditable + * @return void + */ + public function testViewByEditable($urlOptions, $assert, $exception = null, $return = 'view') { + //テスト実行 + parent::testViewByEditable($urlOptions, $assert, $exception, $return); + if ($exception) { + return; + } + + //チェック + $this->__assertView($urlOptions['key'], true); + } + +/** + * view()のassert + * + * @param string $contentKey コンテンツキー + * @param bool $isLatest 最終コンテンツかどうか + * @return void + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) + */ + private function __assertView($contentKey, $isLatest = false) { + if ($contentKey === 'content_key_1') { + if ($isLatest) { + //コンテンツのデータ(id=2, key=content_key_1)に対する期待値 + $this->assertTextContains('Title 2', $this->view); + $this->assertTextContains('Description 2', $this->view); + $badgeId = 'nc-badge-6-2'; + } else { + //コンテンツのデータ(id=1, key=content_key_1)に対する期待値 + $this->assertTextContains('Title 1', $this->view); + $this->assertTextContains('Description 1', $this->view); + $badgeId = 'nc-badge-6-1'; + } + + } elseif ($contentKey === 'content_key_2') { + //コンテンツのデータ(id=3, key=content_key_2)に対する期待値 + $this->assertTextContains('Title 3', $this->view); + $this->assertTextContains('Description 3', $this->view); + $badgeId = 'nc-badge-6-3'; + + } elseif ($contentKey === 'content_key_3') { + if ($isLatest) { + //コンテンツのデータ(id=5, key=content_key_3)に対する期待値 + $this->assertTextContains('Title 5', $this->view); + $this->assertTextContains('Description 5', $this->view); + $badgeId = 'nc-badge-6-5'; + } else { + //コンテンツのデータ(id=4, key=content_key_3)に対する期待値 + $this->assertTextContains('Title 4', $this->view); + $this->assertTextContains('Description 4', $this->view); + $badgeId = 'nc-badge-6-4'; + } + + } elseif ($contentKey === 'content_key_4') { + if ($isLatest) { + //コンテンツのデータ(id=7, key=content_key_4)に対する期待値 + $this->assertTextContains('Title 7', $this->view); + $this->assertTextContains('Description 7', $this->view); + $badgeId = 'nc-badge-6-7'; + } else { + //コンテンツのデータ(id=6, key=content_key_4)に対する期待値 + $this->assertTextContains('Title 6', $this->view); + $this->assertTextContains('Description 6', $this->view); + $badgeId = 'nc-badge-6-6'; + } + + } elseif ($contentKey === 'content_key_5') { + //コンテンツのデータ(id=8, key=content_key_5)に対する期待値 + $this->assertTextContains('Title 8', $this->view); + $this->assertTextContains('Description 8', $this->view); + $badgeId = 'nc-badge-6-8'; + } + + $pattern = '/' . preg_quote('<span class="badge"', '/') . ' id="' . $badgeId . '">1' . preg_quote('</span>', '/') . '/'; + $result = str_replace("\n", '', $this->view); + $result = str_replace("\t", '', $result); + $this->assertRegExp($pattern, $result); + } + +/** + * viewアクションのテスト + * + * @return void + */ + //public function testViewOnLinkUpdateCountError() { + // //テストデータ + // $this->_mockForReturnFalse('Links.Link', 'updateCount'); + // $urlOptions = Hash::insert($this->__data(), 'key', 'content_key_1'); + // + // //テスト実行 + // parent::testView($urlOptions, null, 'BadRequestException'); + //} + +} diff --git a/Test/Case/Model/Behavior/empty b/Test/Case/Model/Behavior/empty deleted file mode 100644 index e69de29..0000000 diff --git a/Test/Case/Model/Link/DeleteLinkTest.php b/Test/Case/Model/Link/DeleteLinkTest.php new file mode 100644 index 0000000..071d5f6 --- /dev/null +++ b/Test/Case/Model/Link/DeleteLinkTest.php @@ -0,0 +1,102 @@ +<?php +/** + * Link::deleteLink()のテスト + * + * @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('WorkflowDeleteTest', 'Workflow.TestSuite'); +App::uses('LinkFixture', 'Links.Test/Fixture'); +App::uses('LinkOrderFixture', 'Links.Test/Fixture'); + +/** + * Link::deleteLink()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\Link + */ +class LinkDeleteLinkTest extends WorkflowDeleteTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'Link'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'deleteLink'; + +/** + * Delete用DataProvider + * + * ### 戻り値 + * - data: 削除データ + * - associationModels: 削除確認の関連モデル array(model => conditions) + * + * @return array テストデータ + */ + public function dataProviderDelete() { + $data['Link'] = (new LinkFixture())->records[0]; + $data['LinkOrder'] = (new LinkOrderFixture())->records[0]; + + $association = array(); + + $results = array(); + $results[0] = array($data, $association); + + return $results; + } + +/** + * ExceptionError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド + * + * @return array テストデータ + */ + public function dataProviderDeleteOnExceptionError() { + $data['Link'] = (new LinkFixture())->records[0]; + $data['LinkOrder'] = (new LinkOrderFixture())->records[0]; + + return array( + array($data, 'Links.Link', 'deleteAll'), + array($data, 'Links.LinkOrder', 'delete'), + ); + } + +} diff --git a/Test/Case/Model/Link/SaveLinkTest.php b/Test/Case/Model/Link/SaveLinkTest.php new file mode 100644 index 0000000..f93446a --- /dev/null +++ b/Test/Case/Model/Link/SaveLinkTest.php @@ -0,0 +1,131 @@ +<?php +/** + * Link::saveLink()のテスト + * + * @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('WorkflowSaveTest', 'Workflow.TestSuite'); +App::uses('LinkFixture', 'Links.Test/Fixture'); + +/** + * Link::saveLink()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\Link + */ +class LinkSaveLinkTest extends WorkflowSaveTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'Link'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'saveLink'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + $model = $this->_modelName; + $this->$model->Behaviors->unload('Topics'); + } + +/** + * Save用DataProvider + * + * ### 戻り値 + * - data 登録データ + * + * @return array テストデータ + */ + public function dataProviderSave() { + $data['Link'] = (new LinkFixture())->records[1]; + $data['Link']['status'] = '1'; + + $results = array(); + // * 編集の登録処理 + $results[0] = array($data); + // * 新規の登録処理 + $results[1] = array($data); + $results[1] = Hash::insert($results[1], '0.Link.id', null); + $results[1] = Hash::insert($results[1], '0.Link.key', null); + $results[1] = Hash::remove($results[1], '0.Link.created_user'); + + return $results; + } + +/** + * SaveのExceptionError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド + * + * @return array テストデータ + */ + public function dataProviderSaveOnExceptionError() { + $data['Link'] = (new LinkFixture())->records[0]; + + return array( + array($data, 'Links.Link', 'save'), + ); + } + +/** + * SaveのValidationError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド(省略可:デフォルト validates) + * + * @return array テストデータ + */ + public function dataProviderSaveOnValidationError() { + $data['Link'] = (new LinkFixture())->records[0]; + + return array( + array($data, 'Links.Link'), + ); + } + +} diff --git a/Test/Case/Model/Link/SaveTest.php b/Test/Case/Model/Link/SaveTest.php new file mode 100644 index 0000000..065d20b --- /dev/null +++ b/Test/Case/Model/Link/SaveTest.php @@ -0,0 +1,170 @@ +<?php +/** + * beforeSave()とafterSave()のテスト + * + * @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('NetCommonsModelTestCase', 'NetCommons.TestSuite'); +App::uses('LinkFixture', 'Links.Test/Fixture'); +App::uses('LinkOrderFixture', 'Links.Test/Fixture'); + +/** + * beforeSave()とafterSave()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\Link + */ +class LinkSaveTest extends NetCommonsModelTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'Link'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'save'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + $model = $this->_modelName; + $this->$model->Behaviors->unload('Topics'); + } + +/** + * テストDataの取得 + * + * @return array + */ + private function __data() { + Current::write('Room.id', '2'); + Current::writePermission('2', 'content_publishable', true); + Current::write('Block.key', 'block_1'); + + $data['Link'] = array( + 'block_id' => '2', + 'key' => '', + 'language_id' => '2', + 'category_id' => '1', + 'status' => '1', + 'url' => 'http://www.netcommons.org', + 'title' => 'Title new', + 'description' => '', + ); + $data['LinkOrder'] = array( + 'block_key' => 'block_1', + 'category_key' => 'category_1', + 'link_key' => '', + ); + return $data; + } + +/** + * テスト評価 + * + * @param array $result 結果 + * @param array $expected 期待値 + * @return void + */ + private function __assert($result, $expected) { + $model = $this->_modelName; + + $key = OriginalKeyBehavior::generateKey($this->$model->alias, $this->$model->useDbConfig); + $expected['Link'] = Hash::merge($expected['Link'], array( + 'key' => $key, + 'is_active' => true, + 'is_latest' => true, + 'id' => '9', + 'is_origin' => true, + 'is_translation' => false, + 'is_original_copy' => false, + )); + $expected['LinkOrder'] = Hash::merge($expected['LinkOrder'], array( + 'link_key' => $key, + 'weight' => 5, + 'id' => '6', + )); + + $this->assertDatetime($result['Link']['created']); + $this->assertDatetime($result['Link']['modified']); + $this->assertDatetime($result['LinkOrder']['created']); + $this->assertDatetime($result['LinkOrder']['modified']); + + $result = Hash::remove($result, '{s}.created'); + $result = Hash::remove($result, '{s}.modified'); + + $this->assertEquals($expected, $result); + } + +/** + * save()のテスト + * + * @return void + */ + public function testSave() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //テスト実施 + $data = $this->__data(); + $result = $this->$model->$methodName($data); + + //チェック + $this->__assert($result, $data); + } + +/** + * save()のExceptionErrorテスト + * + * @return void + */ + public function testSaveOnExceptionError() { + $model = $this->_modelName; + $methodName = $this->_methodName; + $this->_mockForReturnFalse($model, 'Links.LinkOrder', 'save'); + + //テスト実施 + $this->setExpectedException('InternalErrorException'); + $data = $this->__data(); + $this->$model->$methodName($data); + } + +} diff --git a/Test/Case/Model/Link/UpdateCountTest.php b/Test/Case/Model/Link/UpdateCountTest.php new file mode 100644 index 0000000..9cf35b9 --- /dev/null +++ b/Test/Case/Model/Link/UpdateCountTest.php @@ -0,0 +1,114 @@ +<?php +/** + * Link::updateCount()のテスト + * + * @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('NetCommonsModelTestCase', 'NetCommons.TestSuite'); + +/** + * Link::updateCount()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\Link + */ +class LinkUpdateCountTest extends NetCommonsModelTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'Link'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'updateCount'; + +/** + * updateCount()のテスト + * + * @return void + */ + public function testUpdateCount() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //データ生成 + $id = '2'; + Current::$current = Hash::insert(Current::$current, 'Block.id', '2'); + + //事前チェック + $result = $this->$model->find('first', array( + 'recursive' => -1, + 'fields' => array('id', 'key', 'click_count'), + 'conditions' => array('id' => $id), + )); + $expected = array('id' => '2', 'key' => 'content_key_1', 'click_count' => '1'); + $this->assertEquals($expected, $result[$this->$model->alias]); + + //テスト実施 + $result = $this->$model->$methodName($id); + $this->assertTrue($result); + + //チェック + $result = $this->$model->find('first', array( + 'recursive' => -1, + 'fields' => array('id', 'key', 'click_count'), + 'conditions' => array('id' => $id), + )); + $expected['click_count'] = '2'; + $this->assertEquals($expected, $result[$this->$model->alias]); + } + +/** + * updateCount()のExceptionErrorテスト + * + * @return void + */ + public function testUpdateCountOnExceptionError() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //データ生成 + $id = '2'; + Current::$current = Hash::insert(Current::$current, 'Block.id', '2'); + $this->_mockForReturnFalse($model, 'Links.Link', 'updateAll'); + + //テスト実施 + $this->setExpectedException('InternalErrorException'); + $this->$model->$methodName($id); + } + +} diff --git a/Test/Case/Model/Link/ValidateTest.php b/Test/Case/Model/Link/ValidateTest.php new file mode 100644 index 0000000..1388f57 --- /dev/null +++ b/Test/Case/Model/Link/ValidateTest.php @@ -0,0 +1,115 @@ +<?php +/** + * Link::validate()のテスト + * + * @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('NetCommonsValidateTest', 'NetCommons.TestSuite'); +App::uses('LinkFixture', 'Links.Test/Fixture'); +App::uses('LinkOrderFixture', 'Links.Test/Fixture'); + +/** + * Link::validate()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\Link + */ +class LinkValidateTest extends NetCommonsValidateTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.links.link', + 'plugin.links.link_order', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'Link'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'validates'; + +/** + * ValidationErrorのDataProvider + * + * ### 戻り値 + * - data 登録データ + * - field フィールド名 + * - value セットする値 + * - message エラーメッセージ + * - overwrite 上書きするデータ(省略可) + * + * @return array テストデータ + */ + public function dataProviderValidationError() { + $data['Link'] = (new LinkFixture())->records[0]; + $data['LinkOrder'] = (new LinkOrderFixture())->records[0]; + + return array( + array('data' => $data, 'field' => 'block_id', 'value' => null, + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'block_id', 'value' => 'a', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'key', 'value' => '', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'language_id', 'value' => null, + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'language_id', 'value' => 'a', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'click_count', 'value' => 'a', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'url', 'value' => '', + 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('links', 'URL'))), + array('data' => $data, 'field' => 'url', 'value' => 'a', + 'message' => sprintf(__d('net_commons', 'Unauthorized pattern for %s. Please input the data in %s format.'), __d('links', 'URL'), __d('links', 'URL'))), + array('data' => $data, 'field' => 'title', 'value' => '', + 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('links', 'Title'))), + ); + } + +/** + * LinkOrder->validates()のエラーテスト + * + * @return void + */ + public function testLinkOrderValidateError() { + $model = $this->_modelName; + + //データ生成 + $data['Link'] = (new LinkFixture())->records[0]; + $data['LinkOrder'] = (new LinkOrderFixture())->records[0]; + $data['LinkOrder'] = Hash::insert($data['LinkOrder'], 'weight', 'aaaa'); + + //テスト実施 + $this->$model->set($data); + $result = $this->$model->validates(); + $this->assertFalse($result); + + //チェック + $this->assertEquals($this->$model->LinkOrder->validationErrors['weight'][0], __d('net_commons', 'Invalid request.')); + } + +} diff --git a/Test/Case/Model/LinkBlock/CreateLinkBlockTest.php b/Test/Case/Model/LinkBlock/CreateLinkBlockTest.php new file mode 100644 index 0000000..aac50d8 --- /dev/null +++ b/Test/Case/Model/LinkBlock/CreateLinkBlockTest.php @@ -0,0 +1,79 @@ +<?php +/** + * LinkBlock::createLinkBlock()のテスト + * + * @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('NetCommonsModelTestCase', 'NetCommons.TestSuite'); + +/** + * LinkBlock::createLinkBlock()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkBlock + */ +class LinkBlockCreateLinkBlockTest extends NetCommonsModelTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkBlock'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'createLinkBlock'; + +/** + * createLinkBlock()のテスト + * + * @return void + */ + public function testCreateLinkBlock() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //テスト実施 + $result = $this->$model->$methodName(); + + //チェック + $expected = array('LinkBlock', 'BlocksLanguage', 'Block', 'LinkSetting'); + $this->assertEquals($expected, array_keys($result)); + + $pattern = '/' . __d('links', 'New Bookmark List %s', '[0-9]{14}') . '/'; + $this->assertRegExp($pattern, Hash::get($result, 'LinkBlock.name')); + } + +} diff --git a/Test/Case/Model/LinkBlock/DeleteLinkBlockTest.php b/Test/Case/Model/LinkBlock/DeleteLinkBlockTest.php new file mode 100644 index 0000000..4a32d85 --- /dev/null +++ b/Test/Case/Model/LinkBlock/DeleteLinkBlockTest.php @@ -0,0 +1,107 @@ +<?php +/** + * LinkBlock::deleteLinkBlock()のテスト + * + * @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('WorkflowDeleteTest', 'Workflow.TestSuite'); +App::uses('LinkBlockFixture', 'Links.Test/Fixture'); + +/** + * LinkBlock::deleteLinkBlock()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkBlock + */ +class LinkBlockDeleteLinkBlockTest extends WorkflowDeleteTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkBlock'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'deleteLinkBlock'; + +/** + * Delete用DataProvider + * + * ### 戻り値 + * - data: 削除データ + * - associationModels: 削除確認の関連モデル array(model => conditions) + * + * @return array テストデータ + * @see NetCommonsDeleteTest::testDelete() + */ + public function dataProviderDelete() { + $data = array( + 'LinkBlock' => array( + 'id' => '2', + 'key' => 'block_1' + ) + ); + $association = array( + 'Link' => array('block_id' => $data['LinkBlock']['id']), + 'LinkOrder' => array('block_key' => $data['LinkBlock']['key']), + ); + + $results = array(); + $results[0] = array($data, $association); + + return $results; + } + +/** + * ExceptionError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド + * + * @return array テストデータ + */ + public function dataProviderDeleteOnExceptionError() { + $data = $this->dataProviderDelete()[0][0]; + + return array( + array($data, 'Links.Link', 'deleteAll'), + array($data, 'Links.LinkOrder', 'deleteAll'), + ); + } + +} diff --git a/Test/Case/Model/LinkBlock/GetLinkBlockTest.php b/Test/Case/Model/LinkBlock/GetLinkBlockTest.php new file mode 100644 index 0000000..91a3012 --- /dev/null +++ b/Test/Case/Model/LinkBlock/GetLinkBlockTest.php @@ -0,0 +1,114 @@ +<?php +/** + * LinkBlock::getLinkBlock()のテスト + * + * @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('WorkflowGetTest', 'Workflow.TestSuite'); + +/** + * LinkBlock::getLinkBlock()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkBlock + */ +class LinkBlockGetLinkBlockTest extends WorkflowGetTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkBlock'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'getLinkBlock'; + +/** + * getLinkBlock()のテスト + * + * @return void + */ + public function testGetLinkBlock() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //テストデータ + $roomId = '2'; + $blockId = '2'; + $blockKey = 'block_1'; + Current::write('Room.id', $roomId); + Current::write('Block.id', $blockId); + Current::write('Block.key', $blockKey); + + //テスト実施 + $result = $this->$model->$methodName(); + + //チェック + $expected = array('LinkBlock', 'Block', 'BlocksLanguage', 'LinkBlocksLanguage', 'LinkSetting'); + $this->assertEquals($expected, array_keys($result)); + + $this->assertEquals($blockId, Hash::get($result, 'LinkBlock.id')); + $this->assertEquals('2', Hash::get($result, 'LinkBlock.language_id')); + $this->assertEquals($roomId, Hash::get($result, 'LinkBlock.room_id')); + $this->assertEquals($blockKey, Hash::get($result, 'LinkBlock.key')); + + $this->assertEquals($blockId, Hash::get($result, 'Block.id')); + $this->assertEquals('2', Hash::get($result, 'BlocksLanguage.language_id')); + $this->assertEquals($roomId, Hash::get($result, 'Block.room_id')); + $this->assertEquals($this->plugin, Hash::get($result, 'Block.plugin_key')); + $this->assertEquals($blockKey, Hash::get($result, 'Block.key')); + + $this->assertEquals(0, Hash::get($result, 'LinkSetting.use_workflow')); + } + +/** + * getLinkBlock()のテスト + * + * @return void + */ + public function testGetLinkBlockWOBlockId() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //テストデータ + Current::$current['Block']['id'] = '99'; + + //テスト実施 + $result = $this->$model->$methodName(); + $this->assertFalse($result); + } + +} diff --git a/Test/Case/Model/LinkBlock/SaveLinkBlockTest.php b/Test/Case/Model/LinkBlock/SaveLinkBlockTest.php new file mode 100644 index 0000000..410a6b3 --- /dev/null +++ b/Test/Case/Model/LinkBlock/SaveLinkBlockTest.php @@ -0,0 +1,263 @@ +<?php +/** + * LinkBlock::saveLinkBlock()のテスト + * + * @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('NetCommonsSaveTest', 'NetCommons.TestSuite'); +App::uses('LinkBlockFixture', 'Links.Test/Fixture'); +App::uses('BlocksLanguageFixture', 'Blocks.Test/Fixture'); + +/** + * LinkBlock::saveLinkBlock()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkBlock + */ +class LinkBlockSaveLinkBlockTest extends NetCommonsSaveTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkBlock'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'saveLinkBlock'; + +/** + * Key Alias + * + * @var array + */ + protected $_keyAlias = 'Block'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + Current::write('Plugin.key', $this->plugin); + } + +/** + * Save用DataProvider + * + * ### 戻り値 + * - data 登録データ + * + * @return array テストデータ + */ + public function dataProviderSave() { + $data['LinkBlock'] = (new LinkBlockFixture())->records[0]; + $data['LinkBlock']['language_id'] = (new BlocksLanguageFixture())->records[0]['language_id']; + $data['LinkBlock']['name'] = (new BlocksLanguageFixture())->records[0]['name']; + $data['LinkBlock']['content_count'] = '0'; + $data['LinkSetting']['use_workflow'] = '0'; + $data['Frame'] = array('id' => '6'); + $data['Block'] = array( + 'id' => $data['LinkBlock']['id'], + 'key' => $data['LinkBlock']['key'], + ); + $data['BlocksLanguage'] = array( + 'language_id' => $data['LinkBlock']['language_id'], + ); + + $results = array(); + // * 編集の登録処理 + $results[0] = array($data); + // * 新規の登録処理 + $results[1] = array($data); + $results[1] = Hash::insert($results[1], '0.LinkBlock.id', null); + $results[1] = Hash::insert($results[1], '0.LinkBlock.key', null); + $results[1] = Hash::remove($results[1], '0.LinkBlock.created_user'); + $results[1] = Hash::insert($results[1], '0.Block.id', null); + $results[1] = Hash::insert($results[1], '0.Block.key', null); + + return $results; + } + +/** + * Saveのテスト + * + * @param array $data 登録データ + * @dataProvider dataProviderSave + * @return void + */ + public function testSave($data) { + $model = $this->_modelName; + $method = $this->_methodName; + if (! $this->_keyAlias) { + $this->_keyAlias = $this->$model->alias; + } + + $created = !isset($data[$this->$model->alias]['id']); + + //チェック用データ取得 + if (! $created) { + $before = $this->$model->find('first', array( + 'recursive' => 0, + 'conditions' => array('LinkBlock.id' => $data[$this->$model->alias]['id']), + )); + } else { + $max = $this->$model->find('first', array( + 'recursive' => 0, + 'fields' => array('LinkBlock.id'), + 'order' => array('LinkBlock.id' => 'desc'), + )); + $before[$this->$model->alias] = array(); + } + + //テスト実行 + $result = $this->$model->$method($data); + $this->assertNotEmpty($result); + + //idのチェック + if (isset($data[$this->$model->alias]['id'])) { + $id = $data[$this->$model->alias]['id']; + } elseif ($max) { + $id = (string)($max[$this->$model->alias]['id'] + 1); + } else { + $id = $this->$model->getLastInsertID(); + } + + //チェック + $actual = $this->_getActual($id, $created); + $expected = $this->_getExpected($id, $data, $before, $created); + $this->assertEquals($expected, $actual); + } + +/** + * 結果データ取得 + * + * @param int $id ID + * @param bool $created 作成かどうか + * @return array + */ + protected function _getActual($id, $created) { + $model = $this->_modelName; + + //登録データ取得 + $actual = $this->$model->find('first', array( + 'recursive' => 0, + 'conditions' => array('LinkBlock.id' => $id), + )); + + if ($created) { + $actual[$this->$model->alias] = Hash::remove($actual[$this->$model->alias], 'created'); + $actual[$this->$model->alias] = Hash::remove($actual[$this->$model->alias], 'created_user'); + $actual[$this->$model->alias] = Hash::remove($actual[$this->$model->alias], 'modified'); + $actual[$this->$model->alias] = Hash::remove($actual[$this->$model->alias], 'modified_user'); + } else { + $actual[$this->$model->alias] = Hash::remove($actual[$this->$model->alias], 'modified'); + $actual[$this->$model->alias] = Hash::remove($actual[$this->$model->alias], 'modified_user'); + } + + return $actual[$this->$model->alias]; + } + +/** + * 期待値の取得 + * + * @param int $id ID + * @param array $data 登録データ + * @param array $before 登録前データ + * @param bool $created 作成かどうか + * @return array + */ + protected function _getExpected($id, $data, $before, $created) { + $model = $this->_modelName; + + if ($created && $this->$model->hasField('key')) { + $data[$this->$model->alias]['key'] = OriginalKeyBehavior::generateKey( + $this->_keyAlias, $this->$model->useDbConfig + ); + } + + $expected[$this->$model->alias] = Hash::merge( + $before[$this->$model->alias], + $data[$this->$model->alias] + ); + $expected[$this->$model->alias]['id'] = $id; + $expected[$this->$model->alias] = Hash::remove($expected[$this->$model->alias], 'modified'); + $expected[$this->$model->alias] = Hash::remove($expected[$this->$model->alias], 'modified_user'); + $expected[$this->$model->alias]['block_id'] = $id; + $expected[$this->$model->alias]['is_origin'] = true; + $expected[$this->$model->alias]['is_translation'] = false; + + return $expected[$this->$model->alias]; + } + +/** + * SaveのExceptionError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド + * + * @return array テストデータ + */ + public function dataProviderSaveOnExceptionError() { + $data = $this->dataProviderSave()[0][0]; + + return array( + array($data, 'Links.LinkBlock', 'save'), + ); + } + +/** + * SaveのValidationError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド(省略可:デフォルト validates) + * + * @return array テストデータ + */ + public function dataProviderSaveOnValidationError() { + $data = $this->dataProviderSave()[0][0]; + + return array( + array($data, 'Links.LinkBlock'), + ); + } + +} diff --git a/Test/Case/Model/LinkBlock/SaveTest.php b/Test/Case/Model/LinkBlock/SaveTest.php new file mode 100644 index 0000000..0cfa490 --- /dev/null +++ b/Test/Case/Model/LinkBlock/SaveTest.php @@ -0,0 +1,183 @@ +<?php +/** + * beforeSave()とafterSave()のテスト + * + * @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('NetCommonsSaveTest', 'NetCommons.TestSuite'); +App::uses('LinkBlockFixture', 'Links.Test/Fixture'); +App::uses('BlocksLanguageFixture', 'Blocks.Test/Fixture'); + +/** + * beforeSave()とafterSave()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkBlock + */ +class LinkBlockSaveTest extends NetCommonsSaveTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkBlock'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'save'; + +/** + * block key + * + * @var string + */ + public $blockKey = 'e1e4c8c9ccd9fc39c391da4bcd093fb2'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + Current::write('Plugin.key', $this->plugin); + Current::write('Block.key', $this->blockKey); + } + +/** + * Save用DataProvider + * + * ### 戻り値 + * - data 登録データ + * + * @return array テストデータ + */ + public function dataProviderSave() { + //データ生成 + $data['LinkBlock'] = (new LinkBlockFixture())->records[0]; + $data['LinkBlock']['language_id'] = (new BlocksLanguageFixture())->records[0]['language_id']; + $data['LinkBlock']['name'] = (new BlocksLanguageFixture())->records[0]['name']; + $data['LinkSetting']['use_workflow'] = '0'; + $data['Frame'] = array('id' => '6'); + $data['Block'] = array( + 'id' => $data['LinkBlock']['id'], + 'key' => $data['LinkBlock']['key'], + ); + $data['BlocksLanguage'] = array( + 'language_id' => $data['LinkBlock']['language_id'], + ); + + $results = array(); + // * 編集の登録処理 + $results[0] = array($data); + // * 新規の登録処理 + $results[1] = array($data); + $results[1] = Hash::insert($results[1], '0.LinkBlock.id', null); + $results[1] = Hash::insert($results[1], '0.LinkBlock.key', null); + $results[1] = Hash::remove($results[1], '0.LinkBlock.created_user'); + $results[1] = Hash::insert($results[1], '0.LinkSetting.use_workflow', '1'); + $results[1] = Hash::insert($results[1], '0.Block.id', null); + $results[1] = Hash::insert($results[1], '0.Block.key', null); + + return $results; + } + +/** + * Saveのテスト + * + * @param array $data 登録データ + * @dataProvider dataProviderSave + * @return void + */ + public function testSave($data) { + $model = $this->_modelName; + $method = $this->_methodName; + + //テスト実行 + if (! isset($data[$this->$model->alias]['id'])) { + $this->$model->useTable = false; + } + $result = $this->$model->$method($data); + if (! isset($data[$this->$model->alias]['id'])) { + $this->assertNull($result); + } else { + $this->assertNotEmpty($result); + } + + //登録データ取得 + $actual = $this->$model->LinkSetting->getLinkSetting(); + + $expected['LinkSetting'] = $data['LinkSetting']; + $this->assertEquals($expected, $actual); + } + +/** + * SaveのExceptionError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド + * + * @return array テストデータ + */ + public function dataProviderSaveOnExceptionError() { + $data = $this->dataProviderSave()[0][0]; + + return array( + array($data, 'Blocks.BlockSetting', 'saveMany'), + ); + } + +/** + * SaveのValidationError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド(省略可:デフォルト validates) + * + * @return array テストデータ + */ + public function dataProviderSaveOnValidationError() { + $data = $this->dataProviderSave()[0][0]; + + return array( + array($data, 'Links.LinkSetting'), + ); + } + +} diff --git a/Test/Case/Model/LinkBlock/ValidateTest.php b/Test/Case/Model/LinkBlock/ValidateTest.php new file mode 100644 index 0000000..cbf5663 --- /dev/null +++ b/Test/Case/Model/LinkBlock/ValidateTest.php @@ -0,0 +1,104 @@ +<?php +/** + * LinkBlock::validate()のテスト + * + * @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('NetCommonsValidateTest', 'NetCommons.TestSuite'); +App::uses('LinkBlockFixture', 'Links.Test/Fixture'); + +/** + * LinkBlock::validate()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkBlock + */ +class LinkBlockValidateTest extends NetCommonsValidateTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.links.link', + 'plugin.links.block_setting_for_link', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkBlock'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'validates'; + +/** + * ValidationErrorのDataProvider + * + * ### 戻り値 + * - data 登録データ + * - field フィールド名 + * - value セットする値 + * - message エラーメッセージ + * - overwrite 上書きするデータ(省略可) + * + * @return array テストデータ + */ + public function dataProviderValidationError() { + $data['LinkBlock'] = (new LinkBlockFixture())->records[0]; + + return array( + array('data' => $data, 'field' => 'language_id', 'value' => '', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'language_id', 'value' => 'a', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'room_id', 'value' => '', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'room_id', 'value' => 'a', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'name', 'value' => '', + 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('links', 'Link list Title'))), + ); + } + +/** + * LinkSetting->validates()のエラーテスト + * + * @return void + */ + public function testLinkSettingValidateError() { + $model = $this->_modelName; + + //データ生成 + $data['LinkBlock'] = (new LinkBlockFixture())->records[0]; + $data['LinkSetting']['use_workflow'] = 'aaaa'; + + //テスト実施 + $this->$model->set($data); + $result = $this->$model->validates(); + $this->assertFalse($result); + + //チェック + $this->assertEquals($this->$model->LinkSetting->validationErrors['use_workflow'][0], __d('net_commons', 'Invalid request.')); + } + +} diff --git a/Test/Case/Model/LinkFrameSetting/GetLinkFrameSettingTest.php b/Test/Case/Model/LinkFrameSetting/GetLinkFrameSettingTest.php new file mode 100644 index 0000000..6e4dd40 --- /dev/null +++ b/Test/Case/Model/LinkFrameSetting/GetLinkFrameSettingTest.php @@ -0,0 +1,190 @@ +<?php +/** + * LinkFrameSetting::getLinkFrameSetting()のテスト + * + * @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('NetCommonsGetTest', 'NetCommons.TestSuite'); + +/** + * LinkFrameSetting::getLinkFrameSetting()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkFrameSetting + */ +class LinkFrameSettingGetLinkFrameSettingTest extends NetCommonsGetTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkFrameSetting'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'getLinkFrameSetting'; + +/** + * getLinkFrameSetting()のテスト + * + * @return void + */ + public function testGetLinkFrameSetting() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //データ生成 + Current::$current['Frame']['key'] = 'frame_3'; + $created = false; + + //テスト実施 + $result = $this->$model->$methodName($created); + + //チェック + $this->assertEquals('6', Hash::get($result, 'LinkFrameSetting.id')); + + $this->__assertLinkFrameSetting($result['LinkFrameSetting'], array( + 'id' => Hash::get($result, 'LinkFrameSetting.id'), + 'frame_key' => Current::$current['Frame']['key'], + 'display_type' => '3', + 'open_new_tab' => true, + 'display_click_count' => true, + 'category_separator_line' => 'line_a2.gif', + 'list_style' => 'mark_a1.gif', + 'created_user' => null, + 'created' => null, + 'modified_user' => null, + 'modified' => null, + 'category_separator_line_css' => '', + 'list_style_css' => '' + )); + } + +/** + * getLinkFrameSetting()のテスト(Frame.keyがなく、作成フラグがtrueの場合) + * + * @return void + */ + public function testCreatedWOFrame() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //データ生成 + Current::$current['Frame']['key'] = 'aaaaaa'; + $created = true; + + //テスト実施 + $result = $this->$model->$methodName($created); + + //チェック + $this->__assertLinkFrameSetting($result['LinkFrameSetting'], array( + 'display_type' => '1', + 'open_new_tab' => true, + 'display_click_count' => true, + 'frame_key' => Current::$current['Frame']['key'], + 'category_separator_line' => 'default', + 'list_style' => null, + 'created_user' => null, + 'created' => null, + 'modified_user' => null, + 'modified' => null, + 'category_separator_line_css' => '', + 'list_style_css' => 'list-style-type: none;' + )); + } + +/** + * getLinkFrameSetting()のテスト(Frame.keyがなく、作成フラグがfalseの場合) + * + * @return void + */ + public function testNotCreatedWOFrame() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //データ生成 + Current::$current['Frame']['key'] = 'aaaaaa'; + $created = false; + + //テスト実施 + $result = $this->$model->$methodName($created); + + //チェック + $this->assertEmpty($result); + $this->assertInternalType('array', $result); + } + +/** + * 結果のチェック + * + * @param array $result 結果 + * @param array $expected 期待値 + * @return void + */ + private function __assertLinkFrameSetting($result, $expected) { + $this->assertEquals(array_keys($expected), array_keys($result)); + + $pathKey = 'category_separator_line'; + $this->assertEquals(Hash::get($expected, $pathKey), Hash::get($result, $pathKey)); + if (Hash::get($expected, $pathKey)) { + $pattern = '//'; + $this->assertRegExp($pattern, Hash::get($result, $pathKey . '_css')); + } else { + $this->assertEquals(null, Hash::get($result, $pathKey . '_css')); + } + + $pathKey = 'list_style'; + $this->assertEquals(Hash::get($expected, $pathKey), Hash::get($result, $pathKey)); + if (Hash::get($expected, $pathKey)) { + $pattern = '/' . preg_quote(Hash::get($expected, $pathKey), '/') . '/'; + $this->assertRegExp($pattern, Hash::get($result, $pathKey . '_css')); + } else { + $this->assertEquals('list-style-type: none;', Hash::get($result, $pathKey . '_css')); + } + + $pathKey = 'frame_key'; + $this->assertEquals(Hash::get($expected, $pathKey), Hash::get($result, $pathKey)); + + $pathKey = 'display_type'; + $this->assertEquals(Hash::get($expected, $pathKey), Hash::get($result, $pathKey)); + + $pathKey = 'open_new_tab'; + $this->assertEquals(Hash::get($expected, $pathKey), Hash::get($result, $pathKey)); + + $pathKey = 'display_click_count'; + $this->assertEquals(Hash::get($expected, $pathKey), Hash::get($result, $pathKey)); + } + +} diff --git a/Test/Case/Model/LinkFrameSetting/SaveLinkFrameSettingTest.php b/Test/Case/Model/LinkFrameSetting/SaveLinkFrameSettingTest.php new file mode 100644 index 0000000..31d2ee3 --- /dev/null +++ b/Test/Case/Model/LinkFrameSetting/SaveLinkFrameSettingTest.php @@ -0,0 +1,124 @@ +<?php +/** + * LinkFrameSetting::saveLinkFrameSetting()のテスト + * + * @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('NetCommonsSaveTest', 'NetCommons.TestSuite'); +App::uses('LinkFrameSettingFixture', 'Links.Test/Fixture'); + +/** + * LinkFrameSetting::saveLinkFrameSetting()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkFrameSetting + */ +class LinkFrameSettingSaveLinkFrameSettingTest extends NetCommonsSaveTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkFrameSetting'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'saveLinkFrameSetting'; + +/** + * Save用DataProvider + * + * ### 戻り値 + * - data 登録データ + * + * @return array テストデータ + */ + public function dataProviderSave() { + $data['LinkFrameSetting'] = Hash::merge((new LinkFrameSettingFixture())->records[0], array( + 'display_type' => '1', + 'open_new_tab' => false, + 'display_click_count' => false, + 'category_separator_line' => 'line_a3.gif', + 'list_style' => 'mark_a3.gif', + )); + + $results = array(); + // * 編集の登録処理 + $results[0] = array($data); + // * 新規の登録処理 + $results[1] = array($data); + $results[1] = Hash::insert($results[1], '0.LinkFrameSetting.id', null); + $results[1] = Hash::remove($results[1], '0.LinkFrameSetting.created_user'); + + return $results; + } + +/** + * SaveのExceptionError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド + * + * @return array テストデータ + */ + public function dataProviderSaveOnExceptionError() { + $data = $this->dataProviderSave()[0][0]; + + return array( + array($data, 'Links.LinkFrameSetting', 'save'), + ); + } + +/** + * SaveのValidationError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド(省略可:デフォルト validates) + * + * @return array テストデータ + */ + public function dataProviderSaveOnValidationError() { + $data = $this->dataProviderSave()[0][0]; + + return array( + array($data, 'Links.LinkFrameSetting'), + ); + } + +} diff --git a/Test/Case/Model/LinkFrameSetting/ValidateTest.php b/Test/Case/Model/LinkFrameSetting/ValidateTest.php new file mode 100644 index 0000000..891254a --- /dev/null +++ b/Test/Case/Model/LinkFrameSetting/ValidateTest.php @@ -0,0 +1,86 @@ +<?php +/** + * LinkFrameSetting::validate()のテスト + * + * @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('NetCommonsValidateTest', 'NetCommons.TestSuite'); +App::uses('LinkFrameSettingFixture', 'Links.Test/Fixture'); + +/** + * LinkFrameSetting::validate()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkFrameSetting + */ +class LinkFrameSettingValidateTest extends NetCommonsValidateTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.links.link_frame_setting', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkFrameSetting'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'validates'; + +/** + * ValidationErrorのDataProvider + * + * ### 戻り値 + * - data 登録データ + * - field フィールド名 + * - value セットする値 + * - message エラーメッセージ + * - overwrite 上書きするデータ(省略可) + * + * @return array テストデータ + */ + public function dataProviderValidationError() { + $data['LinkFrameSetting'] = (new LinkFrameSettingFixture())->records[0]; + + return array( + array('data' => $data, 'field' => 'frame_key', 'value' => '', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'display_type', 'value' => 'a', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'display_type', 'value' => '99', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'open_new_tab', 'value' => '2', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'display_click_count', 'value' => '2', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'category_separator_line', 'value' => 'aa', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'list_style', 'value' => 'aa', + 'message' => __d('net_commons', 'Invalid request.')), + ); + } + +} diff --git a/Test/Case/Model/LinkOrder/DeleteTest.php b/Test/Case/Model/LinkOrder/DeleteTest.php new file mode 100644 index 0000000..4ad22de --- /dev/null +++ b/Test/Case/Model/LinkOrder/DeleteTest.php @@ -0,0 +1,91 @@ +<?php +/** + * beforeDelete()とafterDelete()のテスト + * + * @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('NetCommonsModelTestCase', 'NetCommons.TestSuite'); +App::uses('LinkOrderFixture', 'Links.Test/Fixture'); + +/** + * beforeDelete()とafterDelete()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkOrder + */ +class LinkOrderDeleteTest extends NetCommonsModelTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkOrder'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'delete'; + +/** + * delete()のテスト + * + * @return void + */ + public function testDelete() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //事前チェック + $result = $this->$model->find('first', array( + 'recursive' => -1, + 'fields' => array('weight'), + 'conditions' => array('id' => '2') + )); + $this->assertEquals('2', $result[$this->$model->alias]['weight']); + + //テスト実施 + $id = (new LinkOrderFixture())->records[0]['id']; + $result = $this->$model->$methodName($id); + $this->assertTrue($result); + + //チェック + $result = $this->$model->find('first', array( + 'recursive' => -1, + 'fields' => array('weight'), + 'conditions' => array('id' => '2') + )); + $this->assertEquals('1', $result[$this->$model->alias]['weight']); + } + +} diff --git a/Test/Case/Model/LinkOrder/GetMaxWeightTest.php b/Test/Case/Model/LinkOrder/GetMaxWeightTest.php new file mode 100644 index 0000000..930c9e1 --- /dev/null +++ b/Test/Case/Model/LinkOrder/GetMaxWeightTest.php @@ -0,0 +1,99 @@ +<?php +/** + * LinkOrder::getMaxWeight()のテスト + * + * @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('NetCommonsGetTest', 'NetCommons.TestSuite'); + +/** + * LinkOrder::getMaxWeight()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkOrder + */ +class LinkOrderGetMaxWeightTest extends NetCommonsGetTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkOrder'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'getMaxWeight'; + +/** + * getMaxWeight()のテスト + * + * @return void + */ + public function testGetMaxWeight() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //データ生成 + Current::$current = Hash::insert(Current::$current, 'Block.key', 'block_1'); + $categoryKey = 'category_1'; + + //テスト実施 + $result = $this->$model->$methodName($categoryKey); + + //チェック + $this->assertEquals(4, $result); + } + +/** + * getMaxWeight()のテスト(一つも選択していないカテゴリー) + * + * @return void + */ + public function testGetMaxWeightNoDataCategory() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //データ生成 + Current::$current = Hash::insert(Current::$current, 'Block.key', 'block_1'); + $categoryKey = 'category_99'; + + //テスト実施 + $result = $this->$model->$methodName($categoryKey); + + //チェック + $this->assertEquals(0, $result); + } + +} diff --git a/Test/Case/Model/LinkOrder/SaveLinkOrdersTest.php b/Test/Case/Model/LinkOrder/SaveLinkOrdersTest.php new file mode 100644 index 0000000..6e6ef83 --- /dev/null +++ b/Test/Case/Model/LinkOrder/SaveLinkOrdersTest.php @@ -0,0 +1,152 @@ +<?php +/** + * LinkOrder::saveLinkOrders()のテスト + * + * @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('NetCommonsSaveTest', 'NetCommons.TestSuite'); +App::uses('LinkOrderFixture', 'Links.Test/Fixture'); + +/** + * LinkOrder::saveLinkOrders()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkOrder + */ +class LinkOrderSaveLinkOrdersTest extends NetCommonsSaveTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkOrder'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'saveLinkOrders'; + +/** + * Save用DataProvider + * + * ### 戻り値 + * - data 登録データ + * + * @return array テストデータ + */ + public function dataProviderSave() { + $results = array(); + $results[0][0]['LinkOrders'] = array(); + $results[0][0]['LinkOrders'][] = array('LinkOrder' => Hash::insert((new LinkOrderFixture())->records[2], 'weight', '1')); + $results[0][0]['LinkOrders'][] = array('LinkOrder' => Hash::insert((new LinkOrderFixture())->records[4], 'weight', '1')); + $results[0][0]['LinkOrders'][] = array('LinkOrder' => Hash::insert((new LinkOrderFixture())->records[3], 'weight', '2')); + $results[0][0]['LinkOrders'][] = array('LinkOrder' => Hash::insert((new LinkOrderFixture())->records[1], 'weight', '3')); + $results[0][0]['LinkOrders'][] = array('LinkOrder' => Hash::insert((new LinkOrderFixture())->records[0], 'weight', '4')); + $results[0][0]['LinkOrders'] = Hash::combine($results[0][0]['LinkOrders'], '{n}.LinkOrder.id', '{n}'); + + return $results; + } + +/** + * Saveのテスト + * + * @param array $data 登録データ + * @dataProvider dataProviderSave + * @return void + */ + public function testSave($data) { + $model = $this->_modelName; + $method = $this->_methodName; + + $fields = array_keys(Hash::get($data, 'LinkOrders.1.LinkOrder')); + $expected = $this->$model->find('all', array( + 'recursive' => -1, + 'fields' => $fields, + 'order' => array('id' => 'asc') + )); + $expected = Hash::combine($expected, '{n}.LinkOrder.id', '{n}'); + $expected = Hash::merge($expected, $data['LinkOrders']); + + //テスト実行 + $result = $this->$model->$method($data); + $this->assertNotEmpty($result); + + //チェック + $actual = $this->$model->find('all', array( + 'recursive' => -1, + 'fields' => $fields, + 'order' => array('id' => 'asc') + )); + $actual = Hash::combine($actual, '{n}.LinkOrder.id', '{n}'); + + $this->assertEquals($expected, $actual); + } + +/** + * SaveのExceptionError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド + * + * @return array テストデータ + */ + public function dataProviderSaveOnExceptionError() { + $data = $this->dataProviderSave()[0][0]; + + return array( + array($data, 'Links.LinkOrder', 'saveMany'), + ); + } + +/** + * SaveのValidationError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド(省略可:デフォルト validates) + * + * @return array テストデータ + */ + public function dataProviderSaveOnValidationError() { + $data = $this->dataProviderSave()[0][0]; + + return array( + array($data, 'Links.LinkOrder', 'validateMany'), + ); + } + +} diff --git a/Test/Case/Model/LinkOrder/SaveTest.php b/Test/Case/Model/LinkOrder/SaveTest.php new file mode 100644 index 0000000..5fe94fc --- /dev/null +++ b/Test/Case/Model/LinkOrder/SaveTest.php @@ -0,0 +1,180 @@ +<?php +/** + * beforeSave()とafterSave()のテスト + * + * @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('NetCommonsModelTestCase', 'NetCommons.TestSuite'); +App::uses('LinkOrderFixture', 'Links.Test/Fixture'); + +/** + * beforeSave()とafterSave()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkOrder + */ +class LinkOrderSaveTest extends NetCommonsModelTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkOrder'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'save'; + +/** + * テストDataの取得 + * + * @return array + */ + private function __data() { + Current::$current = Hash::insert(Current::$current, 'Block.key', 'block_1'); + + $data['LinkOrder'] = (new LinkOrderFixture())->records[0]; + $data['LinkOrder'] = Hash::remove($data['LinkOrder'], 'created'); + $data['LinkOrder'] = Hash::remove($data['LinkOrder'], 'created_user'); + $data['LinkOrder'] = Hash::remove($data['LinkOrder'], 'modified'); + $data['LinkOrder'] = Hash::remove($data['LinkOrder'], 'modified_user'); + + return $data; + } + +/** + * save()のテスト(Weightデータあり) + * + * @return void + */ + public function testSaveWithWeight() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //データ生成 + $data = $this->__data(); + + //テスト実施 + $result = $this->$model->$methodName($data); + + //チェック + $this->assertDatetime($result[$this->$model->alias]['modified']); + $result = Hash::remove($result, 'LinkOrder.modified'); + + $expected = $data; + $this->assertEquals($expected, $result); + } + +/** + * save()のテスト(Weightデータなし) + * + * @return void + */ + public function testSaveWOWeight() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //データ生成 + $data = $this->__data(); + $data = Hash::remove($data, 'LinkOrder.weight'); + + //テスト実施 + $result = $this->$model->$methodName($data); + + //チェック + $this->assertDatetime($result[$this->$model->alias]['modified']); + $result = Hash::remove($result, 'LinkOrder.modified'); + + $expected = $data; + $this->assertEquals($expected, $result); + } + +/** + * save()のテスト(カテゴリーの変更) + * + * @return void + */ + public function testSaveByCategoryNull() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //データ生成 + $data = $this->__data(); + $data = Hash::remove($data, 'LinkOrder.weight'); + $data = Hash::insert($data, 'LinkOrder.category_key', null); + + //テスト実施 + $result = $this->$model->$methodName($data); + + //チェック + $this->assertDatetime($result[$this->$model->alias]['modified']); + $result = Hash::remove($result, 'LinkOrder.modified'); + + $expected = $data; + $expected = Hash::insert($expected, 'LinkOrder.weight', 2); + $this->assertEquals($expected, $result); + } + +/** + * save()のテスト(新規データ) + * + * @return void + */ + public function testSaveByInsertData() { + $model = $this->_modelName; + $methodName = $this->_methodName; + + //データ生成 + $data = $this->__data(); + $data = Hash::remove($data, 'LinkOrder.id'); + $data = Hash::remove($data, 'LinkOrder.weight'); + $data = Hash::insert($data, 'LinkOrder.link_key', 'new_link_order'); + + //テスト実施 + $result = $this->$model->$methodName($data); + + //チェック + $this->assertDatetime($result[$this->$model->alias]['created']); + $result = Hash::remove($result, 'LinkOrder.created'); + $this->assertDatetime($result[$this->$model->alias]['modified']); + $result = Hash::remove($result, 'LinkOrder.modified'); + + $expected = $data; + $expected = Hash::insert($expected, 'LinkOrder.id', '6'); + $expected = Hash::insert($expected, 'LinkOrder.weight', 5); + $this->assertEquals($expected, $result); + } + +} diff --git a/Test/Case/Model/LinkOrder/ValidateTest.php b/Test/Case/Model/LinkOrder/ValidateTest.php new file mode 100644 index 0000000..0e32a6f --- /dev/null +++ b/Test/Case/Model/LinkOrder/ValidateTest.php @@ -0,0 +1,85 @@ +<?php +/** + * LinkOrder::validate()のテスト + * + * @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('NetCommonsValidateTest', 'NetCommons.TestSuite'); +App::uses('LinkOrderFixture', 'Links.Test/Fixture'); + +/** + * LinkOrder::validate()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkOrder + */ +class LinkOrderValidateTest extends NetCommonsValidateTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkOrder'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'validates'; + +/** + * ValidationErrorのDataProvider + * + * ### 戻り値 + * - data 登録データ + * - field フィールド名 + * - value セットする値 + * - message エラーメッセージ + * - overwrite 上書きするデータ(省略可) + * + * @return array テストデータ + */ + public function dataProviderValidationError() { + $data['LinkOrder'] = (new LinkOrderFixture())->records[0]; + + return array( + array('data' => $data, 'field' => 'block_key', 'value' => '', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'link_key', 'value' => '', + 'message' => __d('net_commons', 'Invalid request.')), + array('data' => $data, 'field' => 'weight', 'value' => 'a', + 'message' => __d('net_commons', 'Invalid request.')), + ); + } + +} diff --git a/Test/Case/Model/LinkSetting/SaveLinkSettingTest.php b/Test/Case/Model/LinkSetting/SaveLinkSettingTest.php new file mode 100644 index 0000000..023b126 --- /dev/null +++ b/Test/Case/Model/LinkSetting/SaveLinkSettingTest.php @@ -0,0 +1,157 @@ +<?php +/** + * LinkSetting::saveLinkSetting()のテスト + * + * @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('NetCommonsSaveTest', 'NetCommons.TestSuite'); + +/** + * LinkSetting::saveLinkSetting()のテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\Model\LinkSetting + */ +class LinkSettingSaveLinkSettingTest extends NetCommonsSaveTest { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + 'plugin.workflow.workflow_comment', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * Model name + * + * @var string + */ + protected $_modelName = 'LinkSetting'; + +/** + * Method name + * + * @var string + */ + protected $_methodName = 'saveLinkSetting'; + +/** + * block key + * + * @var string + */ + public $blockKey = 'block_1'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + Current::write('Plugin.key', $this->plugin); + Current::write('Block.key', $this->blockKey); + } + +/** + * Save用DataProvider + * + * ### 戻り値 + * - data 登録データ + * + * @return array テストデータ + * @see NetCommonsSaveTest::testSave(); + */ + public function dataProviderSave() { + $data['LinkSetting']['use_workflow'] = '0'; + + $results = array(); + // * 編集の登録処理 + $results[0] = array($data); + // * 新規の登録処理 + $results[1] = array($data); + $results[1] = Hash::insert($results[1], '0.LinkSetting.use_workflow', '1'); + + return $results; + } + +/** + * Saveのテスト + * + * @param array $data 登録データ + * @dataProvider dataProviderSave + * @return void + */ + public function testSave($data) { + $model = $this->_modelName; + $method = $this->_methodName; + + //テスト実行 + $result = $this->$model->$method($data); + $this->assertNotEmpty($result); + + //登録データ取得 + $actual = $this->$model->getLinkSetting(); + $expected = $data; + + $this->assertEquals($expected, $actual); + } + +/** + * SaveのExceptionError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド + * + * @return array テストデータ + */ + public function dataProviderSaveOnExceptionError() { + $data = $this->dataProviderSave()[0]; + return array( + array($data[0]['LinkSetting'], 'Blocks.BlockSetting', 'saveMany'), + ); + } + +/** + * SaveのValidationError用DataProvider + * + * ### 戻り値 + * - data 登録データ + * - mockModel Mockのモデル + * - mockMethod Mockのメソッド(省略可:デフォルト validates) + * + * @return array テストデータ + */ + public function dataProviderSaveOnValidationError() { + $data = $this->dataProviderSave()[0]; + + return array( + array($data, 'Links.LinkSetting'), + ); + } + +} diff --git a/Test/Case/Model/LinklistPartSettingTest.php b/Test/Case/Model/LinklistPartSettingTest.php deleted file mode 100644 index ebc516f..0000000 --- a/Test/Case/Model/LinklistPartSettingTest.php +++ /dev/null @@ -1,51 +0,0 @@ -<?php -/** - * LinklistPartSetting Test Case - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -App::uses('LinklistPartSetting', 'LinkLists.Model'); - -/** - * Summary for LinklistPartSetting Test Case - */ -class LinklistPartSettingTest extends CakeTestCase { - -/** - * Fixtures - * - * @var array - */ - public $fixtures = array( - 'plugin.link_lists.linklist_part_setting', - 'plugin.link_lists.linklist_block', - 'plugin.link_lists.part', - 'plugin.link_lists.language', - 'plugin.link_lists.languages_part' - ); - -/** - * setUp method - * - * @return void - */ - public function setUp() { - parent::setUp(); - $this->LinklistPartSetting = ClassRegistry::init('LinkLists.LinklistPartSetting'); - } - -/** - * tearDown method - * - * @return void - */ - public function tearDown() { - unset($this->LinklistPartSetting); - - parent::tearDown(); - } - -} diff --git a/Test/Case/Model/LinklistSettingTest.php b/Test/Case/Model/LinklistSettingTest.php deleted file mode 100644 index b85ee01..0000000 --- a/Test/Case/Model/LinklistSettingTest.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php -/** - * LinklistSetting Test Case - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -App::uses('LinklistSetting', 'LinkLists.Model'); - -/** - * Summary for LinklistSetting Test Case - */ -class LinklistSettingTest extends CakeTestCase { - -/** - * Fixtures - * - * @var array - */ - public $fixtures = array( - 'plugin.link_lists.linklist_setting', - 'plugin.link_lists.linklist_block' - ); - -/** - * setUp method - * - * @return void - */ - public function setUp() { - parent::setUp(); - $this->LinklistSetting = ClassRegistry::init('LinkLists.LinklistSetting'); - } - -/** - * tearDown method - * - * @return void - */ - public function tearDown() { - unset($this->LinklistSetting); - - parent::tearDown(); - } - -} diff --git a/Test/Case/Model/LinklistTest.php b/Test/Case/Model/LinklistTest.php deleted file mode 100644 index e5eb9a3..0000000 --- a/Test/Case/Model/LinklistTest.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php -/** - * Linklist Test Case - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -App::uses('Linklist', 'LinkLists.Model'); - -/** - * Summary for Linklist Test Case - */ -class LinklistTest extends CakeTestCase { - -/** - * Fixtures - * - * @var array - */ - public $fixtures = array( - 'plugin.link_lists.linklist', - 'plugin.link_lists.linklists_block', - 'plugin.link_lists.language', - 'plugin.link_lists.linklists_category', - 'plugin.link_lists.block', - 'plugin.link_lists.blocks_language' - ); - -/** - * setUp method - * - * @return void - */ - public function setUp() { - parent::setUp(); - $this->Linklist = ClassRegistry::init('LinkLists.Linklist'); - } - -/** - * tearDown method - * - * @return void - */ - public function tearDown() { - unset($this->Linklist); - - parent::tearDown(); - } - -} diff --git a/Test/Case/Model/LinklistsBlockTest.php b/Test/Case/Model/LinklistsBlockTest.php deleted file mode 100644 index fdbbc8e..0000000 --- a/Test/Case/Model/LinklistsBlockTest.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php -/** - * LinklistsBlock Test Case - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -App::uses('LinklistsBlock', 'LinkLists.Model'); - -/** - * Summary for LinklistsBlock Test Case - */ -class LinklistsBlockTest extends CakeTestCase { - -/** - * Fixtures - * - * @var array - */ - public $fixtures = array( - 'plugin.link_lists.linklists_block', - 'plugin.link_lists.block', - 'plugin.link_lists.language', - 'plugin.link_lists.blocks_language', - 'plugin.link_lists.linklist', - 'plugin.link_lists.linklists_category' - ); - -/** - * setUp method - * - * @return void - */ - public function setUp() { - parent::setUp(); - $this->LinklistsBlock = ClassRegistry::init('LinkLists.LinklistsBlock'); - } - -/** - * tearDown method - * - * @return void - */ - public function tearDown() { - unset($this->LinklistsBlock); - - parent::tearDown(); - } - -} diff --git a/Test/Case/Model/LinklistsCategoryTest.php b/Test/Case/Model/LinklistsCategoryTest.php deleted file mode 100644 index fbfc49e..0000000 --- a/Test/Case/Model/LinklistsCategoryTest.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php -/** - * LinklistsCategory Test Case - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -App::uses('LinklistsCategory', 'LinkLists.Model'); - -/** - * Summary for LinklistsCategory Test Case - */ -class LinklistsCategoryTest extends CakeTestCase { - -/** - * Fixtures - * - * @var array - */ - public $fixtures = array( - 'plugin.link_lists.linklists_category', - 'plugin.link_lists.linklists_block', - 'plugin.link_lists.language', - 'plugin.link_lists.linklist' - ); - -/** - * setUp method - * - * @return void - */ - public function setUp() { - parent::setUp(); - $this->LinklistsCategory = ClassRegistry::init('LinkLists.LinklistsCategory'); - } - -/** - * tearDown method - * - * @return void - */ - public function tearDown() { - unset($this->LinklistsCategory); - - parent::tearDown(); - } - -} diff --git a/Test/Case/View/Elements/LinkBlocks/DeleteFormTest.php b/Test/Case/View/Elements/LinkBlocks/DeleteFormTest.php new file mode 100644 index 0000000..af33798 --- /dev/null +++ b/Test/Case/View/Elements/LinkBlocks/DeleteFormTest.php @@ -0,0 +1,68 @@ +<?php +/** + * View/Elements/LinkBlocks/delete_formのテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * View/Elements/LinkBlocks/delete_formのテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\View\Elements\LinkBlocks\DeleteForm + */ +class LinksViewElementsLinkBlocksDeleteFormTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array(); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //テストプラグインのロード + NetCommonsCakeTestCase::loadTestPlugin($this, 'Links', 'TestLinks'); + //テストコントローラ生成 + $this->generateNc('TestLinks.TestViewElementsLinkBlocksDeleteForm'); + } + +/** + * View/Elements/LinkBlocks/delete_formのテスト + * + * @return void + */ + public function testDeleteForm() { + //テスト実行 + $this->_testGetAction('/test_links/test_view_elements_link_blocks_delete_form/delete_form', + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $pattern = '/' . preg_quote('View/Elements/LinkBlocks/delete_form', '/') . '/'; + $this->assertRegExp($pattern, $this->view); + + $this->assertInput('input', 'data[LinkBlock][id]', '1', $this->view); + $this->assertInput('input', 'data[LinkBlock][key]', 'block_key_1', $this->view); + } + +} diff --git a/Test/Case/View/Elements/LinkBlocks/EditFormTest.php b/Test/Case/View/Elements/LinkBlocks/EditFormTest.php new file mode 100644 index 0000000..715cc28 --- /dev/null +++ b/Test/Case/View/Elements/LinkBlocks/EditFormTest.php @@ -0,0 +1,85 @@ +<?php +/** + * View/Elements/LinkBlocks/edit_formのテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * View/Elements/LinkBlocks/edit_formのテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\View\Elements\LinkBlocks\EditForm + */ +class LinksViewElementsLinkBlocksEditFormTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array(); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //テストプラグインのロード + NetCommonsCakeTestCase::loadTestPlugin($this, 'Links', 'TestLinks'); + //テストコントローラ生成 + $this->generateNc('TestLinks.TestViewElementsLinkBlocksEditForm'); + } + +/** + * View/Elements/LinkBlocks/edit_formのテスト + * + * @return void + */ + public function testEditForm() { + //テスト実行 + $this->_testGetAction('/test_links/test_view_elements_link_blocks_edit_form/edit_form', + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $pattern = '/' . preg_quote('View/Elements/LinkBlocks/edit_form', '/') . '/'; + $this->assertRegExp($pattern, $this->view); + + $this->assertInput('input', 'data[LinkSetting][use_workflow]', 'block_1', $this->view); + $this->assertInput('input', 'data[LinkBlock][name]', 'Block name 1', $this->view); + $this->assertInput('input', 'data[LinkBlock][id]', '2', $this->view); + $this->assertInput('input', 'data[LinkBlock][key]', 'block_1', $this->view); + $this->assertInput('input', 'data[LinkBlock][language_id]', '2', $this->view); + + //$this->element('Blocks.form_hidden')のチェック + //⇒ここでは、呼ばれているかどうかのチェックのみ + $this->assertInput('input', 'data[Frame][id]', '6', $this->view); + $this->assertInput('input', 'data[Block][id]', '2', $this->view); + $this->assertInput('input', 'data[Block][key]', 'block_1', $this->view); + + //$this->element('Blocks.public_type')のチェック + //⇒ここでは、呼ばれているかどうかのチェックのみ + $this->assertInput('input', 'data[Block][public_type]', '0', $this->view); + + //$this->element('Categories.edit_form')のチェック + //⇒ここでは、呼ばれているかどうかのチェックのみ + $this->assertTextContains('ng-controller="Categories"', $this->view); + } + +} diff --git a/Test/Case/View/Elements/LinkFrameSettings/EditFormTest.php b/Test/Case/View/Elements/LinkFrameSettings/EditFormTest.php new file mode 100644 index 0000000..0e3a587 --- /dev/null +++ b/Test/Case/View/Elements/LinkFrameSettings/EditFormTest.php @@ -0,0 +1,78 @@ +<?php +/** + * View/Elements/LinkFrameSettings/edit_formのテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * View/Elements/LinkFrameSettings/edit_formのテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\View\Elements\LinkFrameSettings\EditForm + */ +class LinksViewElementsLinkFrameSettingsEditFormTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array(); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //テストプラグインのロード + NetCommonsCakeTestCase::loadTestPlugin($this, 'Links', 'TestLinks'); + //テストコントローラ生成 + $this->generateNc('TestLinks.TestViewElementsLinkFrameSettingsEditForm'); + } + +/** + * View/Elements/LinkFrameSettings/edit_formのテスト + * + * @return void + */ + public function testEditForm() { + //テスト実行 + $this->_testGetAction('/test_links/test_view_elements_link_frame_settings_edit_form/edit_form', + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $pattern = '/' . preg_quote('View/Elements/LinkFrameSettings/edit_form', '/') . '/'; + $this->assertRegExp($pattern, $this->view); + + $this->assertInput('input', 'data[LinkFrameSetting][id]', '6', $this->view); + $this->assertInput('input', 'data[LinkFrameSetting][frame_key]', 'frame_3', $this->view); + $this->assertInput('input', 'data[Frame][id]', '6', $this->view); + $this->assertInput('input', 'data[Frame][key]', 'frame_3', $this->view); + $this->assertInput('radio', 'data[LinkFrameSetting][display_type]', '2', $this->view); + $this->assertInput('checkbox', 'data[LinkFrameSetting][has_description]', '1', $this->view); + $this->assertInput('input', 'data[LinkFrameSetting][open_new_tab]', '0', $this->view); + $this->assertInput('input', 'data[LinkFrameSetting][open_new_tab]', '1', $this->view); + $this->assertInput('input', 'data[LinkFrameSetting][display_click_count]', '0', $this->view); + $this->assertInput('input', 'data[LinkFrameSetting][display_click_count]', '1', $this->view); + $this->assertInput('input', 'data[LinkFrameSetting][category_separator_line]', 'line_a2.gif', $this->view); + $this->assertInput('input', 'data[LinkFrameSetting][list_style]', 'mark_a1.gif', $this->view); + } + +} diff --git a/Test/Case/View/Elements/Links/DeleteFormTest.php b/Test/Case/View/Elements/Links/DeleteFormTest.php new file mode 100644 index 0000000..9f8a70e --- /dev/null +++ b/Test/Case/View/Elements/Links/DeleteFormTest.php @@ -0,0 +1,75 @@ +<?php +/** + * View/Elements/Links/delete_formのテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * View/Elements/Links/delete_formのテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\View\Elements\Links\DeleteForm + */ +class LinksViewElementsLinksDeleteFormTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array(); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //テストプラグインのロード + NetCommonsCakeTestCase::loadTestPlugin($this, 'Links', 'TestLinks'); + //テストコントローラ生成 + $this->generateNc('TestLinks.TestViewElementsLinksDeleteForm'); + } + +/** + * View/Elements/Links/delete_formのテスト + * + * @return void + */ + public function testDeleteForm() { + //テスト実行 + $this->_testGetAction('/test_links/test_view_elements_links_delete_form/delete_form', + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $pattern = '/' . preg_quote('View/Elements/Links/delete_form', '/') . '/'; + $this->assertRegExp($pattern, $this->view); + + $this->assertInput('form', null, 'links/links/delete', $this->view); + $this->assertInput('input', '_method', 'DELETE', $this->view); + $this->assertInput('input', 'data[Block][id]', '2', $this->view); + $this->assertInput('input', 'data[Block][key]', 'block_1', $this->view); + $this->assertInput('input', 'data[Frame][id]', '6', $this->view); + $this->assertInput('input', 'data[Link][id]', '2', $this->view); + $this->assertInput('input', 'data[Link][key]', 'content_key_1', $this->view); + $this->assertInput('input', 'data[LinkOrder][id]', '1', $this->view); + $this->assertInput('button', 'delete', null, $this->view); + } + +} diff --git a/Test/Case/View/Elements/Links/EditFormTest.php b/Test/Case/View/Elements/Links/EditFormTest.php new file mode 100644 index 0000000..03e6557 --- /dev/null +++ b/Test/Case/View/Elements/Links/EditFormTest.php @@ -0,0 +1,84 @@ +<?php +/** + * View/Elements/Links/edit_formのテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * View/Elements/Links/edit_formのテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\View\Elements\Links\EditForm + */ +class LinksViewElementsLinksEditFormTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //テストプラグインのロード + NetCommonsCakeTestCase::loadTestPlugin($this, 'Links', 'TestLinks'); + //テストコントローラ生成 + $this->generateNc('TestLinks.TestViewElementsLinksEditForm'); + } + +/** + * View/Elements/Links/edit_formのテスト + * + * @return void + */ + public function testEditForm() { + //テスト実行 + $this->_testGetAction('/test_links/test_view_elements_links_edit_form/edit_form/2', + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $pattern = '/' . preg_quote('View/Elements/Links/edit_form', '/') . '/'; + $this->assertRegExp($pattern, $this->view); + + $this->assertInput('input', 'data[Block][id]', '2', $this->view); + $this->assertInput('input', 'data[Block][key]', 'block_1', $this->view); + $this->assertInput('input', 'data[Frame][id]', '6', $this->view); + $this->assertInput('input', 'data[Link][id]', '2', $this->view); + $this->assertInput('input', 'data[Link][block_id]', '2', $this->view); + $this->assertInput('input', 'data[Link][key]', 'content_key_1', $this->view); + $this->assertInput('input', 'data[Link][language_id]', '2', $this->view); + $this->assertInput('input', 'data[LinkOrder][id]', '1', $this->view); + $this->assertInput('input', 'data[LinkOrder][block_key]', 'block_1', $this->view); + $this->assertInput('input', 'data[LinkOrder][link_key]', 'content_key_1', $this->view); + $this->assertInput('input', 'data[Link][url]', 'http://www.netcommons.org', $this->view); + $this->assertInput('input', 'data[Link][title]', 'Title 2" id="LinkTitle', $this->view); + $this->assertInput('textarea', 'data[Link][description]', 'Description 2', $this->view); + $this->assertInput('select', 'data[Link][category_id]', '', $this->view); + } + +} diff --git a/Test/Case/View/Elements/Links/EditLinkTest.php b/Test/Case/View/Elements/Links/EditLinkTest.php new file mode 100644 index 0000000..5cc27d6 --- /dev/null +++ b/Test/Case/View/Elements/Links/EditLinkTest.php @@ -0,0 +1,90 @@ +<?php +/** + * View/Elements/Links/edit_linkのテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * View/Elements/Links/edit_linkのテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\View\Elements\Links\EditLink + */ +class LinksViewElementsLinksEditLinkTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.links.link', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //テストプラグインのロード + NetCommonsCakeTestCase::loadTestPlugin($this, 'Links', 'TestLinks'); + //テストコントローラ生成 + $this->generateNc('TestLinks.TestViewElementsLinksEditLink'); + } + +/** + * View/Elements/Links/edit_linkのテスト + * + * @return void + */ + public function testEditLink() { + //ログイン + TestAuthGeneral::login($this); + + //テスト実行 + $this->_testGetAction('/test_links/test_view_elements_links_edit_link/edit_link/2?frame_id=6', + array('method' => 'assertNotEmpty'), null, 'view'); + + //ログアウト + TestAuthGeneral::logout($this); + + //チェック + $pattern = '/' . preg_quote('View/Elements/Links/edit_link', '/') . '/'; + $this->assertRegExp($pattern, $this->view); + $this->assertTextContains('glyphicon-edit', $this->view); + } + +/** + * View/Elements/Links/edit_linkのテスト + * + * @return void + */ + public function testEditLinkNotCanEdit() { + //テスト実行 + $this->_testGetAction('/test_links/test_view_elements_links_edit_link/edit_link/2?frame_id=6', + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $pattern = '/' . preg_quote('View/Elements/Links/edit_link', '/') . '/'; + $this->assertRegExp($pattern, $this->view); + $this->assertTextNotContains('glyphicon-edit', $this->view); + } + +} diff --git a/Test/Case/View/Elements/Links/IndexDropdownTest.php b/Test/Case/View/Elements/Links/IndexDropdownTest.php new file mode 100644 index 0000000..72cb58e --- /dev/null +++ b/Test/Case/View/Elements/Links/IndexDropdownTest.php @@ -0,0 +1,107 @@ +<?php +/** + * View/Elements/Links/index_dropdownのテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * View/Elements/Links/index_dropdownのテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\View\Elements\Links\IndexDropdown + */ +class LinksViewElementsLinksIndexDropdownTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //テストプラグインのロード + NetCommonsCakeTestCase::loadTestPlugin($this, 'Links', 'TestLinks'); + //テストコントローラ生成 + $this->generateNc('TestLinks.TestViewElementsLinksIndexDropdown'); + //ログイン + TestAuthGeneral::login($this); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + //ログアウト + TestAuthGeneral::logout($this); + parent::tearDown(); + } + +/** + * View/Elements/Links/index_dropdownのテスト + * + * @return void + */ + public function testIndexDropdown() { + //テスト実行 + $this->_testGetAction('/test_links/test_view_elements_links_index_dropdown/index_dropdown/2?frame_id=6', + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $pattern = '/' . preg_quote('View/Elements/Links/index_dropdown', '/') . '/'; + $this->assertRegExp($pattern, $this->view); + + $this->assertTextContains('<ul class="dropdown-menu" role="menu">', $this->view); + + $this->assertTextContains('Category 1', $this->view); + $this->assertTextContains('Title 2', $this->view); + $this->assertTextContains('Title 3', $this->view); + $this->assertTextContains('Title 5', $this->view); + $this->assertTextContains('Title 7', $this->view); + $this->assertTextContains('Title 8', $this->view); + + $this->assertTextNotContains('Description 2', $this->view); + $this->assertTextNotContains('Description 3', $this->view); + $this->assertTextNotContains('Description 5', $this->view); + $this->assertTextNotContains('Description 7', $this->view); + $this->assertTextNotContains('Description 8', $this->view); + + $this->assertTextContains('nc-badge-6-2', $this->view); + $this->assertTextContains('nc-badge-6-3', $this->view); + $this->assertTextContains('nc-badge-6-5', $this->view); + $this->assertTextContains('nc-badge-6-7', $this->view); + $this->assertTextContains('nc-badge-6-8', $this->view); + } + +} diff --git a/Test/Case/View/Elements/Links/IndexListOnlyTitleTest.php b/Test/Case/View/Elements/Links/IndexListOnlyTitleTest.php new file mode 100644 index 0000000..666369f --- /dev/null +++ b/Test/Case/View/Elements/Links/IndexListOnlyTitleTest.php @@ -0,0 +1,109 @@ +<?php +/** + * View/Elements/Links/index_list_only_titleのテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * View/Elements/Links/index_list_only_titleのテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\View\Elements\Links\IndexListOnlyTitle + */ +class LinksViewElementsLinksIndexListOnlyTitleTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //テストプラグインのロード + NetCommonsCakeTestCase::loadTestPlugin($this, 'Links', 'TestLinks'); + //テストコントローラ生成 + $this->generateNc('TestLinks.TestViewElementsLinksIndexListOnlyTitle'); + //ログイン + TestAuthGeneral::login($this); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + //ログアウト + TestAuthGeneral::logout($this); + parent::tearDown(); + } + +/** + * View/Elements/Links/index_list_only_titleのテスト + * + * @return void + */ + public function testIndexListOnlyTitle() { + //テスト実行 + $this->_testGetAction('/test_links/test_view_elements_links_index_list_only_title/index_list_only_title/2?frame_id=6', + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $pattern = '/' . preg_quote('View/Elements/Links/index_list_only_title', '/') . '/'; + $this->assertRegExp($pattern, $this->view); + + $this->assertTextContains('<ul class="list-group"', $this->view); + $this->assertTextContains('/links/img/line/line_a2.gif', $this->view); + $this->assertTextContains('/links/img/mark/mark_a1.gif', $this->view); + + $this->assertTextContains('Category 1', $this->view); + $this->assertTextContains('Title 2', $this->view); + $this->assertTextContains('Title 3', $this->view); + $this->assertTextContains('Title 5', $this->view); + $this->assertTextContains('Title 7', $this->view); + $this->assertTextContains('Title 8', $this->view); + + $this->assertTextNotContains('Description 2', $this->view); + $this->assertTextNotContains('Description 3', $this->view); + $this->assertTextNotContains('Description 5', $this->view); + $this->assertTextNotContains('Description 7', $this->view); + $this->assertTextNotContains('Description 8', $this->view); + + $this->assertTextContains('nc-badge-6-2', $this->view); + $this->assertTextContains('nc-badge-6-3', $this->view); + $this->assertTextContains('nc-badge-6-5', $this->view); + $this->assertTextContains('nc-badge-6-7', $this->view); + $this->assertTextContains('nc-badge-6-8', $this->view); + } + +} diff --git a/Test/Case/View/Elements/Links/IndexListWithDescriptionTest.php b/Test/Case/View/Elements/Links/IndexListWithDescriptionTest.php new file mode 100644 index 0000000..65df283 --- /dev/null +++ b/Test/Case/View/Elements/Links/IndexListWithDescriptionTest.php @@ -0,0 +1,109 @@ +<?php +/** + * View/Elements/Links/index_list_with_descriptionのテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * View/Elements/Links/index_list_with_descriptionのテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\View\Elements\Links\IndexListWithDescription + */ +class LinksViewElementsLinksIndexListWithDescriptionTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.categories.category', + 'plugin.categories.category_order', + 'plugin.categories.categories_language', + 'plugin.links.link', + 'plugin.links.link_frame_setting', + 'plugin.links.link_order', + 'plugin.links.block_setting_for_link', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //テストプラグインのロード + NetCommonsCakeTestCase::loadTestPlugin($this, 'Links', 'TestLinks'); + //テストコントローラ生成 + $this->generateNc('TestLinks.TestViewElementsLinksIndexListWithDescription'); + //ログイン + TestAuthGeneral::login($this); + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + //ログアウト + TestAuthGeneral::logout($this); + parent::tearDown(); + } + +/** + * View/Elements/Links/index_list_with_descriptionのテスト + * + * @return void + */ + public function testIndexListWithDescription() { + //テスト実行 + $this->_testGetAction('/test_links/test_view_elements_links_index_list_with_description/index_list_with_description/2?frame_id=6', + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $pattern = '/' . preg_quote('View/Elements/Links/index_list_with_description', '/') . '/'; + $this->assertRegExp($pattern, $this->view); + + $this->assertTextContains('<ul class="list-group"', $this->view); + $this->assertTextContains('/links/img/line/line_a2.gif', $this->view); + $this->assertTextContains('/links/img/mark/mark_a1.gif', $this->view); + + $this->assertTextContains('Category 1', $this->view); + $this->assertTextContains('Title 2', $this->view); + $this->assertTextContains('Title 3', $this->view); + $this->assertTextContains('Title 5', $this->view); + $this->assertTextContains('Title 7', $this->view); + $this->assertTextContains('Title 8', $this->view); + + $this->assertTextContains('Description 2', $this->view); + $this->assertTextContains('Description 3', $this->view); + $this->assertTextContains('Description 5', $this->view); + $this->assertTextContains('Description 7', $this->view); + $this->assertTextContains('Description 8', $this->view); + + $this->assertTextContains('nc-badge-6-2', $this->view); + $this->assertTextContains('nc-badge-6-3', $this->view); + $this->assertTextContains('nc-badge-6-5', $this->view); + $this->assertTextContains('nc-badge-6-7', $this->view); + $this->assertTextContains('nc-badge-6-8', $this->view); + } + +} diff --git a/Test/Case/View/Elements/Links/LinkTest.php b/Test/Case/View/Elements/Links/LinkTest.php new file mode 100644 index 0000000..084d041 --- /dev/null +++ b/Test/Case/View/Elements/Links/LinkTest.php @@ -0,0 +1,164 @@ +<?php +/** + * View/Elements/Links/linkのテスト + * + * @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('NetCommonsControllerTestCase', 'NetCommons.TestSuite'); + +/** + * View/Elements/Links/linkのテスト + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Case\View\Elements\Links\Link + */ +class LinksViewElementsLinksLinkTest extends NetCommonsControllerTestCase { + +/** + * Fixtures + * + * @var array + */ + public $fixtures = array( + 'plugin.links.link', + ); + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'links'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + //テストプラグインのロード + NetCommonsCakeTestCase::loadTestPlugin($this, 'Links', 'TestLinks'); + //テストコントローラ生成 + $this->generateNc('TestLinks.TestViewElementsLinksLink'); + } + +/** + * View/Elements/Links/linkのテスト + * [ステータス表示なし、新しいタブで表示、クリック数表示] + * + * @return void + */ + public function testLinkWOStatusWNewTabWClickCount() { + //テスト実行 + $contentKey = 'content_key_1'; + $this->_testGetAction('/test_links/test_view_elements_links_link/link/2/' . $contentKey . '?frame_id=6', + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $this->__assertView($contentKey, false, true, true); + } + +/** + * View/Elements/Links/linkのテスト + * [ステータス表示なし、新しいタブで表示、クリック数表示] + * + * @return void + */ + public function testLinkWStatusWNewTabWClickCount() { + //テスト実行 + $contentKey = 'content_key_2'; + $this->_testGetAction('/test_links/test_view_elements_links_link/link/2/' . $contentKey . '?frame_id=6', + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $this->__assertView($contentKey, true, true, true); + } + +/** + * View/Elements/Links/linkのテスト + * [ステータス表示なし、新しいタブで表示なし、クリック数表示あり] + * + * @return void + */ + public function testLinkWOStatusWONewTabWClickCount() { + //テスト実行 + $contentKey = 'content_key_1'; + $this->_testGetAction('/test_links/test_view_elements_links_link/link_without_new_tab/2/' . $contentKey . '?frame_id=6', + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $this->__assertView($contentKey, false, false, true); + } + +/** + * View/Elements/Links/linkのテスト + * [ステータス表示なし、新しいタブで表示、クリック数表示なし] + * + * @return void + */ + public function testLinkWOStatusWNewTabWOClickCount() { + //テスト実行 + $contentKey = 'content_key_1'; + $this->_testGetAction('/test_links/test_view_elements_links_link/link_without_click_count/2/' . $contentKey . '?frame_id=6', + array('method' => 'assertNotEmpty'), null, 'view'); + + //チェック + $this->__assertView($contentKey, false, true, false); + } + +/** + * view()のassert + * + * @param string $contentKey コンテンツキー + * @param bool $status ステータスを表示するか + * @param bool $openNewTab 新しいタブで開くかどうか + * @param bool $displayClickCount クリック数を表示するかどうか + * @return void + */ + private function __assertView($contentKey, $status, $openNewTab, $displayClickCount) { + $pattern = '/' . preg_quote('View/Elements/Links/link', '/') . '/'; + $this->assertRegExp($pattern, $this->view); + + $this->view = str_replace("\n", '', $this->view); + $this->view = str_replace("\t", '', $this->view); + + if ($contentKey === 'content_key_2') { + $this->assertTextContains('Title 3', $this->view); + $linkId = '3'; + } else { + $this->assertTextContains('Title 1', $this->view); + $linkId = '1'; + } + + $pattern = 'onclick="return false;" ng-click="clickLink($event, \'' . $linkId . '\', \'' . $contentKey . '\')"'; + if ($status) { + $this->assertTextNotContains($pattern, $this->view); + $this->assertTextContains(__d('net_commons', 'Approving'), $this->view); + } else { + $this->assertTextContains($pattern, $this->view); + $this->assertTextNotContains(__d('net_commons', 'Approving'), $this->view); + } + + $pattern = '<span class="badge" id="nc-badge-6-' . $linkId . '">1</span>'; + if ($displayClickCount) { + $this->assertTextContains($pattern, $this->view); + } else { + $this->assertTextNotContains($pattern, $this->view); + } + + $pattern = 'target="_blank"'; + if ($openNewTab) { + $this->assertTextContains($pattern, $this->view); + } else { + $this->assertTextNotContains($pattern, $this->view); + } + } + +} diff --git a/Test/Case/View/Helper/empty b/Test/Case/View/Helper/empty deleted file mode 100644 index e69de29..0000000 diff --git a/Test/Fixture/BlockSettingForLinkFixture.php b/Test/Fixture/BlockSettingForLinkFixture.php new file mode 100644 index 0000000..aec133c --- /dev/null +++ b/Test/Fixture/BlockSettingForLinkFixture.php @@ -0,0 +1,40 @@ +<?php +/** + * BlockSettingForLinkFixture + * + * @author Noriko Arai <arai@nii.ac.jp> + * @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp> + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('BlockSettingFixture', 'Blocks.Test/Fixture'); + +/** + * Summary for BlockSettingForLinkFixture + */ +class BlockSettingForLinkFixture extends BlockSettingFixture { + +/** + * Plugin key + * + * @var string + */ + public $pluginKey = 'links'; + +/** + * Model name + * + * @var string + */ + public $name = 'BlockSetting'; + +/** + * Full Table Name + * + * @var string + */ + public $table = 'block_settings'; + +} diff --git a/Test/Fixture/Frame4linkFixture.php b/Test/Fixture/Frame4linkFixture.php new file mode 100644 index 0000000..3c50ad1 --- /dev/null +++ b/Test/Fixture/Frame4linkFixture.php @@ -0,0 +1,73 @@ +<?php +/** + * Linksプラグイン用FrameFixture + * + * @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('FrameFixture', 'Frames.Test/Fixture'); + +/** + * Linksプラグイン用FrameFixture + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Fixture + */ +class Frame4linkFixture extends FrameFixture { + +/** + * Model name + * + * @var string + */ + public $name = 'Frame'; + +/** + * Full Table Name + * + * @var string + */ + public $table = 'frames'; + +/** + * Records + * + * @var array + */ + public $records = array( + //メイン + array( + 'id' => '6', + 'room_id' => '2', + 'box_id' => '27', + 'plugin_key' => 'test_plugin', + 'block_id' => '2', + 'key' => 'frame_3', + 'weight' => '1', + 'is_deleted' => '0', + ), + array( + 'id' => '7', + 'room_id' => '2', + 'box_id' => '27', + 'plugin_key' => 'test_plugin', + 'block_id' => '2', + 'key' => 'frame_4', + 'weight' => '1', + 'is_deleted' => '0', + ), + array( + 'id' => '8', + 'room_id' => '2', + 'box_id' => '27', + 'plugin_key' => 'test_plugin', + 'block_id' => '2', + 'key' => 'frame_5', + 'weight' => '1', + 'is_deleted' => '0', + ), + ); +} diff --git a/Test/Fixture/FramePublicLanguage4linkFixture.php b/Test/Fixture/FramePublicLanguage4linkFixture.php new file mode 100644 index 0000000..333100c --- /dev/null +++ b/Test/Fixture/FramePublicLanguage4linkFixture.php @@ -0,0 +1,58 @@ +<?php +/** + * Linksプラグイン用FrameFixture + * + * @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('FramePublicLanguageFixture', 'Frames.Test/Fixture'); + +/** + * Linksプラグイン用FrameFixture + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Fixture + */ +class FramePublicLanguage4linkFixture extends FramePublicLanguageFixture { + +/** + * Model name + * + * @var string + */ + public $name = 'FramePublicLanguage'; + +/** + * Full Table Name + * + * @var string + */ + public $table = 'frame_public_languages'; + +/** + * Records + * + * @var array + */ + public $records = array( + //メイン + array( + 'frame_id' => '6', + 'language_id' => '0', + 'is_public' => '1', + ), + array( + 'frame_id' => '7', + 'language_id' => '0', + 'is_public' => '1', + ), + array( + 'frame_id' => '8', + 'language_id' => '0', + 'is_public' => '1', + ), + ); +} diff --git a/Test/Fixture/FramesLanguage4linkFixture.php b/Test/Fixture/FramesLanguage4linkFixture.php new file mode 100644 index 0000000..854fb03 --- /dev/null +++ b/Test/Fixture/FramesLanguage4linkFixture.php @@ -0,0 +1,61 @@ +<?php +/** + * Linksプラグイン用FrameFixture + * + * @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('FramesLanguageFixture', 'Frames.Test/Fixture'); + +/** + * Linksプラグイン用FrameFixture + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Fixture + */ +class FramesLanguage4linkFixture extends FramesLanguageFixture { + +/** + * Model name + * + * @var string + */ + public $name = 'FramesLanguage'; + +/** + * Full Table Name + * + * @var string + */ + public $table = 'frames_languages'; + +/** + * Records + * + * @var array + */ + public $records = array( + //メイン + array( + 'id' => '6', + 'language_id' => '2', + 'frame_id' => '6', + 'name' => 'Test frame main', + ), + array( + 'id' => '7', + 'language_id' => '2', + 'frame_id' => '7', + 'name' => 'Test frame main', + ), + array( + 'id' => '8', + 'language_id' => '2', + 'frame_id' => '8', + 'name' => 'Test frame main', + ), + ); +} diff --git a/Test/Fixture/LinkBlockFixture.php b/Test/Fixture/LinkBlockFixture.php new file mode 100644 index 0000000..07b4410 --- /dev/null +++ b/Test/Fixture/LinkBlockFixture.php @@ -0,0 +1,36 @@ +<?php +/** + * LinkBlockFixture + * + * @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('BlockFixture', 'Blocks.Test/Fixture'); + +/** + * LinkBlockFixture + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Fixture + */ +class LinkBlockFixture extends BlockFixture { + +/** + * Model name + * + * @var string + */ + public $name = 'Block'; + +/** + * Full Table Name + * + * @var string + */ + public $table = 'blocks'; + +} diff --git a/Test/Fixture/LinkFixture.php b/Test/Fixture/LinkFixture.php new file mode 100644 index 0000000..10bfc55 --- /dev/null +++ b/Test/Fixture/LinkFixture.php @@ -0,0 +1,164 @@ +<?php +/** + * Link Fixture + * + * @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 + */ + +/** + * Link Fixture + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Fixture + */ +class LinkFixture extends CakeTestFixture { + +/** + * Records + * + * @var array + */ + public $records = array( + // * ルーム管理者が書いたコンテンツ&一度公開して、下書き中 + array( + 'id' => '1', + 'block_id' => '2', + 'key' => 'content_key_1', + 'language_id' => '2', + 'category_id' => '1', + 'status' => '1', + 'is_active' => true, + 'is_latest' => false, + 'url' => 'http://www.netcommons.org', + 'title' => 'Title 1', + 'description' => 'Description 1', + 'click_count' => '1', + 'created_user' => '1' + ), + array( + 'id' => '2', + 'block_id' => '2', + 'key' => 'content_key_1', + 'language_id' => '2', + 'category_id' => '1', + 'status' => '3', + 'is_active' => false, + 'is_latest' => true, + 'url' => 'http://www.netcommons.org', + 'title' => 'Title 2', + 'description' => 'Description 2', + 'click_count' => '1', + 'created_user' => '1' + ), + // * 一般が書いたコンテンツ&一度も公開していない(承認待ち) + array( + 'id' => '3', + 'block_id' => '2', + 'key' => 'content_key_2', + 'language_id' => '2', + 'category_id' => '1', + 'status' => '2', + 'is_active' => false, + 'is_latest' => true, + 'url' => 'http://www.netcommons.org', + 'title' => 'Title 3', + 'description' => 'Description 3', + 'click_count' => '1', + 'created_user' => '4' + ), + // * 一般が書いたコンテンツ&公開して、一時保存 + array( + 'id' => '4', + 'block_id' => '2', + 'key' => 'content_key_3', + 'language_id' => '2', + 'category_id' => null, + 'status' => '1', + 'is_active' => true, + 'is_latest' => false, + 'url' => 'http://www.netcommons.org', + 'title' => 'Title 4', + 'description' => 'Description 4', + 'click_count' => '1', + 'created_user' => '4' + ), + array( + 'id' => '5', + 'block_id' => '2', + 'key' => 'content_key_3', + 'language_id' => '2', + 'category_id' => null, + 'status' => '3', + 'is_active' => false, + 'is_latest' => true, + 'url' => 'http://www.netcommons.org', + 'title' => 'Title 5', + 'description' => 'Description 5', + 'click_count' => '1', + 'created_user' => '4' + ), + // * 編集者が書いたコンテンツ&一度公開して、差し戻し + array( + 'id' => '6', + 'block_id' => '2', + 'key' => 'content_key_4', + 'language_id' => '2', + 'category_id' => '1', + 'status' => '1', + 'is_active' => true, + 'is_latest' => false, + 'url' => 'http://www.netcommons.org', + 'title' => 'Title 6', + 'description' => 'Description 6', + 'click_count' => '1', + 'created_user' => '3' + ), + array( + 'id' => '7', + 'block_id' => '2', + 'key' => 'content_key_4', + 'language_id' => '2', + 'category_id' => '1', + 'status' => '4', + 'is_active' => false, + 'is_latest' => true, + 'url' => 'http://www.netcommons.org', + 'title' => 'Title 7', + 'description' => 'Description 7', + 'click_count' => '1', + 'created_user' => '3' + ), + // * 編集長が書いたコンテンツ&一度も公開していない(下書き中) + array( + 'id' => '8', + 'block_id' => '2', + 'key' => 'content_key_5', + 'language_id' => '2', + 'category_id' => '1', + 'status' => '3', + 'is_active' => false, + 'is_latest' => true, + 'url' => 'http://www.netcommons.org', + 'title' => 'Title 8', + 'description' => 'Description 8', + 'click_count' => '1', + 'created_user' => '2' + ), + ); + +/** + * Initialize the fixture. + * + * @return void + */ + public function init() { + require_once App::pluginPath('Links') . 'Config' . DS . 'Schema' . DS . 'schema.php'; + $this->fields = (new LinksSchema())->tables[Inflector::tableize($this->name)]; + parent::init(); + } + +} diff --git a/Test/Fixture/LinkFrameSettingFixture.php b/Test/Fixture/LinkFrameSettingFixture.php new file mode 100644 index 0000000..13e1f64 --- /dev/null +++ b/Test/Fixture/LinkFrameSettingFixture.php @@ -0,0 +1,66 @@ +<?php +/** + * LinkFrameSetting Fixture + * + * @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 + */ + +/** + * LinkFrameSetting Fixture + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Fixture + */ +class LinkFrameSettingFixture extends CakeTestFixture { + +/** + * Records + * + * @var array + */ + public $records = array( + array( + 'id' => '6', + 'frame_key' => 'frame_3', + 'display_type' => '3', + 'open_new_tab' => true, + 'display_click_count' => true, + 'category_separator_line' => 'line_a2.gif', + 'list_style' => 'mark_a1.gif', + ), + array( + 'id' => '8', + 'frame_key' => 'frame_4', + 'display_type' => '2', + 'open_new_tab' => true, + 'display_click_count' => true, + 'category_separator_line' => 'line_a2.gif', + 'list_style' => 'mark_a1.gif', + ), + array( + 'id' => '9', + 'frame_key' => 'frame_5', + 'display_type' => '1', + 'open_new_tab' => true, + 'display_click_count' => true, + 'category_separator_line' => 'line_a2.gif', + 'list_style' => 'mark_a1.gif', + ), + ); + +/** + * Initialize the fixture. + * + * @return void + */ + public function init() { + require_once App::pluginPath('Links') . 'Config' . DS . 'Schema' . DS . 'schema.php'; + $this->fields = (new LinksSchema())->tables[Inflector::tableize($this->name)]; + parent::init(); + } + +} diff --git a/Test/Fixture/LinkOrderFixture.php b/Test/Fixture/LinkOrderFixture.php new file mode 100644 index 0000000..ef3cb92 --- /dev/null +++ b/Test/Fixture/LinkOrderFixture.php @@ -0,0 +1,74 @@ +<?php +/** + * LinkOrder Fixture + * + * @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 + */ + +/** + * LinkOrder Fixture + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\Fixture + */ +class LinkOrderFixture extends CakeTestFixture { + +/** + * Records + * + * @var array + */ + public $records = array( + array( + 'id' => '1', + 'block_key' => 'block_1', + 'category_key' => 'category_1', + 'link_key' => 'content_key_1', + 'weight' => '1', + ), + array( + 'id' => '2', + 'block_key' => 'block_1', + 'category_key' => 'category_1', + 'link_key' => 'content_key_2', + 'weight' => '2', + ), + array( + 'id' => '3', + 'block_key' => 'block_1', + 'category_key' => null, + 'link_key' => 'content_key_3', + 'weight' => '1', + ), + array( + 'id' => '4', + 'block_key' => 'block_1', + 'category_key' => 'category_1', + 'link_key' => 'content_key_4', + 'weight' => '3', + ), + array( + 'id' => '5', + 'block_key' => 'block_1', + 'category_key' => 'category_1', + 'link_key' => 'content_key_5', + 'weight' => '4', + ), + ); + +/** + * Initialize the fixture. + * + * @return void + */ + public function init() { + require_once App::pluginPath('Links') . 'Config' . DS . 'Schema' . DS . 'schema.php'; + $this->fields = (new LinksSchema())->tables[Inflector::tableize($this->name)]; + parent::init(); + } + +} diff --git a/Test/Fixture/LinklistFixture.php b/Test/Fixture/LinklistFixture.php deleted file mode 100644 index d400499..0000000 --- a/Test/Fixture/LinklistFixture.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php -/** - * LinklistFixture - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -/** - * Summary for LinklistFixture - */ -class LinklistFixture extends CakeTestFixture { - -/** - * Fields - * - * @var array - */ - public $fields = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), - 'linklists_block_id' => array('type' => 'integer', 'null' => false, 'default' => null), - 'status' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 3), - 'language_id' => array('type' => 'integer', 'null' => false, 'default' => '2'), - 'is_auto_translated' => array('type' => 'boolean', 'null' => false, 'default' => '0'), - 'translation_engine' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'linklists_category_id' => array('type' => 'integer', 'null' => true, 'default' => null), - 'title' => array('type' => 'string', 'null' => true, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'url' => array('type' => 'string', 'null' => false, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'description' => 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, - 'linklists_block_id' => 1, - 'status' => 1, - 'language_id' => 1, - 'is_auto_translated' => 1, - 'translation_engine' => 'Lorem ipsum dolor sit amet', - 'linklists_category_id' => 1, - 'title' => 'Lorem ipsum dolor sit amet', - 'url' => 'Lorem ipsum dolor sit amet', - 'description' => '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-08-30 00:52:54', - 'modified_user' => 1, - 'modified' => '2014-08-30 00:52:54' - ), - ); - -} diff --git a/Test/Fixture/LinklistPartSettingFixture.php b/Test/Fixture/LinklistPartSettingFixture.php deleted file mode 100644 index 4623518..0000000 --- a/Test/Fixture/LinklistPartSettingFixture.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php -/** - * LinklistPartSettingFixture - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -/** - * Summary for LinklistPartSettingFixture - */ -class LinklistPartSettingFixture extends CakeTestFixture { - -/** - * Fields - * - * @var array - */ - public $fields = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), - 'linklist_block_id' => array('type' => 'integer', 'null' => false, 'default' => null), - 'part_id' => array('type' => 'integer', 'null' => false, 'default' => '0'), - 'readable_content' => array('type' => 'boolean', 'null' => false, 'default' => '0'), - 'editable_content' => array('type' => 'boolean', 'null' => false, 'default' => '0'), - 'creatable_content' => array('type' => 'boolean', 'null' => false, 'default' => '0'), - 'publishable_content' => array('type' => 'boolean', 'null' => false, 'default' => '0'), - '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, - 'linklist_block_id' => 1, - 'part_id' => 1, - 'readable_content' => 1, - 'editable_content' => 1, - 'creatable_content' => 1, - 'publishable_content' => 1, - 'created_user' => 1, - 'created' => '2014-08-30 00:55:01', - 'modified_user' => 1, - 'modified' => '2014-08-30 00:55:01' - ), - ); - -} diff --git a/Test/Fixture/LinklistSettingFixture.php b/Test/Fixture/LinklistSettingFixture.php deleted file mode 100644 index 8bf60c0..0000000 --- a/Test/Fixture/LinklistSettingFixture.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php -/** - * LinklistSettingFixture - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -/** - * Summary for LinklistSettingFixture - */ -class LinklistSettingFixture extends CakeTestFixture { - -/** - * Fields - * - * @var array - */ - public $fields = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), - 'linklist_block_id' => array('type' => 'integer', 'null' => false, 'default' => null), - '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, - 'linklist_block_id' => 1, - 'created_user' => 1, - 'created' => '2014-08-30 00:55:24', - 'modified_user' => 1, - 'modified' => '2014-08-30 00:55:24' - ), - ); - -} diff --git a/Test/Fixture/LinklistsBlockFixture.php b/Test/Fixture/LinklistsBlockFixture.php deleted file mode 100644 index 0b741b6..0000000 --- a/Test/Fixture/LinklistsBlockFixture.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php -/** - * LinklistsBlockFixture - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -/** - * Summary for LinklistsBlockFixture - */ -class LinklistsBlockFixture extends CakeTestFixture { - -/** - * Fields - * - * @var array - */ - public $fields = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), - 'block_id' => array('type' => 'integer', 'null' => false, 'default' => null), - '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, - 'block_id' => 1, - 'created_user' => 1, - 'created' => '2014-08-30 00:54:39', - 'modified_user' => 1, - 'modified' => '2014-08-30 00:54:39' - ), - ); - -} diff --git a/Test/Fixture/LinklistsCategoryFixture.php b/Test/Fixture/LinklistsCategoryFixture.php deleted file mode 100644 index 27d5a14..0000000 --- a/Test/Fixture/LinklistsCategoryFixture.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php -/** - * LinklistsCategoryFixture - * -* @author Jun Nishikawa <topaz2@m0n0m0n0.com> -* @link http://www.netcommons.org NetCommons Project -* @license http://www.netcommons.org/license.txt NetCommons License - */ - -/** - * Summary for LinklistsCategoryFixture - */ -class LinklistsCategoryFixture extends CakeTestFixture { - -/** - * Fields - * - * @var array - */ - public $fields = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), - 'linklists_block_id' => array('type' => 'integer', 'null' => false, 'default' => null), - 'status' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 3), - 'language_id' => array('type' => 'integer', 'null' => false, 'default' => '2'), - 'is_auto_translated' => array('type' => 'boolean', 'null' => false, 'default' => '0'), - 'translation_engine' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'title' => array('type' => 'string', '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, - 'linklists_block_id' => 1, - 'status' => 1, - 'language_id' => 1, - 'is_auto_translated' => 1, - 'translation_engine' => 'Lorem ipsum dolor sit amet', - 'title' => 'Lorem ipsum dolor sit amet', - 'created_user' => 1, - 'created' => '2014-08-30 00:53:41', - 'modified_user' => 1, - 'modified' => '2014-08-30 00:53:41' - ), - ); - -} diff --git a/Test/Fixture/empty b/Test/Fixture/empty deleted file mode 100644 index e69de29..0000000 diff --git a/Test/test_app/Plugin/TestLinks/Controller/TestControllerLinksControllerGetController.php b/Test/test_app/Plugin/TestLinks/Controller/TestControllerLinksControllerGetController.php new file mode 100644 index 0000000..5439e01 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/Controller/TestControllerLinksControllerGetController.php @@ -0,0 +1,33 @@ +<?php +/** + * LinksController::get()のテスト用Controller + * + * @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('LinksController', 'Links.Controller'); + +/** + * LinksController::get()のテスト用Controller + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\test_app\Plugin\Links\Controller + */ +class TestControllerLinksControllerGetController extends LinksController { + +/** + * delete_form + * + * @return void + */ + public function get() { + $this->autoRender = true; + App::uses('HttpSocket', 'TestLinks.Network'); + parent::get(); + } + +} diff --git a/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinkBlocksDeleteFormController.php b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinkBlocksDeleteFormController.php new file mode 100644 index 0000000..4a40294 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinkBlocksDeleteFormController.php @@ -0,0 +1,42 @@ +<?php +/** + * View/Elements/LinkBlocks/delete_formテスト用Controller + * + * @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('AppController', 'Controller'); + +/** + * View/Elements/LinkBlocks/delete_formテスト用Controller + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\test_app\Plugin\Links\Controller + */ +class TestViewElementsLinkBlocksDeleteFormController extends AppController { + +/** + * delete_form + * + * @return void + */ + public function delete_form() { + $this->autoRender = true; + + $this->request->data = array( + 'Block' => array( + 'id' => '1', + 'key' => 'block_key_1', + ), + 'LinkBlock' => array( + 'id' => '1', + 'key' => 'block_key_1', + ), + ); + } + +} diff --git a/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinkBlocksEditFormController.php b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinkBlocksEditFormController.php new file mode 100644 index 0000000..856e09e --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinkBlocksEditFormController.php @@ -0,0 +1,73 @@ +<?php +/** + * View/Elements/LinkBlocks/edit_formテスト用Controller + * + * @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('AppController', 'Controller'); + +/** + * View/Elements/LinkBlocks/edit_formテスト用Controller + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\test_app\Plugin\TestLinks\Controller + */ +class TestViewElementsLinkBlocksEditFormController extends AppController { + +/** + * edit_form + * + * @return void + */ + public function edit_form() { + $this->autoRender = true; + + $this->request->data = array( + 'LinkBlock' => array( + 'id' => '2', + 'language_id' => '2', + 'room_id' => '2', + 'plugin_key' => 'links', + 'key' => 'block_1', + 'name' => 'Block name 1', + 'public_type' => '1', + 'publish_start' => null, + 'publish_end' => null, + ), + 'Block' => array( + 'id' => '2', + 'language_id' => '2', + 'room_id' => '2', + 'plugin_key' => 'links', + 'key' => 'block_1', + 'name' => 'Block name 1', + 'public_type' => '1', + 'publish_start' => null, + 'publish_end' => null, + ), + 'LinkSetting' => array( + 'id' => '1', + 'block_key' => 'block_1', + 'use_workflow' => '1', + ), + 'Frame' => array( + 'id' => '6', + 'language_id' => '2', + 'room_id' => '2', + 'box_id' => '3', + 'plugin_key' => 'links', + 'block_id' => '2', + 'key' => 'frame_3', + 'name' => 'Test frame main', + 'weight' => '1', + 'is_deleted' => '0', + ) + ); + } + +} diff --git a/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinkFrameSettingsEditFormController.php b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinkFrameSettingsEditFormController.php new file mode 100644 index 0000000..1eaa526 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinkFrameSettingsEditFormController.php @@ -0,0 +1,57 @@ +<?php +/** + * View/Elements/LinkFrameSettings/edit_formテスト用Controller + * + * @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('AppController', 'Controller'); + +/** + * View/Elements/LinkFrameSettings/edit_formテスト用Controller + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\test_app\Plugin\TestLinks\Controller + */ +class TestViewElementsLinkFrameSettingsEditFormController extends AppController { + +/** + * edit_form + * + * @return void + */ + public function edit_form() { + $this->autoRender = true; + + $this->request->data = array( + 'LinkFrameSetting' => array( + 'id' => '6', + 'frame_key' => 'frame_3', + 'display_type' => '3', + 'open_new_tab' => true, + 'display_click_count' => true, + 'category_separator_line' => 'line_a2.gif', + 'list_style' => 'mark_a1.gif', + 'category_separator_line_css' => 'background-image: url(/links/img/line/line_a2.gif); border-image: url(/links/img/line/line_a2.gif); height: 5px;', + 'list_style_css' => 'list-style-type: none; list-style-image: url(/links/img/mark/mark_a1.gif); ' + ), + 'Frame' => array( + 'id' => '6', + 'language_id' => '2', + 'room_id' => '2', + 'box_id' => '3', + 'plugin_key' => 'links', + 'block_id' => '2', + 'key' => 'frame_3', + 'name' => 'Test frame main', + 'weight' => '1', + 'is_deleted' => '0', + ) + ); + } + +} diff --git a/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksDeleteFormController.php b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksDeleteFormController.php new file mode 100644 index 0000000..c29a5fb --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksDeleteFormController.php @@ -0,0 +1,38 @@ +<?php +/** + * View/Elements/Links/delete_formテスト用Controller + * + * @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('AppController', 'Controller'); + +/** + * View/Elements/Links/delete_formテスト用Controller + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\test_app\Plugin\TestLinks\Controller + */ +class TestViewElementsLinksDeleteFormController extends AppController { + +/** + * delete_form + * + * @return void + */ + public function delete_form() { + $this->autoRender = true; + $this->request->data['Link'] = array('id' => '2', 'key' => 'content_key_1'); + $this->request->data['LinkOrder'] = array('id' => '1'); + $this->request->data['Block'] = array('id' => '2', 'key' => 'block_1'); + $this->request->data['Frame'] = array('id' => '6'); + + $this->request->params['plugin'] = 'links'; + $this->request->params['controller'] = 'links'; + } + +} diff --git a/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksEditFormController.php b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksEditFormController.php new file mode 100644 index 0000000..c31c1a8 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksEditFormController.php @@ -0,0 +1,72 @@ +<?php +/** + * View/Elements/Links/edit_formテスト用Controller + * + * @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('AppController', 'Controller'); +App::uses('LinkFixture', 'Links.Test/Fixture'); +App::uses('LinkOrderFixture', 'Links.Test/Fixture'); +App::uses('CategoryFixture', 'Categories.Test/Fixture'); +App::uses('CategoryOrderFixture', 'Categories.Test/Fixture'); + +/** + * View/Elements/Links/edit_formテスト用Controller + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\test_app\Plugin\TestLinks\Controller + */ +class TestViewElementsLinksEditFormController extends AppController { + +/** + * use component + * + * @var array + */ + public $components = array( + 'Categories.Categories', + ); + +/** + * edit_form + * + * @return void + */ + public function edit_form() { + $this->autoRender = true; + + $this->request->data['Link'] = (new LinkFixture())->records[1]; + $this->request->data['LinkOrder'] = (new LinkOrderFixture())->records[0]; + $this->request->data['Category'] = (new CategoryFixture())->records[0]; + $this->request->data['CategoryOrder'] = (new CategoryOrderFixture())->records[0]; + $this->request->data['Block'] = array( + 'id' => '2', + 'language_id' => '2', + 'room_id' => '2', + 'plugin_key' => 'links', + 'key' => 'block_1', + 'name' => 'Block name 1', + 'public_type' => '1', + 'publish_start' => null, + 'publish_end' => null, + ); + $this->request->data['Frame'] = array( + 'id' => '6', + 'language_id' => '2', + 'room_id' => '2', + 'box_id' => '3', + 'plugin_key' => 'links', + 'block_id' => '2', + 'key' => 'frame_3', + 'name' => 'Test frame main', + 'weight' => '1', + 'is_deleted' => '0', + ); + } + +} diff --git a/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksEditLinkController.php b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksEditLinkController.php new file mode 100644 index 0000000..5bf7260 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksEditLinkController.php @@ -0,0 +1,43 @@ +<?php +/** + * View/Elements/Links/edit_linkテスト用Controller + * + * @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('AppController', 'Controller'); +App::uses('LinkFixture', 'Links.Test/Fixture'); + +/** + * View/Elements/Links/edit_linkテスト用Controller + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\test_app\Plugin\TestLinks\Controller + */ +class TestViewElementsLinksEditLinkController extends AppController { + +/** + * use helpers + * + * @var array + */ + public $helpers = array( + 'Workflow.Workflow', + ); + +/** + * edit_link + * + * @return void + */ + public function edit_link() { + $this->autoRender = true; + $link['Link'] = (new LinkFixture())->records[1]; + $this->set('link', $link); + } + +} diff --git a/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksIndexDropdownController.php b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksIndexDropdownController.php new file mode 100644 index 0000000..a7bf471 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksIndexDropdownController.php @@ -0,0 +1,32 @@ +<?php +/** + * View/Elements/Links/index_dropdownテスト用Controller + * + * @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('LinksController', 'Links.Controller'); + +/** + * View/Elements/Links/index_dropdownテスト用Controller + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\test_app\Plugin\TestLinks\Controller + */ +class TestViewElementsLinksIndexDropdownController extends LinksController { + +/** + * index_dropdown + * + * @return void + */ + public function index_dropdown() { + $this->autoRender = true; + parent::index(); + } + +} diff --git a/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksIndexListOnlyTitleController.php b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksIndexListOnlyTitleController.php new file mode 100644 index 0000000..1f4d246 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksIndexListOnlyTitleController.php @@ -0,0 +1,32 @@ +<?php +/** + * View/Elements/Links/index_list_only_titleテスト用Controller + * + * @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('LinksController', 'Links.Controller'); + +/** + * View/Elements/Links/index_list_only_titleテスト用Controller + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\test_app\Plugin\TestLinks\Controller + */ +class TestViewElementsLinksIndexListOnlyTitleController extends LinksController { + +/** + * index_list_only_title + * + * @return void + */ + public function index_list_only_title() { + $this->autoRender = true; + parent::index(); + } + +} diff --git a/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksIndexListWithDescriptionController.php b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksIndexListWithDescriptionController.php new file mode 100644 index 0000000..a509b59 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksIndexListWithDescriptionController.php @@ -0,0 +1,32 @@ +<?php +/** + * View/Elements/Links/index_list_with_descriptionテスト用Controller + * + * @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('LinksController', 'Links.Controller'); + +/** + * View/Elements/Links/index_list_with_descriptionテスト用Controller + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\test_app\Plugin\TestLinks\Controller + */ +class TestViewElementsLinksIndexListWithDescriptionController extends LinksController { + +/** + * index_list_with_description + * + * @return void + */ + public function index_list_with_description() { + $this->autoRender = true; + parent::index(); + } + +} diff --git a/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksLinkController.php b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksLinkController.php new file mode 100644 index 0000000..8c13985 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/Controller/TestViewElementsLinksLinkController.php @@ -0,0 +1,70 @@ +<?php +/** + * View/Elements/Links/linkテスト用Controller + * + * @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('AppController', 'Controller'); +App::uses('LinkFixture', 'Links.Test/Fixture'); +App::uses('LinkFrameSettingFixture', 'Links.Test/Fixture'); + +/** + * View/Elements/Links/linkテスト用Controller + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\test_app\Plugin\TestLinks\Controller + */ +class TestViewElementsLinksLinkController extends AppController { + +/** + * use helpers + * + * @var array + */ + public $helpers = array( + 'Workflow.Workflow', + ); + +/** + * link + * + * @return void + */ + public function link() { + $this->autoRender = true; + $this->view = 'link'; + if ($this->params['key'] === 'content_key_2') { + $link['Link'] = (new LinkFixture())->records[2]; + } else { + $link['Link'] = (new LinkFixture())->records[0]; + } + $this->set('link', $link); + $this->set('linkFrameSetting', (new LinkFrameSettingFixture())->records[0]); + } + +/** + * link_without_new_tab + * + * @return void + */ + public function link_without_new_tab() { + $this->link(); + $this->viewVars['linkFrameSetting']['open_new_tab'] = false; + } + +/** + * link_without_click_count + * + * @return void + */ + public function link_without_click_count() { + $this->link(); + $this->viewVars['linkFrameSetting']['display_click_count'] = false; + } + +} diff --git a/Test/test_app/Plugin/TestLinks/Network/HttpSocket.php b/Test/test_app/Plugin/TestLinks/Network/HttpSocket.php new file mode 100644 index 0000000..916cba8 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/Network/HttpSocket.php @@ -0,0 +1,89 @@ +<?php +/** + * LinksController::get()のテスト用Controller + * + * @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 + */ + +/** + * LinksController::get()のテスト用ダミーResponse + * + * @author Shohei Nakajima <nakajimashouhei@gmail.com> + * @package NetCommons\Links\Test\test_app\Plugin\Links\Controller + */ +class TestResponse { + +/** + * URL + * + * @var string + */ + public $url = ''; + +/** + * レスポンスボディ + * + * @var string + */ + public $body = ''; + +/** + * Constructor. + * + * @param string $url URL + * @return void + */ + public function __construct($url) { + $this->url = $url; + $this->body = '<head> + <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> + <meta http-equiv="content-language" content="ja" /> + <meta name="robots" content="index,follow" /> + <meta name="description" content="LinksController::get() test description" /> + <title>LinksController::get() test title + '; + } + +/** + * OKかどうか + * + * @return bool + */ + public function isOk() { + return ($this->url === 'success'); + } + +} + +/** + * LinksController::get()のテスト用ダミーHttpSocket + * + * @author Shohei Nakajima + * @package NetCommons\Links\Test\test_app\Plugin\Links\Controller + */ +class HttpSocket { + +/** + * Constructor. + * + * @param array $options オプション + * @return void + */ + public function __construct($options = array()) { + } + +/** + * getメソッド + * + * @param string $url URL + * @return void + */ + public function get($url) { + return new TestResponse($url); + } + +} diff --git a/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinkBlocksDeleteForm/delete_form.ctp b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinkBlocksDeleteForm/delete_form.ctp new file mode 100644 index 0000000..1389669 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinkBlocksDeleteForm/delete_form.ctp @@ -0,0 +1,15 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + +View/Elements/LinkBlocks/delete_form + +element('Links.LinkBlocks/delete_form'); diff --git a/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinkBlocksEditForm/edit_form.ctp b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinkBlocksEditForm/edit_form.ctp new file mode 100644 index 0000000..bfe75e1 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinkBlocksEditForm/edit_form.ctp @@ -0,0 +1,16 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +?> + +View/Elements/LinkBlocks/edit_form + +element('Links.LinkBlocks/edit_form'); diff --git a/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinkFrameSettingsEditForm/edit_form.ctp b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinkFrameSettingsEditForm/edit_form.ctp new file mode 100644 index 0000000..95f08bc --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinkFrameSettingsEditForm/edit_form.ctp @@ -0,0 +1,16 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +?> + +View/Elements/LinkFrameSettings/edit_form + +element('Links.LinkFrameSettings/edit_form'); diff --git a/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksDeleteForm/delete_form.ctp b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksDeleteForm/delete_form.ctp new file mode 100644 index 0000000..9a81999 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksDeleteForm/delete_form.ctp @@ -0,0 +1,16 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +?> + +View/Elements/Links/delete_form + +element('Links.Links/delete_form'); diff --git a/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksEditForm/edit_form.ctp b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksEditForm/edit_form.ctp new file mode 100644 index 0000000..4ee160b --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksEditForm/edit_form.ctp @@ -0,0 +1,16 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +?> + +View/Elements/Links/edit_form + +element('Links.Links/edit_form'); diff --git a/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksEditLink/edit_link.ctp b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksEditLink/edit_link.ctp new file mode 100644 index 0000000..273e1a9 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksEditLink/edit_link.ctp @@ -0,0 +1,16 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +?> + +View/Elements/Links/edit_link + +element('Links.Links/edit_link'); diff --git a/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksIndexDropdown/index_dropdown.ctp b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksIndexDropdown/index_dropdown.ctp new file mode 100644 index 0000000..715774f --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksIndexDropdown/index_dropdown.ctp @@ -0,0 +1,16 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +?> + +View/Elements/Links/index_dropdown + +element('Links.Links/index_dropdown'); diff --git a/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksIndexListOnlyTitle/index_list_only_title.ctp b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksIndexListOnlyTitle/index_list_only_title.ctp new file mode 100644 index 0000000..a794462 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksIndexListOnlyTitle/index_list_only_title.ctp @@ -0,0 +1,16 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +?> + +View/Elements/Links/index_list_only_title + +element('Links.Links/index_list_only_title'); diff --git a/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksIndexListWithDescription/index_list_with_description.ctp b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksIndexListWithDescription/index_list_with_description.ctp new file mode 100644 index 0000000..9876d1c --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksIndexListWithDescription/index_list_with_description.ctp @@ -0,0 +1,16 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +?> + +View/Elements/Links/index_list_with_description + +element('Links.Links/index_list_with_description'); diff --git a/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksLink/link.ctp b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksLink/link.ctp new file mode 100644 index 0000000..01c0cc8 --- /dev/null +++ b/Test/test_app/Plugin/TestLinks/View/TestViewElementsLinksLink/link.ctp @@ -0,0 +1,16 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +?> + +View/Elements/Links/link + +element('Links.Links/link'); 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/Vendor/empty b/Vendor/empty deleted file mode 100644 index e69de29..0000000 diff --git a/View/Elements/LinkBlockRolePermissions/edit_form.ctp b/View/Elements/LinkBlockRolePermissions/edit_form.ctp new file mode 100644 index 0000000..570c1f0 --- /dev/null +++ b/View/Elements/LinkBlockRolePermissions/edit_form.ctp @@ -0,0 +1,30 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + +NetCommonsForm->hidden('Block.id'); ?> +NetCommonsForm->hidden('Block.key'); ?> + + +element('Blocks.block_creatable_setting', array( + 'settingPermissions' => array( + 'content_creatable' => __d('links', 'Link creatable roles'), + ), + )); ?> + +element('Blocks.block_approval_setting', array( + 'model' => 'LinkSetting', + 'useWorkflow' => 'use_workflow', + 'options' => array( + Block::NEED_APPROVAL => __d('blocks', 'Need approval'), + Block::NOT_NEED_APPROVAL => __d('blocks', 'Not need approval'), + ), + )); diff --git a/View/Elements/LinkBlocks/delete_form.ctp b/View/Elements/LinkBlocks/delete_form.ctp new file mode 100644 index 0000000..e55b758 --- /dev/null +++ b/View/Elements/LinkBlocks/delete_form.ctp @@ -0,0 +1,24 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + +
+ +
+ +NetCommonsForm->hidden('LinkBlock.id'); ?> +NetCommonsForm->hidden('LinkBlock.key'); ?> + +Button->delete( + __d('net_commons', 'Delete'), + sprintf(__d('net_commons', 'Deleting the %s. Are you sure to proceed?'), __d('links', 'Link List')), + array('addClass' => 'pull-right') + ); diff --git a/View/Elements/LinkBlocks/edit_form.ctp b/View/Elements/LinkBlocks/edit_form.ctp new file mode 100644 index 0000000..b709631 --- /dev/null +++ b/View/Elements/LinkBlocks/edit_form.ctp @@ -0,0 +1,28 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + +element('Blocks.form_hidden'); ?> +NetCommonsForm->hidden('LinkSetting.use_workflow'); ?> + +NetCommonsForm->hidden('LinkBlock.id'); ?> +NetCommonsForm->hidden('LinkBlock.key'); ?> +NetCommonsForm->hidden('LinkBlock.language_id'); ?> +NetCommonsForm->hidden('BlocksLanguage.language_id'); ?> +NetCommonsForm->input('LinkBlock.name', array( + 'type' => 'text', + 'label' => __d('links', 'Link list Title'), + 'required' => true + )); ?> + +element('Blocks.public_type'); ?> + +element('Categories.edit_form'); \ No newline at end of file diff --git a/View/Elements/LinkFrameSettings/edit_form.ctp b/View/Elements/LinkFrameSettings/edit_form.ctp new file mode 100644 index 0000000..94136ef --- /dev/null +++ b/View/Elements/LinkFrameSettings/edit_form.ctp @@ -0,0 +1,150 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +$LinkFrameSetting = ClassRegistry::init('Links.LinkFrameSetting'); +?> + +NetCommonsForm->hidden('LinkFrameSetting.id'); ?> +NetCommonsForm->hidden('LinkFrameSetting.frame_key'); ?> +NetCommonsForm->hidden('Frame.id'); ?> +NetCommonsForm->hidden('Frame.key'); ?> + +NetCommonsForm->domId('LinkFrameSetting.display_type'); +?> +
+ + +
+
+ NetCommonsForm->label('LinkFrameSetting.category_separator_line', + __d('links', 'Line') + ); ?> + NetCommonsForm->hidden('LinkFrameSetting.category_separator_line', array( + 'ng-value' => 'linkFrameSetting.category_separator_line' + )); ?> + NetCommonsForm->unlockField('LinkFrameSetting.category_separator_line'); ?> + +
+ + + +
+
+
+ +
+
+ NetCommonsForm->label('LinkFrameSetting.list_style', + __d('links', 'Marker') + ); ?> + NetCommonsForm->hidden('LinkFrameSetting.list_style', array( + 'ng-value' => 'linkFrameSetting.list_style' + )); ?> + NetCommonsForm->unlockField('LinkFrameSetting.list_style'); ?> + +
+ + + +
+
+
+ + NetCommonsForm->inlineCheckbox('LinkFrameSetting.open_new_tab', array( + 'label' => __d('links', 'Open as a new tab'), + 'type' => 'checkbox', + )); ?> + + NetCommonsForm->inlineCheckbox('LinkFrameSetting.display_click_count', array( + 'label' => __d('links', 'Count view'), + 'type' => 'checkbox', + )); ?> +
diff --git a/View/Elements/Links/delete_form.ctp b/View/Elements/Links/delete_form.ctp new file mode 100644 index 0000000..c5bd1ec --- /dev/null +++ b/View/Elements/Links/delete_form.ctp @@ -0,0 +1,25 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + +NetCommonsForm->create('Link', array('type' => 'delete', 'url' => NetCommonsUrl::blockUrl(array('action' => 'delete')))); ?> + NetCommonsForm->hidden('Frame.id'); ?> + NetCommonsForm->hidden('Block.id'); ?> + NetCommonsForm->hidden('Block.key'); ?> + NetCommonsForm->hidden('Link.id'); ?> + NetCommonsForm->hidden('Link.key'); ?> + NetCommonsForm->hidden('LinkOrder.id'); ?> + + Button->delete('', + sprintf(__d('net_commons', 'Deleting the %s. Are you sure to proceed?'), __d('links', 'Link')) + ); ?> + +NetCommonsForm->end(); diff --git a/View/Elements/Links/edit_form.ctp b/View/Elements/Links/edit_form.ctp new file mode 100644 index 0000000..b7c6660 --- /dev/null +++ b/View/Elements/Links/edit_form.ctp @@ -0,0 +1,59 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + +NetCommonsForm->hidden('Block.id'); ?> +NetCommonsForm->hidden('Block.key'); ?> +NetCommonsForm->hidden('Frame.id'); ?> +NetCommonsForm->hidden('Link.id'); ?> +NetCommonsForm->hidden('Link.block_id'); ?> +NetCommonsForm->hidden('Link.key'); ?> +NetCommonsForm->hidden('Link.language_id'); ?> +NetCommonsForm->hidden('LinkOrder.id'); ?> +NetCommonsForm->hidden('LinkOrder.block_key'); ?> +NetCommonsForm->hidden('LinkOrder.link_key'); ?> + +
+ + NetCommonsForm->input('Link.url', array( + 'type' => 'text', + 'label' => __d('links', 'URL'), + 'div' => false, + 'required' => true, + 'error' => false + )); ?> + +
+ {{urlError}} +
+
+ +
+ +
+ + +NetCommonsForm->input('Link.title', array( + 'type' => 'text', + 'label' => __d('links', 'Title'), + 'required' => true, + )); ?> + +Category->select('Link.category_id', array('empty' => true)); ?> + +NetCommonsForm->input('Link.description', array( + 'type' => 'textarea', + 'label' => __d('links', 'Description'), + 'rows' => '3', + )); diff --git a/View/Elements/Links/edit_link.ctp b/View/Elements/Links/edit_link.ctp new file mode 100644 index 0000000..185ef4f --- /dev/null +++ b/View/Elements/Links/edit_link.ctp @@ -0,0 +1,18 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + +Workflow->canEdit('Links.Link', $link)) : ?> + LinkButton->edit('', array('key' => $link['Link']['key']), array( + 'tooltip' => true, + 'iconSize' => 'btn-xs' + )); ?> + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + + diff --git a/View/Elements/Links/index_list_only_title.ctp b/View/Elements/Links/index_list_only_title.ctp new file mode 100644 index 0000000..995409e --- /dev/null +++ b/View/Elements/Links/index_list_only_title.ctp @@ -0,0 +1,48 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + + + + + + +
+ + + + + + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + + + + + + +
+ + + + + + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +$attribute = ''; +if ($link['Link']['status'] === WorkflowComponent::STATUS_PUBLISHED) { + $attribute .= ' onclick="return false;" ng-click="clickLink($event, \'' . $link['Link']['id'] . '\', \'' . $link['Link']['key'] . '\')"'; +} +if ($linkFrameSetting['open_new_tab']) { + $attribute .= ' target="_blank"'; +} +?> + +'; + echo h($link['Link']['title']); + echo '' +?> + + + + + + + +request->params['action'] !== 'view') { + echo $this->Workflow->label($link['Link']['status']); +} diff --git a/View/Helper/empty b/View/Helper/empty deleted file mode 100644 index e69de29..0000000 diff --git a/View/LinkBlockRolePermissions/edit.ctp b/View/LinkBlockRolePermissions/edit.ctp new file mode 100644 index 0000000..7aadb87 --- /dev/null +++ b/View/LinkBlockRolePermissions/edit.ctp @@ -0,0 +1,25 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + +
+ BlockTabs->main(BlockTabsHelper::MAIN_TAB_BLOCK_INDEX); ?> + +
+ BlockTabs->block(BlockTabsHelper::BLOCK_TAB_PERMISSION); ?> + + element('Blocks.edit_form', array( + 'model' => 'LinkBlockRolePermission', + 'callback' => 'Links.LinkBlockRolePermissions/edit_form', + 'cancelUrl' => NetCommonsUrl::backToIndexUrl('default_setting_action'), + )); ?> +
+
diff --git a/View/LinkBlocks/edit.ctp b/View/LinkBlocks/edit.ctp new file mode 100644 index 0000000..b005ee0 --- /dev/null +++ b/View/LinkBlocks/edit.ctp @@ -0,0 +1,30 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + +
+ BlockTabs->main(BlockTabsHelper::MAIN_TAB_BLOCK_INDEX); ?> + +
+ BlockTabs->block(BlockTabsHelper::BLOCK_TAB_SETTING); ?> + + BlockForm->displayEditForm(array( + 'model' => 'LinkBlock', + 'callback' => 'Links.LinkBlocks/edit_form', + 'cancelUrl' => NetCommonsUrl::backToIndexUrl('default_setting_action'), + 'displayModified' => true, + )); ?> + + BlockForm->displayDeleteForm(array( + 'callback' => 'Links.LinkBlocks/delete_form', + )); ?> +
+
diff --git a/View/LinkBlocks/index.ctp b/View/LinkBlocks/index.ctp new file mode 100644 index 0000000..373af11 --- /dev/null +++ b/View/LinkBlocks/index.ctp @@ -0,0 +1,85 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + + +
+ BlockTabs->main(BlockTabsHelper::MAIN_TAB_BLOCK_INDEX); ?> + + BlockIndex->description(); ?> + +
+ BlockIndex->create(); ?> + BlockIndex->addLink(); ?> + + BlockIndex->startTable(); ?> + + + BlockIndex->tableHeader( + 'Frame.block_id' + ); ?> + BlockIndex->tableHeader( + 'BlocksLanguage.name', __d('links', 'Link list Title'), + array('sort' => true, 'editUrl' => true) + ); ?> + BlockIndex->tableHeader( + 'Block.content_count', __d('net_commons', 'Number'), + array('sort' => true, 'type' => 'numeric') + ); ?> + BlockIndex->tableHeader( + 'Block.public_type', __d('blocks', 'Publishing setting'), + array('sort' => true) + ); ?> + BlockIndex->tableHeader( + 'TrackableUpdater.handlename', __d('net_commons', 'Modified user'), + array('sort' => true, 'type' => 'handle') + ); ?> + BlockIndex->tableHeader( + 'Block.modified', __d('net_commons', 'Modified datetime'), + array('sort' => true, 'type' => 'datetime') + ); ?> + + + + + BlockIndex->startTableRow($linkBlock['Block']['id']); ?> + BlockIndex->tableData( + 'Frame.block_id', $linkBlock['Block']['id'] + ); ?> + BlockIndex->tableData( + 'BlocksLanguage.name', $linkBlock['BlocksLanguage']['name'], + array('editUrl' => array('block_id' => $linkBlock['Block']['id'])) + ); ?> + BlockIndex->tableData( + 'Block.content_count', $linkBlock['Block']['content_count'], + array('type' => 'numeric') + ); ?> + BlockIndex->tableData( + 'Block.public_type', $linkBlock + ); ?> + BlockIndex->tableData( + 'TrackableUpdater', $linkBlock, + array('type' => 'handle') + ); ?> + BlockIndex->tableData( + 'Block.modified', $linkBlock['Block']['modified'], + array('type' => 'datetime') + ); ?> + BlockIndex->endTableRow(); ?> + + + BlockIndex->endTable(); ?> + + BlockIndex->end(); ?> + + element('NetCommons.paginator'); ?> +
+
diff --git a/View/LinkFrameSettings/edit.ctp b/View/LinkFrameSettings/edit.ctp new file mode 100644 index 0000000..70c438f --- /dev/null +++ b/View/LinkFrameSettings/edit.ctp @@ -0,0 +1,47 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +$LinkFrameSetting = ClassRegistry::init('Links.LinkFrameSetting'); + +$categorySeparators = $LinkFrameSetting->categorySeparators; +$listStyles = $LinkFrameSetting->listStyles; +if (isset($this->data['LinkFrameSetting'])) { + $linkFrameSetting = $this->data['LinkFrameSetting']; + $currentCategorySepaLine = $this->data['LinkFrameSetting']['category_separator_line']; + $currentListStyle = $this->data['LinkFrameSetting']['list_style']; +} else { + $linkFrameSetting = []; + $currentCategorySepaLine = ''; + $currentListStyle = ''; +} +?> + +NetCommonsHtml->css('/links/css/style.css'); ?> +NetCommonsHtml->script('/links/js/links.js'); ?> + +
+ + BlockTabs->main(BlockTabsHelper::MAIN_TAB_FRAME_SETTING); ?> + +
+ BlockForm->displayEditForm(array( + 'model' => 'LinkFrameSetting', + 'callback' => 'Links.LinkFrameSettings/edit_form', + 'cancelUrl' => NetCommonsUrl::backToPageUrl(true), + )); ?> +
+
diff --git a/View/LinkMailSettings/edit.ctp b/View/LinkMailSettings/edit.ctp new file mode 100644 index 0000000..8fc2b35 --- /dev/null +++ b/View/LinkMailSettings/edit.ctp @@ -0,0 +1,30 @@ + + * @author Shohei Nakajima + * @author Mitsuru Mutaguchi + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + +
+ BlockTabs->main(BlockTabsHelper::MAIN_TAB_BLOCK_INDEX); ?> + +
+ BlockTabs->block(BlockTabsHelper::MAIN_TAB_MAIL_SETTING); ?> + + + MailForm->editFrom( + array( + array( + 'mailBodyPopoverMessage' => __d('links', 'MailSetting.mail_fixed_phrase_body.popover'), + ), + ), + NetCommonsUrl::backToIndexUrl('default_setting_action') + ); ?> +
+
diff --git a/View/LinkOrders/edit.ctp b/View/LinkOrders/edit.ctp new file mode 100644 index 0000000..dc40fb7 --- /dev/null +++ b/View/LinkOrders/edit.ctp @@ -0,0 +1,92 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +echo $this->NetCommonsHtml->script('/links/js/links.js'); + +$editUrlFormat = $this->NetCommonsHtml->url(array('controller' => 'links', 'action' => 'edit', 'key' => '%s')); +?> + +
+ + NetCommonsHtml->blockTitle($linkBlock['name']); ?> + + NetCommonsForm->create('LinkOrders', array('type' => 'put')); ?> + data['LinkOrders']) as $linkOrderId) : ?> + NetCommonsForm->hidden('LinkOrders.' . $linkOrderId . '.LinkOrder.id'); ?> + NetCommonsForm->hidden('LinkOrders.' . $linkOrderId . '.LinkOrder.block_key'); ?> + NetCommonsForm->hidden('LinkOrders.' . $linkOrderId . '.LinkOrder.category_key'); ?> + NetCommonsForm->hidden('LinkOrders.' . $linkOrderId . '.LinkOrder.link_key'); ?> + NetCommonsForm->unlockField('LinkOrders.' . $linkOrderId . '.LinkOrder.weight'); ?> + + + NetCommonsForm->hidden('Frame.id'); ?> + NetCommonsForm->hidden('Block.id'); ?> + NetCommonsForm->hidden('Block.key'); ?> + +
+

+
+ +
+ +
+ +
+ Button->cancelAndSave(__d('net_commons', 'Cancel'), __d('net_commons', 'OK')); ?> +
+ + NetCommonsForm->end(); ?> +
diff --git a/View/Links/edit.ctp b/View/Links/edit.ctp new file mode 100644 index 0000000..b8628b2 --- /dev/null +++ b/View/Links/edit.ctp @@ -0,0 +1,43 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ +?> + +NetCommonsHtml->script('/links/js/links.js'); ?> +NetCommonsHtml->css('/links/css/style.css'); ?> + +
+ NetCommonsHtml->blockTitle($linkBlock['name']); ?> + +
+
+ NetCommonsForm->create('Link'); ?> +
+ element('Links/edit_form'); ?> + +
+ + Workflow->inputComment('Link.status'); ?> +
+ + Workflow->buttons('Link.status'); ?> + + NetCommonsForm->end(); ?> + + request->params['action'] === 'edit' && $this->Workflow->canDelete('Link', $this->data)) : ?> + + +
+ + Workflow->comments(); ?> +
+
diff --git a/View/Links/index.ctp b/View/Links/index.ctp new file mode 100644 index 0000000..38e9958 --- /dev/null +++ b/View/Links/index.ctp @@ -0,0 +1,76 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +$this->request->data = array( + 'Frame' => array( + 'id' => Current::read('Frame.id') + ), + 'Block' => array( + 'id' => Current::read('Block.id') + ), + 'Link' => array( + 'id' => null, + 'key' => null, + ), +); +$tokenFields = Hash::flatten($this->request->data); +$hiddenFields = array('Frame.id', 'Block.id'); + +$this->Token->unlockField('Link.id'); +$tokens = $this->Token->getToken('Link', + '/links/links/link.json', + $tokenFields, + $hiddenFields +); + +echo $this->NetCommonsHtml->css('/links/css/style.css'); +echo $this->NetCommonsHtml->script('/links/js/links.js'); + +$displayType = $linkFrameSetting['display_type']; +?> + +
+ + + NetCommonsHtml->blockTitle($linkBlock['name']); ?> + + +
+ + LinkButton->sort('', + NetCommonsUrl::blockUrl(array('controller' => 'link_orders', 'action' => 'edit')) + ); ?> + + + Workflow->addLinkButton('', null, array('tooltip' => __d('links', 'Create link'))); ?> +
+ + element('Links/index_dropdown'); + + } elseif ($displayType === LinkFrameSetting::TYPE_LIST_ONLY_TITLE) { + if ($links) { + echo $this->element('Links/index_list_only_title'); + } else { + echo '
' . __d('links', 'No link found.') . '
'; + } + + } elseif ($displayType === LinkFrameSetting::TYPE_LIST_WITH_DESCRIPTION) { + if ($links) { + echo $this->element('Links/index_list_with_description'); + } else { + echo '
' . __d('links', 'No link found.') . '
'; + } + } + ?> +
diff --git a/View/Links/view.ctp b/View/Links/view.ctp new file mode 100644 index 0000000..a603364 --- /dev/null +++ b/View/Links/view.ctp @@ -0,0 +1,87 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + + +$this->request->data = array( + 'Frame' => array( + 'id' => Current::read('Frame.id') + ), + 'Block' => array( + 'id' => Current::read('Block.id') + ), + 'Link' => array( + 'id' => null, + 'key' => null, + ), +); +$tokenFields = Hash::flatten($this->request->data); +$hiddenFields = array('Frame.id', 'Block.id'); + +$this->Token->unlockField('Link.id'); +$tokens = $this->Token->getToken('Link', + $this->NetCommonsHtml->url('/links/links/link.json'), + $tokenFields, + $hiddenFields +); + +echo $this->NetCommonsHtml->css('/links/css/style.css'); +echo $this->NetCommonsHtml->script('/links/js/links.js'); +?> + +
+ +
+
+ LinkButton->toList(); ?> +
+ Workflow->canEdit('Links.Link', $link)) : ?> +
+ LinkButton->edit('', array('key' => $link['Link']['key'])); ?> +
+ +
+ +

+ Workflow->label($link['Link']['status']) . + $this->element('Links.Links/link', array('link' => $link)); ?> +

+ + + +
+ +
+
diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d190b8b --- /dev/null +++ b/composer.json @@ -0,0 +1,42 @@ +{ + "name": "netcommons/links", + "description": "Links for NetCommons Plugin", + "type": "cakephp-plugin", + "homepage": "http://www.netcommons.org/", + "extra": { + "installer-paths": { + "app/Plugin/{$name}": [ + "type:cakephp-plugin" + ] + } + }, + "require": { + "cakedc/migrations": "~2.2", + "netcommons/blocks": "@dev", + "netcommons/categories": "@dev", + "netcommons/mails": "@dev", + "netcommons/pages": "@dev", + "netcommons/plugin-manager": "@dev", + "netcommons/topics": "@dev", + "netcommons/workflow": "@dev" + }, + "license": "LicenseRef-NetCommons", + "license-ref-net-commons": "https://raw.githubusercontent.com/NetCommons3/NetCommons3/master/license.txt", + "authors": [ + { + "name": "NetCommons Community", + "homepage": "http://www.netcommons.org" + }, + { + "name": "NaKaZii Co., Ltd.", + "homepage": "https://github.com/s-nakajima" + } + ], + "keywords": [ + "cakephp", + "links" + ], + "config": { + "vendor-dir": "vendors" + } +} \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..60656f0 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,22 @@ + + + + + + + + app/Plugin/Links + app/Plugin/Links + + app/Plugin/Links/Config/Migration + app/Plugin/Links/Config/Schema + app/Plugin/Links/Test/Case + app/Plugin/Links/Test/Fixture + + + + + + + + diff --git a/webroot/css/style.css b/webroot/css/style.css new file mode 100644 index 0000000..b53e547 --- /dev/null +++ b/webroot/css/style.css @@ -0,0 +1,74 @@ +/** + * links/css/style.css + * + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + */ + +/** + * 一覧表示 + */ +li.list-group-item.nc-links-li, +li.list-group-item.nc-links-li-none { + border: none; + padding: 0px; + display: list-item; +} + +.nc-links-li { + margin-top: 8px; + margin-left: 30px; + margin-bottom: 15px; +} +.nc-links-li-none { + margin-top: 8px; + /*margin-left: 30px;*/ + margin-bottom: 15px; +} + +.links-line-none { + border: none !important; +} +.links-line-none ul.list-group { + margin-bottom: 0px; +} + +/** + * 一覧表示 + */ +.link-view-info { + margin-bottom: 8px; +} +.link-view-info .pull-left { + margin-right: 32px; +} + +/** + * 表示方法変更 + */ +hr.nc-links-edit-line { + margin-top: 8px; + margin-bottom: 8px; +} +.nc-input-dropdown .pull-left > hr.nc-links-edit-line { + min-width: 100px; + width: 250px; + max-width: 600px; +} +ul.nc-links-edit-mark { + padding-left: 20px; + margin-top: 0px; + margin-bottom: 0px; +} + +.link-frame-setting-display-type .radio:last-child { + margin-bottom: 4px; +} + +/** + * 編集画面 + */ +.link-getbtn { + width: 30%; +} diff --git a/webroot/empty b/webroot/empty deleted file mode 100644 index e69de29..0000000 diff --git a/webroot/img/line/line_a1.gif b/webroot/img/line/line_a1.gif new file mode 100644 index 0000000..80de4a6 Binary files /dev/null and b/webroot/img/line/line_a1.gif differ diff --git a/webroot/img/line/line_a2.gif b/webroot/img/line/line_a2.gif new file mode 100644 index 0000000..1a50835 Binary files /dev/null and b/webroot/img/line/line_a2.gif differ diff --git a/webroot/img/line/line_a3.gif b/webroot/img/line/line_a3.gif new file mode 100644 index 0000000..e258ba5 Binary files /dev/null and b/webroot/img/line/line_a3.gif differ diff --git a/webroot/img/line/line_a4.gif b/webroot/img/line/line_a4.gif new file mode 100644 index 0000000..9ec1249 Binary files /dev/null and b/webroot/img/line/line_a4.gif differ diff --git a/webroot/img/line/line_b1.gif b/webroot/img/line/line_b1.gif new file mode 100644 index 0000000..970bfb0 Binary files /dev/null and b/webroot/img/line/line_b1.gif differ diff --git a/webroot/img/line/line_b2.gif b/webroot/img/line/line_b2.gif new file mode 100644 index 0000000..6e32df1 Binary files /dev/null and b/webroot/img/line/line_b2.gif differ diff --git a/webroot/img/line/line_b3.gif b/webroot/img/line/line_b3.gif new file mode 100644 index 0000000..9d23cb8 Binary files /dev/null and b/webroot/img/line/line_b3.gif differ diff --git a/webroot/img/line/line_b4.gif b/webroot/img/line/line_b4.gif new file mode 100644 index 0000000..ebf5b2e Binary files /dev/null and b/webroot/img/line/line_b4.gif differ diff --git a/webroot/img/line/line_b5.gif b/webroot/img/line/line_b5.gif new file mode 100644 index 0000000..cceefd4 Binary files /dev/null and b/webroot/img/line/line_b5.gif differ diff --git a/webroot/img/line/line_b6.gif b/webroot/img/line/line_b6.gif new file mode 100644 index 0000000..1082bee Binary files /dev/null and b/webroot/img/line/line_b6.gif differ diff --git a/webroot/img/line/line_c1.gif b/webroot/img/line/line_c1.gif new file mode 100644 index 0000000..f79bafc Binary files /dev/null and b/webroot/img/line/line_c1.gif differ diff --git a/webroot/img/line/line_c2.gif b/webroot/img/line/line_c2.gif new file mode 100644 index 0000000..58fd20b Binary files /dev/null and b/webroot/img/line/line_c2.gif differ diff --git a/webroot/img/line/line_c3.gif b/webroot/img/line/line_c3.gif new file mode 100644 index 0000000..6e21b28 Binary files /dev/null and b/webroot/img/line/line_c3.gif differ diff --git a/webroot/img/line/line_c4.gif b/webroot/img/line/line_c4.gif new file mode 100644 index 0000000..c1e255c Binary files /dev/null and b/webroot/img/line/line_c4.gif differ diff --git a/webroot/img/mark/mark_a1.gif b/webroot/img/mark/mark_a1.gif new file mode 100644 index 0000000..32084ba Binary files /dev/null and b/webroot/img/mark/mark_a1.gif differ diff --git a/webroot/img/mark/mark_a2.gif b/webroot/img/mark/mark_a2.gif new file mode 100644 index 0000000..7061243 Binary files /dev/null and b/webroot/img/mark/mark_a2.gif differ diff --git a/webroot/img/mark/mark_a3.gif b/webroot/img/mark/mark_a3.gif new file mode 100644 index 0000000..ddb0798 Binary files /dev/null and b/webroot/img/mark/mark_a3.gif differ diff --git a/webroot/img/mark/mark_a4.gif b/webroot/img/mark/mark_a4.gif new file mode 100644 index 0000000..623818c Binary files /dev/null and b/webroot/img/mark/mark_a4.gif differ diff --git a/webroot/img/mark/mark_a5.gif b/webroot/img/mark/mark_a5.gif new file mode 100644 index 0000000..f1be716 Binary files /dev/null and b/webroot/img/mark/mark_a5.gif differ diff --git a/webroot/img/mark/mark_b1.gif b/webroot/img/mark/mark_b1.gif new file mode 100644 index 0000000..7a62f90 Binary files /dev/null and b/webroot/img/mark/mark_b1.gif differ diff --git a/webroot/img/mark/mark_b2.gif b/webroot/img/mark/mark_b2.gif new file mode 100644 index 0000000..5996aa3 Binary files /dev/null and b/webroot/img/mark/mark_b2.gif differ diff --git a/webroot/img/mark/mark_b3.gif b/webroot/img/mark/mark_b3.gif new file mode 100644 index 0000000..2c058d1 Binary files /dev/null and b/webroot/img/mark/mark_b3.gif differ diff --git a/webroot/img/mark/mark_c1.gif b/webroot/img/mark/mark_c1.gif new file mode 100644 index 0000000..72a1103 Binary files /dev/null and b/webroot/img/mark/mark_c1.gif differ diff --git a/webroot/img/mark/mark_c2.gif b/webroot/img/mark/mark_c2.gif new file mode 100644 index 0000000..4eb3930 Binary files /dev/null and b/webroot/img/mark/mark_c2.gif differ diff --git a/webroot/img/mark/mark_c3.gif b/webroot/img/mark/mark_c3.gif new file mode 100644 index 0000000..e284895 Binary files /dev/null and b/webroot/img/mark/mark_c3.gif differ diff --git a/webroot/img/mark/mark_c4.gif b/webroot/img/mark/mark_c4.gif new file mode 100644 index 0000000..80d71a5 Binary files /dev/null and b/webroot/img/mark/mark_c4.gif differ diff --git a/webroot/img/mark/mark_d1.gif b/webroot/img/mark/mark_d1.gif new file mode 100644 index 0000000..336a498 Binary files /dev/null and b/webroot/img/mark/mark_d1.gif differ diff --git a/webroot/img/mark/mark_d2.gif b/webroot/img/mark/mark_d2.gif new file mode 100644 index 0000000..ec93bf9 Binary files /dev/null and b/webroot/img/mark/mark_d2.gif differ diff --git a/webroot/img/mark/mark_d3.gif b/webroot/img/mark/mark_d3.gif new file mode 100644 index 0000000..73a8933 Binary files /dev/null and b/webroot/img/mark/mark_d3.gif differ diff --git a/webroot/img/mark/mark_d4.gif b/webroot/img/mark/mark_d4.gif new file mode 100644 index 0000000..a199c3a Binary files /dev/null and b/webroot/img/mark/mark_d4.gif differ diff --git a/webroot/img/mark/mark_d5.gif b/webroot/img/mark/mark_d5.gif new file mode 100644 index 0000000..fb4572a Binary files /dev/null and b/webroot/img/mark/mark_d5.gif differ diff --git a/webroot/img/mark/mark_e1.gif b/webroot/img/mark/mark_e1.gif new file mode 100644 index 0000000..91d67b1 Binary files /dev/null and b/webroot/img/mark/mark_e1.gif differ diff --git a/webroot/img/mark/mark_e2.gif b/webroot/img/mark/mark_e2.gif new file mode 100644 index 0000000..9500204 Binary files /dev/null and b/webroot/img/mark/mark_e2.gif differ diff --git a/webroot/img/mark/mark_e3.gif b/webroot/img/mark/mark_e3.gif new file mode 100644 index 0000000..e3fed11 Binary files /dev/null and b/webroot/img/mark/mark_e3.gif differ diff --git a/webroot/img/mark/mark_e4.gif b/webroot/img/mark/mark_e4.gif new file mode 100644 index 0000000..231f793 Binary files /dev/null and b/webroot/img/mark/mark_e4.gif differ diff --git a/webroot/img/mark/mark_e5.gif b/webroot/img/mark/mark_e5.gif new file mode 100644 index 0000000..97076fb Binary files /dev/null and b/webroot/img/mark/mark_e5.gif differ diff --git a/webroot/js/links.js b/webroot/js/links.js new file mode 100644 index 0000000..df10e14 --- /dev/null +++ b/webroot/js/links.js @@ -0,0 +1,231 @@ +/** + * @fileoverview Links Javascript + * @author nakajimashouhei@gmail.com (Shohei Nakajima) + */ + + +/** + * LinksIndex Javascript + * + * @param {string} Controller name + * @param {function($scope, $http, $window)} Controller + */ +NetCommonsApp.controller('LinksIndex', + ['$scope', '$http', '$window', 'NC3_URL', function($scope, $http, $window, NC3_URL) { + + /** + * data + * + * @type {object} + */ + $scope.data = {}; + + /** + * initialize + * + * @return {void} + */ + $scope.initialize = function(data) { + $scope.data = { + _Token: data['_Token'], + Frame: {id: data['Frame']['id']}, + Block: {id: data['Block']['id']}, + Link: {id: '', key: ''} + }; + }; + + /** + * Click link + * + * @param {integer} links.id + * @return {void} + */ + $scope.clickLink = function($event, id, key) { + $scope.data.Link.id = id; + $scope.data.Link.key = key; + + $http.get(NC3_URL + '/net_commons/net_commons/csrfToken.json') + .then(function(response) { + var token = response.data; + $scope.data._Token.key = token.data._Token.key; + + //POSTリクエスト + $http.put( + NC3_URL + '/links/links/link.json', + $.param({_method: 'PUT', data: $scope.data}), + {cache: false, + headers: + {'Content-Type': 'application/x-www-form-urlencoded'} + } + ).then(function() { + var element = $('#nc-badge-' + $scope.data.Frame.id + '-' + id); + if (element) { + var count = parseInt(element.html()) + 1; + element.html(count); + } + }); + }); + + if ($event.target.target) { + $window.open($event.target.href, $event.target.target); + } else { + $window.location.href = $event.target.href; + } + }; + }]); + + +/** + * LinksEdit Javascript + * + * @param {string} Controller name + * @param {function($scope, $http)} Controller + */ +NetCommonsApp.controller('LinksEdit', + ['$scope', '$http', 'NC3_URL', function($scope, $http, NC3_URL) { + + /** + * Get url + * + * @return {void} + */ + $scope.getUrl = function(frameId) { + var element = $('input[name="data[Link][url]"]'); + + if (angular.isUndefined(element[0]) || ! element[0].value) { + return; + } + + $http.get(NC3_URL + '/links/links/get.json', + {params: {frame_id: frameId, url: element[0].value}}) + .then(function(response) { + var data = response.data; + element = $('input[name="data[Link][title]"]'); + if (! angular.isUndefined(element[0]) && + ! angular.isUndefined(data['title'])) { + element[0].value = data['title']; + } + + element = $('textarea[name="data[Link][description]"]'); + if (! angular.isUndefined(element[0]) && + ! angular.isUndefined(data['description'])) { + element[0].value = data['description']; + } + + $scope.urlError = ''; + }, + function(response) { + var data = response.data; + $scope.urlError = angular.isUndefined(data['error']) ? data['name'] : data['error']; + }); + }; + + }]); + + +/** + * LinksEdit Javascript + * + * @param {string} Controller name + * @param {function($scope)} Controller + */ +NetCommonsApp.controller('LinkFrameSettings', ['$scope', function($scope) { + + /** + * initialize + * + * @return {void} + */ + $scope.initialize = function(data) { + $scope.linkFrameSetting = data.linkFrameSetting; + $scope.currentCategorySeparatorLine = data.currentCategorySeparatorLine; + $scope.currentListStyle = data.currentListStyle; + }; + + /** + * Select categorySeparatorLine + * + * @return {void} + */ + $scope.selectCategorySeparatorLine = function(line) { + $scope.linkFrameSetting.category_separator_line = line.key; + $scope.currentCategorySeparatorLine = line; + }; + + /** + * Select listStyle + * + * @return {void} + */ + $scope.selectListStyle = function(mark) { + $scope.linkFrameSetting.list_style = mark.key; + $scope.currentListStyle = mark; + }; + +}]); + + +/** + * LinkOrders Javascript + * + * @param {string} Controller name + * @param {function($scope)} Controller + */ +NetCommonsApp.controller('LinkOrders', ['$scope', function($scope) { + + /** + * Links + * + * @type {object} + */ + $scope.links = {}; + + /** + * Categories + * + * @type {object} + */ + $scope.categories = []; + + /** + * initialize + * + * @return {void} + */ + $scope.initialize = function(data) { + var categoryId = ''; + angular.forEach(data.categories, function(value) { + $scope.categories.push(value); + + categoryId = value.Category.id; + + if (! angular.isUndefined(data.links[categoryId])) { + angular.forEach(data.links[categoryId], function(link) { + if (angular.isUndefined($scope.links['_' + categoryId])) { + $scope.links['_' + categoryId] = new Array(); + } + $scope.links['_' + categoryId].push(link); + }); + } + }); + }; + + /** + * move + * + * @return {void} + */ + $scope.move = function(categoryId, type, index) { + var dest = (type === 'up') ? index - 1 : index + 1; + + if (angular.isUndefined($scope.links['_' + categoryId][dest])) { + return false; + } + + var destLink = angular.copy($scope.links['_' + categoryId][dest]); + var targetLink = angular.copy($scope.links['_' + categoryId][index]); + $scope.links['_' + categoryId][index] = destLink; + $scope.links['_' + categoryId][dest] = targetLink; + }; + +}]);