2010-10-15 05:23:02 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2010-10-15 05:23:02 +02:00
|
|
|
* @subpackage forms
|
|
|
|
*/
|
|
|
|
class MemberDatetimeOptionsetFieldTest extends SapphireTest {
|
|
|
|
|
2011-03-30 08:49:11 +02:00
|
|
|
public static $fixture_file = 'MemberDatetimeOptionsetFieldTest.yml';
|
2010-10-15 05:23:02 +02:00
|
|
|
|
|
|
|
protected function createDateFormatFieldForMember($member) {
|
|
|
|
require_once 'Zend/Date.php';
|
|
|
|
$defaultDateFormat = Zend_Locale_Format::getDateFormat($member->Locale);
|
|
|
|
$dateFormatMap = array(
|
|
|
|
'MMM d, yyyy' => Zend_Date::now()->toString('MMM d, yyyy'),
|
|
|
|
'yyyy/MM/dd' => Zend_Date::now()->toString('yyyy/MM/dd'),
|
|
|
|
'MM/dd/yyyy' => Zend_Date::now()->toString('MM/dd/yyyy'),
|
|
|
|
'dd/MM/yyyy' => Zend_Date::now()->toString('dd/MM/yyyy'),
|
|
|
|
);
|
|
|
|
$dateFormatMap[$defaultDateFormat] = Zend_Date::now()->toString($defaultDateFormat) . ' (default)';
|
2011-12-23 10:30:49 +01:00
|
|
|
$field = new MemberDatetimeOptionsetField(
|
2010-10-15 05:23:02 +02:00
|
|
|
'DateFormat',
|
|
|
|
'Date format',
|
|
|
|
$dateFormatMap
|
|
|
|
);
|
|
|
|
$field->setValue($member->DateFormat);
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function createTimeFormatFieldForMember($member) {
|
|
|
|
require_once 'Zend/Date.php';
|
|
|
|
$defaultTimeFormat = Zend_Locale_Format::getTimeFormat($member->Locale);
|
|
|
|
$timeFormatMap = array(
|
|
|
|
'h:mm a' => Zend_Date::now()->toString('h:mm a'),
|
|
|
|
'H:mm' => Zend_Date::now()->toString('H:mm'),
|
|
|
|
);
|
|
|
|
$timeFormatMap[$defaultTimeFormat] = Zend_Date::now()->toString($defaultTimeFormat) . ' (default)';
|
2011-12-23 10:30:49 +01:00
|
|
|
$field = new MemberDatetimeOptionsetField(
|
2010-10-15 05:23:02 +02:00
|
|
|
'TimeFormat',
|
|
|
|
'Time format',
|
|
|
|
$timeFormatMap
|
|
|
|
);
|
|
|
|
$field->setValue($member->TimeFormat);
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDateFormatDefaultCheckedInFormField() {
|
2010-10-15 05:23:02 +02:00
|
|
|
$field = $this->createDateFormatFieldForMember($this->objFromFixture('Member', 'noformatmember'));
|
2012-09-26 23:34:00 +02:00
|
|
|
$field->setForm(new Form(new MemberDatetimeOptionsetFieldTest_Controller(), 'Form', new FieldList(),
|
|
|
|
new FieldList())); // fake form
|
2010-10-15 05:23:02 +02:00
|
|
|
$parser = new CSSContentParser($field->Field());
|
2011-05-30 11:33:27 +02:00
|
|
|
$xmlArr = $parser->getBySelector('#Form_Form_DateFormat_MMM_d__y');
|
2010-10-15 05:23:02 +02:00
|
|
|
$this->assertEquals('checked', (string) $xmlArr[0]['checked']);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testTimeFormatDefaultCheckedInFormField() {
|
2010-10-15 05:23:02 +02:00
|
|
|
$field = $this->createTimeFormatFieldForMember($this->objFromFixture('Member', 'noformatmember'));
|
2012-09-26 23:34:00 +02:00
|
|
|
$field->setForm(new Form(new MemberDatetimeOptionsetFieldTest_Controller(), 'Form', new FieldList(),
|
|
|
|
new FieldList())); // fake form
|
2010-10-15 05:23:02 +02:00
|
|
|
$parser = new CSSContentParser($field->Field());
|
2011-05-30 11:33:27 +02:00
|
|
|
$xmlArr = $parser->getBySelector('#Form_Form_TimeFormat_h_mm_ss_a');
|
2010-10-15 05:23:02 +02:00
|
|
|
$this->assertEquals('checked', (string) $xmlArr[0]['checked']);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDateFormatChosenIsCheckedInFormField() {
|
2010-10-15 05:23:02 +02:00
|
|
|
$member = $this->objFromFixture('Member', 'noformatmember');
|
|
|
|
$member->setField('DateFormat', 'MM/dd/yyyy');
|
|
|
|
$field = $this->createDateFormatFieldForMember($member);
|
2012-09-26 23:34:00 +02:00
|
|
|
$field->setForm(new Form(new MemberDatetimeOptionsetFieldTest_Controller(), 'Form', new FieldList(),
|
|
|
|
new FieldList())); // fake form
|
2010-10-15 05:23:02 +02:00
|
|
|
$parser = new CSSContentParser($field->Field());
|
2010-10-19 00:34:09 +02:00
|
|
|
$xmlArr = $parser->getBySelector('#Form_Form_DateFormat_MM_dd_yyyy');
|
2010-10-15 05:23:02 +02:00
|
|
|
$this->assertEquals('checked', (string) $xmlArr[0]['checked']);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDateFormatCustomFormatAppearsInCustomInputInField() {
|
2010-10-15 05:23:02 +02:00
|
|
|
$member = $this->objFromFixture('Member', 'noformatmember');
|
|
|
|
$member->setField('DateFormat', 'dd MM yy');
|
|
|
|
$field = $this->createDateFormatFieldForMember($member);
|
2012-09-26 23:34:00 +02:00
|
|
|
$field->setForm(new Form(new MemberDatetimeOptionsetFieldTest_Controller(), 'Form', new FieldList(),
|
|
|
|
new FieldList())); // fake form
|
2010-10-15 05:23:02 +02:00
|
|
|
$parser = new CSSContentParser($field->Field());
|
|
|
|
$xmlInputArr = $parser->getBySelector('.valCustom input');
|
|
|
|
$xmlPreview = $parser->getBySelector('.preview');
|
|
|
|
$this->assertEquals('checked', (string) $xmlInputArr[0]['checked']);
|
|
|
|
$this->assertEquals('dd MM yy', (string) $xmlInputArr[1]['value']);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDateFormValid() {
|
2011-12-23 10:30:49 +01:00
|
|
|
$field = new MemberDatetimeOptionsetField('DateFormat', 'DateFormat');
|
2012-04-12 02:20:18 +02:00
|
|
|
$this->assertTrue($field->validate(null));
|
2010-10-15 05:23:02 +02:00
|
|
|
$_POST['DateFormat_custom'] = 'dd MM yyyy';
|
2012-04-12 02:20:18 +02:00
|
|
|
$this->assertTrue($field->validate(null));
|
2010-10-15 05:23:02 +02:00
|
|
|
$_POST['DateFormat_custom'] = 'sdfdsfdfd1244';
|
2012-04-12 02:20:18 +02:00
|
|
|
$this->assertFalse($field->validate(null));
|
2010-10-15 05:23:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
class MemberDatetimeOptionsetFieldTest_Controller extends Controller {
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Link() {
|
2010-10-15 05:23:02 +02:00
|
|
|
return 'test';
|
|
|
|
}
|
|
|
|
|
2012-04-12 02:20:18 +02:00
|
|
|
}
|