コード例 #1
0
 /**
  * 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')
 {
     //ログイン
     TestAuthGeneral::login($this, Role::ROOM_ROLE_KEY_EDITOR);
     //テスト実施
     $url = Hash::merge(array('plugin' => $this->plugin, 'controller' => $this->_controller, 'action' => 'view'), $urlOptions);
     $this->_testGetAction($url, $assert, $exception, $return);
     //ログアウト
     TestAuthGeneral::logout($this);
 }
コード例 #2
0
ファイル: IndexTest.php プロジェクト: s-nakajima/ControlPanel
 /**
  * XmlException()のテスト
  *
  * @return void
  * @throws XmlException
  */
 public function testIndexOnXmlException()
 {
     TestAuthGeneral::login($this, UserRole::USER_ROLE_KEY_SYSTEM_ADMINISTRATOR);
     //Mockの設定
     $this->controller->Notification->expects($this->once())->method('serialize')->will($this->returnCallback(function () {
         throw new XmlException(__d('cake_dev', 'Invalid input.'));
     }));
     //テスト実行
     $this->_testNcAction('/control_panel/control_panel/index', array('method' => 'get'));
     $this->assertCount(1, $this->vars['notifications']);
 }
コード例 #3
0
 /**
  * アクセスチェック
  *
  * @param string|null $role 会員権限、nullはログインなし
  * @param string $exception Exception文字列
  * @dataProvider dataProvider
  * @return void
  */
 public function testPermission($role, $exception)
 {
     if (isset($role)) {
         TestAuthGeneral::login($this, $role);
     }
     if ($exception) {
         $this->setExpectedException($exception);
     }
     //テスト実行
     $this->_testNcAction('/test_control_panel/test_control_panel_app/index', array('method' => 'get'));
     if (!$exception) {
         $this->assertNotEmpty($this->view);
     }
 }
コード例 #4
0
 /**
  * accessCheck()のテスト
  *
  * @return void
  */
 public function testAccessCheck()
 {
     //ログイン
     TestAuthGeneral::login($this);
     //テストアクション実行
     $this->_testGetAction('/test_public_space/test_public_space_component/index', array('method' => 'assertNotEmpty'), null, 'view');
     $pattern = '/' . preg_quote('Controller/Component/TestPublicSpaceComponent', '/') . '/';
     $this->assertRegExp($pattern, $this->view);
     //テストデータ
     $this->_mockForReturnTrue('Rooms.RolesRoomsUser', 'saveAccessed');
     //テスト実行
     $result = $this->controller->PublicSpace->accessCheck($this->controller);
     //チェック
     $this->assertTrue($result);
 }
コード例 #5
0
 /**
  * indexのテスト
  *
  * @return void
  */
 public function testIndexTitle()
 {
     $this->generateNc('TestControlPanel.TestLayoutComponentTitle');
     //ログイン
     TestAuthGeneral::login($this);
     //テスト実行
     $this->_testNcAction('/test_control_panel/test_layout_component_title/index', array('method' => 'get'));
     //チェック
     // * ControlPanelLayoutComponentのチェック
     $this->assertEquals('ControlPanel.default', $this->controller->layout);
     $this->assertNull(Hash::get($this->vars, 'title'));
     // * View/Layout/defaultのチェック
     $pattern = '/' . preg_quote('TestControlPanel/Controller/TestLayoutComponentTitleController', '/') . '/';
     $this->assertRegExp($pattern, $this->contents);
     $pattern = '/Test Title/';
     $this->assertRegExp($pattern, $this->contents);
     $pattern = '/Test Subtitle/';
     $this->assertRegExp($pattern, $this->contents);
 }
コード例 #6
0
 /**
  * editアクションのPOSTテスト
  *
  * @param array $data POSTデータ
  * @param string|null $exception Exception
  * @param string $return testActionの実行後の結果
  * @dataProvider dataProviderEditPost
  * @return void
  */
 public function testEditPost($data, $exception = null, $return = 'view')
 {
     //ログイン
     TestAuthGeneral::login($this);
     $frameId = '6';
     $blockId = '4';
     $blockKey = 'block_2';
     $roomId = '1';
     $permissions = $this->_getPermissionData(true, Hash::check($data, '{s}.use_comment_approval'));
     $RolesRoomFixture = new RolesRoomFixture();
     $rolesRooms = Hash::extract($RolesRoomFixture->records, '{n}[room_id=' . $roomId . ']');
     $default['Block'] = array('id' => $blockId, 'key' => $blockKey);
     foreach ($permissions as $permission => $roles) {
         foreach ($roles as $role) {
             $rolesRoom = Hash::extract($rolesRooms, '{n}[role_key=' . $role . ']');
             $default['BlockRolePermission'][$permission][$role] = array('roles_room_id' => $rolesRoom[0]['id'], 'block_key' => $blockKey, 'permission' => $permission, 'value' => '1');
         }
     }
     //テスト実施
     $url = array('action' => 'edit', 'frame_id' => $frameId, 'block_id' => $blockId);
     $result = $this->_testPostAction('post', Hash::merge($default, $data), $url, $exception, $return);
     //正常の場合、リダイレクト
     if (!isset($exception)) {
         $header = $this->controller->response->header();
         $this->assertNotEmpty($header['Location']);
     }
     //ログアウト
     TestAuthGeneral::logout($this);
     return $result;
 }
