Browse Source

Fix failing tests and remove PrivateActionException.

With isAction() handling private method access checks, we can't easily
distinguish between methods missing, and methods not having public
visibility. This error class is just cruft now.
Mark Story 11 years ago
parent
commit
94cbb69b40

+ 13 - 14
src/Controller/Controller.php

@@ -395,23 +395,22 @@ class Controller implements EventListener {
  *
  * @return mixed The resulting response.
  * @throws \LogicException When request is not set.
- * @throws \Cake\Controller\Exception\PrivateActionException When actions are not public or prefixed by _
- * @throws \Cake\Controller\Exception\MissingActionException When actions are not defined.
+ * @throws \Cake\Controller\Exception\MissingActionException When actions are not defined or inaccessible.
  */
 	public function invokeAction() {
+		$request = $this->request;
+		if (!isset($request)) {
+			throw new LogicException('No Request object configured. Cannot invoke action');
+		}
+		if (!$this->isAction($request->params['action'])) {
+			throw new MissingActionException(array(
+				'controller' => $this->name . "Controller",
+				'action' => $request->params['action'],
+				'prefix' => isset($request->params['prefix']) ? $request->params['prefix'] : '',
+				'plugin' => $request->params['plugin'],
+			));
+		}
 		try {
-			$request = $this->request;
-			if (!isset($request)) {
-				throw new LogicException('No Request object configured. Cannot invoke action');
-			}
-			if (!$this->isAction($request)) {
-				throw new PrivateActionException(array(
-					'controller' => $this->name . "Controller",
-					'action' => $request->params['action'],
-					'prefix' => isset($request->params['prefix']) ? $request->params['prefix'] : '',
-					'plugin' => $request->params['plugin'],
-				));
-			}
 			$method = new ReflectionMethod($this, $request->params['action']);
 			return $method->invokeArgs($this, $request->params['pass']);
 		} catch (ReflectionException $e) {

+ 2 - 3
src/Controller/Exception/MissingActionException.php

@@ -17,15 +17,14 @@ use Cake\Core\Exception\Exception;
 
 /**
  * Missing Action exception - used when a controller action
- * cannot be found.
- *
+ * cannot be found, or when the controller's isAction() method returns false.
  */
 class MissingActionException extends Exception {
 
 /**
  * {@inheritDoc}
  */
-	protected $_messageTemplate = 'Action %s::%s() could not be found.';
+	protected $_messageTemplate = 'Action %s::%s() could not be found, or is not accessible.';
 
 /**
  * {@inheritDoc}

+ 0 - 44
src/Controller/Exception/PrivateActionException.php

@@ -1,44 +0,0 @@
-<?php
-/**
- * PrivateActionException class
- *
- * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link          http://book.cakephp.org/2.0/en/development/testing.html
- * @since         3.0.0
- * @license       http://www.opensource.org/licenses/mit-license.php MIT License
- */
-namespace Cake\Controller\Exception;
-
-use Cake\Core\Exception\Exception;
-
-/**
- * Private Action exception - used when a controller action
- * starts with a  `_`.
- */
-class PrivateActionException extends Exception {
-
-/**
- * Message template.
- *
- * @var string
- */
-	protected $_messageTemplate = 'Private Action %s::%s() is not directly accessible.';
-
-/**
- * Constructor
- *
- * @param string $message Excception message
- * @param int $code Exception code
- * @param Exception $previous Previous exception
- */
-	public function __construct($message, $code = 404, Exception $previous = null) {
-		parent::__construct($message, $code, $previous);
-	}
-
-}

+ 0 - 27
src/Template/Error/private_action.ctp

@@ -1,27 +0,0 @@
-<?php
-/**
- *
- * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link          http://cakephp.org CakePHP(tm) Project
- * @since         0.10.0
- * @license       http://www.opensource.org/licenses/mit-license.php MIT License
- */
-?>
-<h2><?= sprintf('Private Method in %s', $controller); ?></h2>
-<p class="error">
-	<strong>Error: </strong>
-	<?= sprintf('<em>%s::%s()</em> cannot be accessed directly.', h($controller), h($action)); ?>
-</p>
-<p class="notice">
-	<strong>Notice: </strong>
-	<?= sprintf('If you want to customize this error message, create %s', APP_DIR . DS . 'Template' . DS . 'Error' . DS . 'private_action.ctp'); ?>
-</p>
-
-<?= $this->element('exception_stack_trace'); ?>

+ 7 - 7
tests/TestCase/Controller/ControllerTest.php

@@ -693,7 +693,7 @@ class ControllerTest extends TestCase {
  * testMissingAction method
  *
  * @expectedException \Cake\Controller\Exception\MissingActionException
- * @expectedExceptionMessage Action TestController::missing() could not be found.
+ * @expectedExceptionMessage Action TestController::missing() could not be found, or is not accessible.
  * @return void
  */
 	public function testInvokeActionMissingAction() {
@@ -708,8 +708,8 @@ class ControllerTest extends TestCase {
 /**
  * test invoking private methods.
  *
- * @expectedException \Cake\Controller\Exception\PrivateActionException
- * @expectedExceptionMessage Private Action TestController::private_m() is not directly accessible.
+ * @expectedException \Cake\Controller\Exception\MissingActionException
+ * @expectedExceptionMessage Action TestController::private_m() could not be found, or is not accessible.
  * @return void
  */
 	public function testInvokeActionPrivate() {
@@ -724,8 +724,8 @@ class ControllerTest extends TestCase {
 /**
  * test invoking protected methods.
  *
- * @expectedException \Cake\Controller\Exception\PrivateActionException
- * @expectedExceptionMessage Private Action TestController::protected_m() is not directly accessible.
+ * @expectedException \Cake\Controller\Exception\MissingActionException
+ * @expectedExceptionMessage Action TestController::protected_m() could not be found, or is not accessible.
  * @return void
  */
 	public function testInvokeActionProtected() {
@@ -740,8 +740,8 @@ class ControllerTest extends TestCase {
 /**
  * test invoking controller methods.
  *
- * @expectedException \Cake\Controller\Exception\PrivateActionException
- * @expectedExceptionMessage Private Action TestController::redirect() is not directly accessible.
+ * @expectedException \Cake\Controller\Exception\MissingActionException
+ * @expectedExceptionMessage Action TestController::redirect() could not be found, or is not accessible.
  * @return void
  */
 	public function testInvokeActionBaseMethods() {

+ 0 - 9
tests/TestCase/Error/ExceptionRendererTest.php

@@ -18,7 +18,6 @@ use Cake\Controller\Component;
 use Cake\Controller\Controller;
 use Cake\Controller\Exception\MissingActionException;
 use Cake\Controller\Exception\MissingComponentException;
-use Cake\Controller\Exception\PrivateActionException;
 use Cake\Core\App;
 use Cake\Core\Configure;
 use Cake\Core\Exception\MissingPluginException;
@@ -490,14 +489,6 @@ class ExceptionRendererTest extends TestCase {
 				404
 			),
 			array(
-				new PrivateActionException(array('controller' => 'PostsController', 'action' => '_secretSauce')),
-				array(
-					'/<h2>Private Method in PostsController<\/h2>/',
-					'/<em>PostsController::_secretSauce\(\)<\/em>/'
-				),
-				404
-			),
-			array(
 				new MissingViewException(array('file' => '/posts/about.ctp')),
 				array(
 					"/posts\/about.ctp/"