Merge remote-tracking branch 'refs/remotes/origin/master' into pull-159

This commit is contained in:
Sam Minnee 2012-01-10 15:51:20 +13:00
commit 23959888d7
3 changed files with 133 additions and 28 deletions

0
sake Normal file → Executable file
View File

View File

@ -618,34 +618,6 @@ class Security extends Controller {
return new ChangePasswordForm($this, 'ChangePasswordForm');
}
/**
* Authenticate using the given email and password, returning the
* appropriate member object if
*
* @return bool|Member Returns FALSE if authentication fails, otherwise
* the member object
* @see setDefaultAdmin()
*/
public static function authenticate($RAW_email, $RAW_password) {
$SQL_email = Convert::raw2sql($RAW_email);
$SQL_password = Convert::raw2sql($RAW_password);
// Default login (see {@setDetaultAdmin()})
if(($RAW_email == self::$default_username) && ($RAW_password == self::$default_password)
&& !empty(self::$default_username) && !empty(self::$default_password)) {
$member = self::findAnAdministrator();
} else {
$member = DataObject::get_one("Member", "\"" . Member::get_unique_identifier_field() . "\" = '$SQL_email' AND \"Password\" IS NOT NULL");
if($member && ($member->checkPassword($RAW_password) == false)) {
$member = null;
}
}
return $member;
}
/**
* Return an existing member with administrator privileges, or create one of necessary.
*

View File

@ -0,0 +1,133 @@
<?php
/**
* Test the API for creating GridField_URLHandler compeonnts
*/
class GridField_URLHandlerTest extends FunctionalTest {
function testFormSubmission() {
$result = $this->get("GridField_URLHandlerTest_Controller/Form/field/Grid/showform");
$formResult = $this->submitForm('Form_Form', 'action_doAction', array('Test' => 'foo bar') );
$this->assertEquals("Submitted foo bar to component", $formResult->getBody());
}
function testNestedRequestHandlerFormSubmission() {
$result = $this->get("GridField_URLHandlerTest_Controller/Form/field/Grid/item/3/showform");
$formResult = $this->submitForm('Form_Form', 'action_doAction', array('Test' => 'foo bar') );
$this->assertEquals("Submitted foo bar to item #3", $formResult->getBody());
}
function testURL() {
$result = $this->get("GridField_URLHandlerTest_Controller/Form/field/Grid/testpage");
$this->assertEquals("Test page for component", $result->getBody());
}
function testNestedRequestHandlerURL() {
$result = $this->get("GridField_URLHandlerTest_Controller/Form/field/Grid/item/5/testpage");
$this->assertEquals("Test page for item #5", $result->getBody());
}
}
class GridField_URLHandlerTest_Controller extends Controller implements TestOnly {
function Link() {
return get_class($this) ."/";
}
function Form() {
$gridConfig = GridFieldConfig::create();
$gridConfig->addComponent(new GridField_URLHandlerTest_Component());
$gridData = new ArrayList();
$gridField = new GridField('Grid', 'My grid', $gridData, $gridConfig);
return new Form($this, 'Form', new FieldList(
$gridField
), new FieldList());
}
}
/**
* Test URLHandler with a nested request handler
*/
class GridField_URLHandlerTest_Component extends RequestHandler implements GridField_URLHandler {
protected $gridField;
function getURLHandlers($gridField) {
return array(
'showform' => 'showform',
'testpage' => 'testpage',
'Form' => 'Form',
'item/$ID' => 'handleItem',
);
}
function handleItem($gridField, $request) {
$id = $request->param("ID");
return new GridField_URLHandlerTest_Component_ItemRequest(
$gridField, $id,
Controller::join_links($gridField->Link(), 'item/' . $id));
}
function Link() {
return $this->gridField->Link();
}
function showform($gridField, $request) {
return "<head>" . SSViewer::get_base_tag("") . "</head>" . $this->Form($gridField, $request)->forTemplate();
}
function Form($gridField, $request) {
$this->gridField = $gridField;
return new Form($this, 'Form', new FieldList(
new TextField("Test")
), new FieldList(
new FormAction('doAction', 'Go')
));
}
function doAction($data, $form) {
return "Submitted " . $data['Test'] . " to component";
}
function testpage($gridField, $request) {
return "Test page for component";
}
}
class GridField_URLHandlerTest_Component_ItemRequest extends RequestHandler {
protected $gridField;
protected $link;
protected $id;
function __construct($gridField, $id, $link) {
$this->gridField = $gridField;
$this->id = $id;
$this->link = $link;
parent::__construct();
}
function Link() {
return $this->link;
}
function showform() {
return "<head>" . SSViewer::get_base_tag("") . "</head>" . $this->Form()->forTemplate();
}
function Form() {
return new Form($this, 'Form', new FieldList(
new TextField("Test")
), new FieldList(
new FormAction('doAction', 'Go')
));
}
function doAction($data, $form) {
return "Submitted " . $data['Test'] . " to item #" . $this->id;
}
function testpage() {
return "Test page for item #" . $this->id;
}
}