コード例 #7
0
 /**
  * editアクションのValidateionErrorテスト
  *
  * @param array $data POSTデータ
  * @param array $urlOptions URLオプション
  * @param string|null $validationError ValidationError
  * @dataProvider dataProviderEditValidationError
  * @return void
  */
 public function testEditValidationError($data, $urlOptions, $validationError = null)
 {
     //ログイン
     TestAuthGeneral::login($this);
     //テスト実施
     $this->_testActionOnValidationError('put', $data, Hash::merge(array('action' => 'edit'), $urlOptions), $validationError);
     //ログアウト
     TestAuthGeneral::logout($this);
 }
コード例 #8
0
 /**
  * index()のページネーションテスト
  *
  * @param int $page ページ番号
  * @param bool $isFirst 最初のページかどうか
  * @param bool $isLast 最後のページかどうか
  * @dataProvider dataProviderPaginator
  * @return void
  */
 public function testIndexPaginator($page, $isFirst, $isLast)
 {
     TestAuthGeneral::login($this);
     //テスト実施
     $frameId = '16';
     $url = array('plugin' => $this->plugin, 'controller' => $this->_controller, 'action' => 'index', 'frame_id' => $frameId);
     if (!$isFirst) {
         $url[] = 'page:' . $page;
     }
     $result = $this->_testNcAction($url, array('method' => 'get'));
     //チェック
     $this->assertRegExp('/' . preg_quote('<ul class="pagination">', '/') . '/', $result);
     if ($isFirst) {
         $this->assertNotRegExp('/<li><a.*?rel="first".*?<\\/a><\\/li>/', $result);
     } else {
         $this->assertRegExp('/<li><a.*?rel="first".*?<\\/a><\\/li>/', $result);
     }
     $this->assertRegExp('/<li class="active"><a>' . $page . '<\\/a><\\/li>/', $result);
     if ($isLast) {
         $this->assertNotRegExp('/<li><a.*?rel="last".*?<\\/a><\\/li>/', $result);
     } else {
         $this->assertRegExp('/<li><a.*?rel="last".*?<\\/a><\\/li>/', $result);
     }
     TestAuthGeneral::logout($this);
 }
コード例 #9
0
 /**
  * index()のアクセス許可テスト
  *
  * @param string $role ロール名
  * @param bool $isException Exceptionの有無
  * @dataProvider dataProviderRoleAccess
  * @return void
  */
 public function testAccessPermission($role, $isException)
 {
     if (isset($role)) {
         TestAuthGeneral::login($this, $role);
     }
     if ($isException) {
         $exception = 'ForbiddenException';
     } else {
         $exception = null;
     }
     //テスト実施
     $frameId = '6';
     $url = array('plugin' => $this->plugin, 'controller' => $this->_controller, 'action' => 'index', 'frame_id' => $frameId);
     $result = $this->_testNcAction($url, array('method' => 'get'), $exception, 'viewFile');
     //チェック
     $this->assertTextEquals('index', $result);
 }
コード例 #10
0
 /**
  * delete()のテスト
  *
  * @param array $data 削除データ
  * @dataProvider dataProviderDelete
  * @return void
  */
 public function testDelete($data)
 {
     //ログイン
     TestAuthGeneral::login($this);
     $frameId = '6';
     $blockId = '4';
     //アクション実行
     $url = NetCommonsUrl::actionUrl(array('plugin' => $this->plugin, 'controller' => $this->_controller, 'action' => 'delete', 'frame_id' => $frameId, 'block_id' => $blockId));
     $params = array('method' => 'delete', 'return' => 'view', 'data' => $data);
     $this->testAction($url, $params);
     //チェック
     $header = $this->controller->response->header();
     $asserts = array(array('method' => 'assertNotEmpty', 'value' => $header['Location']));
     $this->asserts($asserts, $this->contents);
     //ログアウト
     TestAuthGeneral::logout($this);
 }
コード例 #11
0
 /**
  * deleteアクションのPOSTテスト
  *
  * @param array $data POSTデータ
  * @param string $role ロール
  * @param array $urlOptions URLオプション
  * @param string|null $exception Exception
  * @param string $return testActionの実行後の結果
  * @dataProvider dataProviderDeletePost
  * @return void
  */
 public function testDeletePost($data, $role, $urlOptions, $exception = null, $return = 'view')
 {
     //ログイン
     if (isset($role)) {
         TestAuthGeneral::login($this, $role);
     }
     //テスト実施
     $this->_testPostAction('delete', $data, Hash::merge(array('action' => 'delete'), $urlOptions), $exception, $return);
     //正常の場合、リダイレクト
     if (!$exception) {
         $header = $this->controller->response->header();
         $this->assertNotEmpty($header['Location']);
     }
     //ログアウト
     if (isset($role)) {
         TestAuthGeneral::logout($this);
     }
 }
コード例 #12
0
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     //ログアウト
     TestAuthGeneral::logout($this);
     parent::tearDown();
 }