2008-08-09 05:19:54 +02:00
|
|
|
<?php
|
|
|
|
|
2009-09-10 08:34:40 +02:00
|
|
|
class ControllerTest extends FunctionalTest {
|
2012-05-04 11:55:40 +02:00
|
|
|
|
2011-03-30 08:49:11 +02:00
|
|
|
static $fixture_file = 'ControllerTest.yml';
|
2012-05-04 11:55:40 +02:00
|
|
|
|
|
|
|
protected $autoFollowRedirection = false;
|
2008-08-09 05:19:54 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDefaultAction() {
|
2008-08-09 05:19:54 +02:00
|
|
|
/* For a controller with a template, the default action will simple run that template. */
|
2009-09-10 08:34:40 +02:00
|
|
|
$response = $this->get("ControllerTest_Controller/");
|
2008-11-24 20:28:46 +01:00
|
|
|
$this->assertRegExp("/This is the main template. Content is 'default content'/", $response->getBody());
|
2008-08-09 05:19:54 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testMethodActions() {
|
2012-09-26 23:34:00 +02:00
|
|
|
/* The Action can refer to a method that is called on the object. If a method returns an array, then it
|
|
|
|
* will be used to customise the template data */
|
2009-09-10 08:34:40 +02:00
|
|
|
$response = $this->get("ControllerTest_Controller/methodaction");
|
2008-11-24 20:28:46 +01:00
|
|
|
$this->assertRegExp("/This is the main template. Content is 'methodaction content'./", $response->getBody());
|
2008-08-09 05:19:54 +02:00
|
|
|
|
|
|
|
/* If the method just returns a string, then that will be used as the response */
|
2009-09-10 08:34:40 +02:00
|
|
|
$response = $this->get("ControllerTest_Controller/stringaction");
|
2008-11-24 20:28:46 +01:00
|
|
|
$this->assertRegExp("/stringaction was called./", $response->getBody());
|
2008-08-09 05:19:54 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testTemplateActions() {
|
2008-08-09 05:19:54 +02:00
|
|
|
/* If there is no method, it can be used to point to an alternative template. */
|
2009-09-10 08:34:40 +02:00
|
|
|
$response = $this->get("ControllerTest_Controller/templateaction");
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertRegExp("/This is the template for templateaction. Content is 'default content'./",
|
|
|
|
$response->getBody());
|
2008-08-09 05:19:54 +02:00
|
|
|
}
|
2009-10-11 02:07:01 +02:00
|
|
|
|
|
|
|
public function testUndefinedActions() {
|
2013-01-15 00:34:05 +01:00
|
|
|
$response = Director::test('ControllerTest_AccessUnsecuredSubController/undefinedaction');
|
2009-10-11 02:07:01 +02:00
|
|
|
$this->assertEquals(404, $response->getStatusCode(), 'Undefined actions return a not found response.');
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testAllowedActions() {
|
2009-09-10 08:34:40 +02:00
|
|
|
$adminUser = $this->objFromFixture('Member', 'admin');
|
|
|
|
|
2013-01-15 00:34:05 +01:00
|
|
|
$response = $this->get("ControllerTest_AccessBaseController/unsecuredaction");
|
|
|
|
$this->assertEquals(200, $response->getStatusCode(),
|
|
|
|
'Access granted on action without $allowed_actions on defining controller'
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->get("ControllerTest_AccessBaseController/onlysecuredinsubclassaction");
|
|
|
|
$this->assertEquals(200, $response->getStatusCode(),
|
|
|
|
'Access granted on action without $allowed_actions on defining controller, ' .
|
|
|
|
'even when action is secured in subclasses'
|
|
|
|
);
|
2008-08-09 05:19:54 +02:00
|
|
|
|
2013-01-15 00:34:05 +01:00
|
|
|
$response = $this->get("ControllerTest_AccessSecuredController/onlysecuredinsubclassaction");
|
|
|
|
$this->assertEquals(403, $response->getStatusCode(),
|
|
|
|
'Access denied on action with $allowed_actions on defining controller, ' .
|
|
|
|
'even if action is unsecured on parent class'
|
|
|
|
);
|
2008-08-09 05:19:54 +02:00
|
|
|
|
2013-06-10 11:51:35 +02:00
|
|
|
$response = $this->get("ControllerTest_AccessSecuredController/templateaction");
|
|
|
|
$this->assertEquals(403, $response->getStatusCode(),
|
|
|
|
'Access denied on action with $allowed_actions on defining controller, ' .
|
|
|
|
'if action is not a method but rather a template discovered by naming convention'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->session()->inst_set('loggedInAs', $adminUser->ID);
|
|
|
|
$response = $this->get("ControllerTest_AccessSecuredController/templateaction");
|
|
|
|
$this->assertEquals(200, $response->getStatusCode(),
|
|
|
|
'Access granted for logged in admin on action with $allowed_actions on defining controller, ' .
|
|
|
|
'if action is not a method but rather a template discovered by naming convention'
|
|
|
|
);
|
|
|
|
$this->session()->inst_set('loggedInAs', null);
|
|
|
|
|
2013-01-15 00:34:05 +01:00
|
|
|
$response = $this->get("ControllerTest_AccessSecuredController/adminonly");
|
|
|
|
$this->assertEquals(403, $response->getStatusCode(),
|
|
|
|
'Access denied on action with $allowed_actions on defining controller, ' .
|
|
|
|
'when action is not defined on any parent classes'
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->get("ControllerTest_AccessSecuredController/aDmiNOnlY");
|
|
|
|
$this->assertEquals(403, $response->getStatusCode(),
|
|
|
|
'Access denied on action with $allowed_actions on defining controller, ' .
|
|
|
|
'regardless of capitalization'
|
|
|
|
);
|
2009-03-21 06:10:05 +01:00
|
|
|
|
2013-01-15 00:34:05 +01:00
|
|
|
// TODO Change this API
|
|
|
|
$response = $this->get('ControllerTest_AccessUnsecuredSubController/unsecuredaction');
|
2009-04-02 18:34:27 +02:00
|
|
|
$this->assertEquals(200, $response->getStatusCode(),
|
2013-01-15 00:34:05 +01:00
|
|
|
"Controller without a specified allowed_actions allows its own actions through"
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->get('ControllerTest_AccessUnsecuredSubController/adminonly');
|
|
|
|
$this->assertEquals(403, $response->getStatusCode(),
|
|
|
|
"Controller without a specified allowed_actions still disallows actions defined on parents"
|
2009-04-02 18:34:27 +02:00
|
|
|
);
|
|
|
|
|
2013-01-15 00:34:05 +01:00
|
|
|
$response = $this->get("ControllerTest_AccessAsteriskSecuredController/index");
|
2009-09-10 03:37:44 +02:00
|
|
|
$this->assertEquals(403, $response->getStatusCode(),
|
|
|
|
"Actions can be globally disallowed by using asterisk (*) for index method"
|
|
|
|
);
|
|
|
|
|
2013-01-15 00:34:05 +01:00
|
|
|
$response = $this->get("ControllerTest_AccessAsteriskSecuredController/onlysecuredinsubclassaction");
|
2012-06-14 08:45:12 +02:00
|
|
|
$this->assertEquals(404, $response->getStatusCode(),
|
2013-01-15 00:34:05 +01:00
|
|
|
"Actions can be globally disallowed by using asterisk (*) instead of a method name, " .
|
|
|
|
"in which case they'll be marked as 'not found'"
|
2009-04-02 18:34:27 +02:00
|
|
|
);
|
|
|
|
|
2013-01-15 00:34:05 +01:00
|
|
|
$response = $this->get("ControllerTest_AccessAsteriskSecuredController/unsecuredaction");
|
2009-04-02 18:34:27 +02:00
|
|
|
$this->assertEquals(200, $response->getStatusCode(),
|
|
|
|
"Actions can be overridden to be allowed if globally disallowed by using asterisk (*)"
|
|
|
|
);
|
2009-09-10 08:34:40 +02:00
|
|
|
|
|
|
|
$this->session()->inst_set('loggedInAs', $adminUser->ID);
|
2013-01-15 00:34:05 +01:00
|
|
|
$response = $this->get("ControllerTest_AccessSecuredController/adminonly");
|
2009-09-10 08:34:40 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
200,
|
|
|
|
$response->getStatusCode(),
|
|
|
|
"Permission codes are respected when set in \$allowed_actions"
|
|
|
|
);
|
2012-06-14 08:45:12 +02:00
|
|
|
|
2013-01-15 00:34:05 +01:00
|
|
|
$response = $this->get("ControllerTest_AccessUnsecuredSubController/adminonly");
|
2012-06-14 08:45:12 +02:00
|
|
|
$this->assertEquals(200, $response->getStatusCode(),
|
|
|
|
"Actions can be globally disallowed by using asterisk (*) instead of a method name"
|
|
|
|
);
|
2013-01-15 00:34:05 +01:00
|
|
|
|
2012-06-14 08:45:12 +02:00
|
|
|
$this->session()->inst_set('loggedInAs', null);
|
2008-08-09 05:19:54 +02:00
|
|
|
}
|
2008-08-28 06:25:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test Controller::join_links()
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testJoinLinks() {
|
2012-09-26 23:34:00 +02:00
|
|
|
/* Controller::join_links() will reliably join two URL-segments together so that they will be
|
|
|
|
* appropriately parsed by the URL parser */
|
2008-08-28 06:25:13 +02:00
|
|
|
$this->assertEquals("admin/crm/MyForm", Controller::join_links("admin/crm", "MyForm"));
|
|
|
|
$this->assertEquals("admin/crm/MyForm", Controller::join_links("admin/crm/", "MyForm"));
|
|
|
|
|
|
|
|
/* It will also handle appropriate combination of querystring variables */
|
|
|
|
$this->assertEquals("admin/crm/MyForm?flush=1", Controller::join_links("admin/crm/?flush=1", "MyForm"));
|
|
|
|
$this->assertEquals("admin/crm/MyForm?flush=1", Controller::join_links("admin/crm/", "MyForm?flush=1"));
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals("admin/crm/MyForm?field=1&other=1",
|
|
|
|
Controller::join_links("admin/crm/?field=1", "MyForm?other=1"));
|
2008-08-28 06:25:13 +02:00
|
|
|
|
|
|
|
/* It can handle arbitrary numbers of components, and will ignore empty ones */
|
|
|
|
$this->assertEquals("admin/crm/MyForm/", Controller::join_links("admin/", "crm", "", "MyForm/"));
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals("admin/crm/MyForm/?a=1&b=2",
|
|
|
|
Controller::join_links("admin/?a=1", "crm", "", "MyForm/?b=2"));
|
2008-08-28 06:25:13 +02:00
|
|
|
|
|
|
|
/* It can also be used to attach additional get variables to a link */
|
|
|
|
$this->assertEquals("admin/crm?flush=1", Controller::join_links("admin/crm", "?flush=1"));
|
|
|
|
$this->assertEquals("admin/crm?existing=1&flush=1", Controller::join_links("admin/crm?existing=1", "?flush=1"));
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals("admin/crm/MyForm?a=1&b=2&c=3",
|
|
|
|
Controller::join_links("?a=1", "admin/crm", "?b=2", "MyForm?c=3"));
|
2008-08-28 06:25:13 +02:00
|
|
|
|
|
|
|
/* Note, however, that it doesn't deal with duplicates very well. */
|
|
|
|
$this->assertEquals("admin/crm?flush=1&flush=1", Controller::join_links("admin/crm?flush=1", "?flush=1"));
|
2009-10-11 02:07:15 +02:00
|
|
|
|
|
|
|
$this->assertEquals (
|
|
|
|
'admin/action', Controller::join_links('admin/', '/', '/action'), 'Test that multiple slashes are trimmed.'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals('/admin/action', Controller::join_links('/admin', 'action'));
|
2010-10-15 02:29:29 +02:00
|
|
|
|
|
|
|
/* One fragment identifier is handled as you would expect */
|
|
|
|
$this->assertEquals("my-page?arg=var#subsection", Controller::join_links("my-page#subsection", "?arg=var"));
|
|
|
|
|
|
|
|
/* If there are multiple, it takes the last one */
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals("my-page?arg=var#second-section",
|
|
|
|
Controller::join_links("my-page#subsection", "?arg=var", "#second-section"));
|
2012-03-08 21:41:17 +01:00
|
|
|
|
|
|
|
/* Does type-safe checks for zero value */
|
|
|
|
$this->assertEquals("my-page/0", Controller::join_links("my-page", 0));
|
2008-08-28 06:25:13 +02:00
|
|
|
}
|
2009-10-11 02:07:23 +02:00
|
|
|
|
|
|
|
/**
|
2010-10-15 04:52:20 +02:00
|
|
|
* @covers Controller::hasAction
|
2009-10-11 02:07:23 +02:00
|
|
|
*/
|
|
|
|
public function testHasAction() {
|
|
|
|
$controller = new ControllerTest_HasAction();
|
|
|
|
|
2010-10-13 05:30:54 +02:00
|
|
|
$this->assertFalse($controller->hasAction('1'), 'Numeric actions do not slip through.');
|
2012-09-26 23:34:00 +02:00
|
|
|
//$this->assertFalse($controller->hasAction('lowercase_permission'),
|
|
|
|
//'Lowercase permission does not slip through.');
|
2009-10-11 02:07:23 +02:00
|
|
|
$this->assertFalse($controller->hasAction('undefined'), 'undefined actions do not exist');
|
|
|
|
$this->assertTrue($controller->hasAction('allowed_action'), 'allowed actions are recognised');
|
|
|
|
$this->assertTrue($controller->hasAction('template_action'), 'action-specific templates are recognised');
|
2009-10-11 02:07:24 +02:00
|
|
|
|
|
|
|
$unsecured = new ControllerTest_HasAction_Unsecured();
|
|
|
|
|
|
|
|
$this->assertTrue (
|
|
|
|
$unsecured->hasAction('defined_action'),
|
|
|
|
'Without an allowed_actions, any defined methods are recognised as actions'
|
|
|
|
);
|
2009-10-11 02:07:23 +02:00
|
|
|
}
|
2012-02-11 03:08:39 +01:00
|
|
|
|
2012-09-26 23:34:00 +02:00
|
|
|
/* Controller::BaseURL no longer exists, but was just a direct call to Director::BaseURL, so not sure what this
|
|
|
|
* code was supposed to test
|
2010-12-11 03:01:13 +01:00
|
|
|
public function testBaseURL() {
|
|
|
|
Director::setBaseURL('/baseurl/');
|
|
|
|
$this->assertEquals(Controller::BaseURL(), Director::BaseURL());
|
|
|
|
}
|
2012-02-11 03:08:39 +01:00
|
|
|
*/
|
2012-05-04 11:55:40 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testRedirectBackByReferer() {
|
2012-05-04 11:55:40 +02:00
|
|
|
$internalRelativeUrl = '/some-url';
|
2012-09-26 23:34:00 +02:00
|
|
|
$response = $this->get('ControllerTest_Controller/redirectbacktest', null,
|
|
|
|
array('Referer' => $internalRelativeUrl));
|
2012-05-04 11:55:40 +02:00
|
|
|
$this->assertEquals(302, $response->getStatusCode());
|
|
|
|
$this->assertEquals($internalRelativeUrl, $response->getHeader('Location'),
|
|
|
|
"Redirects on internal relative URLs"
|
|
|
|
);
|
|
|
|
|
|
|
|
$internalAbsoluteUrl = Director::absoluteBaseURL() . '/some-url';
|
2012-09-26 23:34:00 +02:00
|
|
|
$response = $this->get('ControllerTest_Controller/redirectbacktest', null,
|
|
|
|
array('Referer' => $internalAbsoluteUrl));
|
2012-05-04 11:55:40 +02:00
|
|
|
$this->assertEquals(302, $response->getStatusCode());
|
|
|
|
$this->assertEquals($internalAbsoluteUrl, $response->getHeader('Location'),
|
|
|
|
"Redirects on internal absolute URLs"
|
|
|
|
);
|
|
|
|
|
|
|
|
$externalAbsoluteUrl = 'http://myhost.com/some-url';
|
2012-09-26 23:34:00 +02:00
|
|
|
$response = $this->get('ControllerTest_Controller/redirectbacktest', null,
|
|
|
|
array('Referer' => $externalAbsoluteUrl));
|
2012-05-04 11:55:40 +02:00
|
|
|
$this->assertEquals(200, $response->getStatusCode(),
|
|
|
|
"Doesn't redirect on external URLs"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testRedirectBackByBackUrl() {
|
2012-05-04 11:55:40 +02:00
|
|
|
$internalRelativeUrl = '/some-url';
|
|
|
|
$response = $this->get('ControllerTest_Controller/redirectbacktest?BackURL=' . urlencode($internalRelativeUrl));
|
|
|
|
$this->assertEquals(302, $response->getStatusCode());
|
|
|
|
$this->assertEquals($internalRelativeUrl, $response->getHeader('Location'),
|
|
|
|
"Redirects on internal relative URLs"
|
|
|
|
);
|
|
|
|
|
|
|
|
$internalAbsoluteUrl = Director::absoluteBaseURL() . '/some-url';
|
|
|
|
$response = $this->get('ControllerTest_Controller/redirectbacktest?BackURL=' . urlencode($internalAbsoluteUrl));
|
|
|
|
$this->assertEquals($internalAbsoluteUrl, $response->getHeader('Location'));
|
|
|
|
$this->assertEquals(302, $response->getStatusCode(),
|
|
|
|
"Redirects on internal absolute URLs"
|
|
|
|
);
|
|
|
|
|
|
|
|
$externalAbsoluteUrl = 'http://myhost.com/some-url';
|
|
|
|
$response = $this->get('ControllerTest_Controller/redirectbacktest?BackURL=' . urlencode($externalAbsoluteUrl));
|
|
|
|
$this->assertEquals(200, $response->getStatusCode(),
|
|
|
|
"Doesn't redirect on external URLs"
|
|
|
|
);
|
|
|
|
}
|
2008-08-09 05:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simple controller for testing
|
|
|
|
*/
|
2011-02-13 23:14:51 +01:00
|
|
|
class ControllerTest_Controller extends Controller implements TestOnly {
|
2008-08-09 05:19:54 +02:00
|
|
|
public $Content = "default content";
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function methodaction() {
|
2008-08-09 05:19:54 +02:00
|
|
|
return array(
|
|
|
|
"Content" => "methodaction content"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function stringaction() {
|
2008-08-09 05:19:54 +02:00
|
|
|
return "stringaction was called.";
|
|
|
|
}
|
2012-05-04 11:55:40 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function redirectbacktest() {
|
2012-05-04 11:55:40 +02:00
|
|
|
return $this->redirectBack();
|
|
|
|
}
|
2008-08-09 05:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-15 00:34:05 +01:00
|
|
|
* Allowed actions flattened:
|
|
|
|
* - unsecuredaction: *
|
|
|
|
* - onlysecuredinsubclassaction: *
|
|
|
|
* - unsecuredinparentclassaction: *
|
|
|
|
* - unsecuredinsubclassaction: *
|
|
|
|
*/
|
|
|
|
class ControllerTest_AccessBaseController extends Controller implements TestOnly {
|
|
|
|
// Accessible by all
|
|
|
|
public function unsecuredaction() {
|
|
|
|
return 'unsecuredaction was called.';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Accessible by all
|
|
|
|
public function onlysecuredinsubclassaction() {
|
|
|
|
return 'onlysecuredinsubclass was called.';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Accessible by all
|
|
|
|
public function unsecuredinparentclassaction() {
|
|
|
|
return 'unsecuredinparentclassaction was called.';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Accessible by all
|
|
|
|
public function unsecuredinsubclassaction() {
|
|
|
|
return 'unsecuredinsubclass was called.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allowed actions flattened:
|
|
|
|
* - unsecuredaction: *
|
|
|
|
* - onlysecuredinsubclassaction: ADMIN (parent: *)
|
|
|
|
* - unsecuredinparentclassaction: *
|
|
|
|
* - unsecuredinsubclassaction: (none) (parent: *)
|
|
|
|
* - adminonly: ADMIN
|
2008-08-09 05:19:54 +02:00
|
|
|
*/
|
2013-01-15 00:34:05 +01:00
|
|
|
class ControllerTest_AccessSecuredController extends ControllerTest_AccessBaseController implements TestOnly {
|
|
|
|
|
2008-08-09 05:19:54 +02:00
|
|
|
static $allowed_actions = array(
|
2013-01-15 00:34:05 +01:00
|
|
|
"onlysecuredinsubclassaction" => 'ADMIN',
|
2008-08-09 05:19:54 +02:00
|
|
|
"adminonly" => "ADMIN",
|
2013-06-10 11:51:35 +02:00
|
|
|
// Defined as ControllerTest_templateaction
|
|
|
|
'templateaction' => 'ADMIN'
|
|
|
|
);
|
|
|
|
|
|
|
|
protected $templates = array(
|
|
|
|
'templateaction' => 'ControllerTest_templateaction'
|
2008-08-09 05:19:54 +02:00
|
|
|
);
|
2013-01-15 00:34:05 +01:00
|
|
|
|
|
|
|
// Accessible by ADMIN only
|
|
|
|
public function onlysecuredinsubclassaction() {
|
|
|
|
return 'onlysecuredinsubclass was called.';
|
2008-08-09 05:19:54 +02:00
|
|
|
}
|
2013-01-15 00:34:05 +01:00
|
|
|
|
|
|
|
// Not accessible, since overloaded but not mentioned in $allowed_actions
|
|
|
|
public function unsecuredinsubclassaction() {
|
|
|
|
return 'unsecuredinsubclass was called.';
|
2008-08-09 05:19:54 +02:00
|
|
|
}
|
|
|
|
|
2013-01-15 00:34:05 +01:00
|
|
|
// Accessible by all, since only defined in parent class
|
|
|
|
//public function unsecuredinparentclassaction() {
|
|
|
|
|
|
|
|
// Accessible by ADMIN only
|
2012-09-19 12:07:39 +02:00
|
|
|
public function adminonly() {
|
2008-08-09 05:19:54 +02:00
|
|
|
return "You must be an admin!";
|
|
|
|
}
|
2013-06-10 11:51:35 +02:00
|
|
|
|
2009-03-21 06:10:05 +01:00
|
|
|
}
|
|
|
|
|
2013-01-15 00:34:05 +01:00
|
|
|
/**
|
|
|
|
* Allowed actions flattened:
|
|
|
|
* - unsecuredaction: *
|
|
|
|
* - onlysecuredinsubclassaction: ADMIN (parent: *)
|
|
|
|
* - unsecuredinparentclassaction: ADMIN (parent: *)
|
|
|
|
* - unsecuredinsubclassaction: (none) (parent: *)
|
|
|
|
* - adminonly: ADMIN (parent: ADMIN)
|
|
|
|
*/
|
|
|
|
class ControllerTest_AccessAsteriskSecuredController extends ControllerTest_AccessBaseController implements TestOnly {
|
2009-04-02 18:34:27 +02:00
|
|
|
|
|
|
|
static $allowed_actions = array(
|
|
|
|
"*" => "ADMIN",
|
|
|
|
'unsecuredaction' => true,
|
|
|
|
);
|
|
|
|
|
2013-01-15 00:34:05 +01:00
|
|
|
// Accessible by ADMIN only
|
2012-09-19 12:07:39 +02:00
|
|
|
public function adminonly() {
|
2009-04-02 18:34:27 +02:00
|
|
|
return "You must be an admin!";
|
|
|
|
}
|
|
|
|
|
2013-01-15 00:34:05 +01:00
|
|
|
// Accessible by all
|
2012-09-19 12:07:39 +02:00
|
|
|
public function unsecuredaction() {
|
2009-04-02 18:34:27 +02:00
|
|
|
return "Allowed for everybody";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-15 00:34:05 +01:00
|
|
|
/**
|
|
|
|
* Allowed actions flattened:
|
|
|
|
* - unsecuredaction: *
|
|
|
|
* - onlysecuredinsubclassaction: ADMIN (parent: *)
|
|
|
|
* - unsecuredinparentclassaction: *
|
|
|
|
* - unsecuredinsubclassaction: (none) (parent: *)
|
|
|
|
* - adminonly: ADMIN
|
|
|
|
*/
|
|
|
|
class ControllerTest_AccessUnsecuredSubController extends ControllerTest_AccessSecuredController implements TestOnly {
|
|
|
|
|
|
|
|
// No $allowed_actions defined here
|
|
|
|
|
|
|
|
// Accessible by ADMIN only, defined in parent class
|
|
|
|
public function onlysecuredinsubclassaction() {
|
|
|
|
return 'onlysecuredinsubclass was called.';
|
|
|
|
}
|
|
|
|
}
|
2009-10-11 02:07:23 +02:00
|
|
|
|
|
|
|
class ControllerTest_HasAction extends Controller {
|
|
|
|
|
|
|
|
public static $allowed_actions = array (
|
2010-10-13 05:39:04 +02:00
|
|
|
'allowed_action',
|
2010-10-13 05:39:36 +02:00
|
|
|
//'other_action' => 'lowercase_permission'
|
2009-10-11 02:07:23 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
protected $templates = array (
|
|
|
|
'template_action' => 'template'
|
|
|
|
);
|
|
|
|
|
2009-10-11 02:07:24 +02:00
|
|
|
}
|
|
|
|
|
2011-02-13 23:14:51 +01:00
|
|
|
class ControllerTest_HasAction_Unsecured extends ControllerTest_HasAction implements TestOnly {
|
2009-10-11 02:07:24 +02:00
|
|
|
|
|
|
|
public function defined_action() { }
|
|
|
|
|
2010-12-11 03:01:13 +01:00
|
|
|
}
|