function testDateFormValid() { $field = new Member_DatetimeOptionsetField('DateFormat', 'DateFormat'); $this->assertTrue($field->validate()); $_POST['DateFormat_custom'] = 'dd MM yyyy'; $this->assertTrue($field->validate()); $_POST['DateFormat_custom'] = 'sdfdsfdfd1244'; $this->assertFalse($field->validate()); }
/** * Return a {@link FieldSet} of fields that would appropriate for editing * this member. * * @return FieldSet Return a FieldSet of fields that would appropriate for * editing this member. */ public function getCMSFields() { require_once 'Zend/Date.php'; $fields = parent::getCMSFields(); $mainFields = $fields->fieldByName("Root")->fieldByName("Main")->Children; $password = new ConfirmedPasswordField('Password', null, null, null, true); $password->setCanBeEmpty(true); if (!$this->ID) { $password->showOnClick = false; } $mainFields->replaceField('Password', $password); $mainFields->insertBefore(new HeaderField('MemberDetailsHeader', _t('Member.PERSONALDETAILS', "Personal Details", PR_MEDIUM, 'Headline for formfields')), 'FirstName'); $mainFields->insertBefore(new HeaderField('MemberUserDetailsHeader', _t('Member.USERDETAILS', "User Details", PR_MEDIUM, 'Headline for formfields')), 'Email'); $mainFields->replaceField('Locale', new DropdownField("Locale", _t('Member.INTERFACELANG', "Interface Language", PR_MEDIUM, 'Language of the CMS'), i18n::get_existing_translations())); $mainFields->removeByName('Bounced'); $mainFields->removeByName('RememberLoginToken'); $mainFields->removeByName('AutoLoginHash'); $mainFields->removeByName('AutoLoginExpired'); $mainFields->removeByName('PasswordEncryption'); $mainFields->removeByName('PasswordExpiry'); $mainFields->removeByName('LockedOutUntil'); if (!self::$lock_out_after_incorrect_logins) { $mainFields->removeByName('FailedLoginCount'); } $mainFields->removeByName('Salt'); $mainFields->removeByName('NumVisit'); $mainFields->removeByName('LastVisited'); $fields->removeByName('Subscriptions'); // Groups relation will get us into logical conflicts because // Members are displayed within group edit form in SecurityAdmin $fields->removeByName('Groups'); if (Permission::check('EDIT_PERMISSIONS')) { $groupsField = new TreeMultiselectField('Groups', false, 'Group'); $fields->findOrMakeTab('Root.Groups', singleton('Group')->i18n_plural_name()); $fields->addFieldToTab('Root.Groups', $groupsField); // Add permission field (readonly to avoid complicated group assignment logic). // This should only be available for existing records, as new records start // with no permissions until they have a group assignment anyway. if ($this->ID) { $permissionsField = new PermissionCheckboxSetField_Readonly('Permissions', singleton('Permission')->i18n_plural_name(), 'Permission', 'GroupID', $this->getManyManyComponents('Groups')); $fields->findOrMakeTab('Root.Permissions', singleton('Permission')->i18n_plural_name()); $fields->addFieldToTab('Root.Permissions', $permissionsField); } } $defaultDateFormat = Zend_Locale_Format::getDateFormat($this->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) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default')); $mainFields->push($dateFormatField = new Member_DatetimeOptionsetField('DateFormat', $this->fieldLabel('DateFormat'), $dateFormatMap)); $dateFormatField->setValue($this->DateFormat); $defaultTimeFormat = Zend_Locale_Format::getTimeFormat($this->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) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default')); $mainFields->push($timeFormatField = new Member_DatetimeOptionsetField('TimeFormat', $this->fieldLabel('TimeFormat'), $timeFormatMap)); $timeFormatField->setValue($this->TimeFormat); $this->extend('updateCMSFields', $fields); return $fields; }