Пример #1
0
	/**
	 * Test the getInput method.
	 */
	public function testGetInput()
	{
		$form = new JFormInspector('form1');

		$this->assertThat(
			$form->load('<form><field name="checkbox" type="checkbox" /></form>'),
			$this->isTrue(),
			'Line:'.__LINE__.' XML string should load successfully.'
		);

		$field = new JFormFieldCheckbox($form);

		$this->assertThat(
			$field->setup($form->getXml()->field, 'value'),
			$this->isTrue(),
			'Line:'.__LINE__.' The setup method should return true.'
		);

		$this->assertThat(
			strlen($field->input),
			$this->greaterThan(0),
			'Line:'.__LINE__.' The getInput method should return something without error.'
		);

		// TODO: Should check all the attributes have come in properly.
	}
 /**
  * Tests checked attribute setup by JFormField::setup method
  *
  * @covers JFormFieldCheckbox::setup
  * @covers JFormField::__get
  *
  * @return void
  */
 public function testSetupChecked()
 {
     $field = new JFormFieldCheckbox();
     $element = simplexml_load_string('<field name="myName" type="checkbox" checked="true" />');
     $this->assertThat($field->setup($element, ''), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true if successful.');
     $this->assertThat($field->checked, $this->isTrue(), 'Line:' . __LINE__ . ' The property should be computed from the XML.');
 }
Пример #3
0
 protected function getInput()
 {
     JLoader::register('JEVHelper', JPATH_SITE . "/components/com_jevents/libraries/helper.php");
     JEVHelper::ConditionalFields($this->element, $this->form->getName());
     $input = parent::getInput();
     return $input;
 }
Пример #4
0
 /**
  * Method to get certain otherwise inaccessible properties from the form field object.
  *
  * @param   string  $name  The property name for which to the the value.
  *
  * @return  mixed  The property value or null.
  *
  * @since   2.0
  */
 public function __get($name)
 {
     switch ($name) {
         case 'static':
             if (empty($this->static)) {
                 $this->static = $this->getStatic();
             }
             return $this->static;
             break;
         case 'repeatable':
             if (empty($this->repeatable)) {
                 $this->repeatable = $this->getRepeatable();
             }
             return $this->repeatable;
             break;
         default:
             return parent::__get($name);
     }
 }
Пример #5
0
 /**
  * Method to get the field input markup.
  * Adds the remaining fields for the database connection to the form
  *
  * @return  string  The field input markup
  * @since   3.1
  */
 protected function getInput()
 {
     $numberOfFields = 6;
     $this->form->loadFile('database');
     // Remove field 'prefix' is required
     $prefix = (string) $this->element['prefix'];
     if ($prefix == 'false' || $prefix == '0') {
         $this->form->removeField('prefix', 'db');
         $numberOfFields--;
     }
     // If second database connection is required remove
     // checkbox and change 'required' field attributes
     if ($this->required) {
         $this->form->removeField('database');
         $this->form->setFieldAttribute('db_type', 'required', 'true', 'db');
         $this->form->setFieldAttribute('db_host', 'required', 'true', 'db');
         $this->form->setFieldAttribute('db_user', 'required', 'true', 'db');
         $this->form->setFieldAttribute('db_name', 'required', 'true', 'db');
         $this->form->setFieldAttribute('prefix', 'required', 'true', 'db');
     }
     // Create individual IDs for each of the fields
     $id = str_replace('database_', '', $this->id);
     $this->form->setFieldAttribute('enabled', 'id', 'enabled_' . $id, 'db');
     $this->form->setFieldAttribute('db_type', 'id', 'db_type_' . $id, 'db');
     $this->form->setFieldAttribute('db_host', 'id', 'db_host_' . $id, 'db');
     $this->form->setFieldAttribute('db_user', 'id', 'db_user_' . $id, 'db');
     $this->form->setFieldAttribute('db_pass', 'id', 'db_pass_' . $id, 'db');
     $this->form->setFieldAttribute('db_name', 'id', 'db_name_' . $id, 'db');
     $this->form->setFieldAttribute('prefix', 'id', 'prefix_' . $id, 'db');
     $script = 'var group = jQuery(\'#' . $this->id . '\').parent().parent();';
     $script .= 'for(var i = 0; i < ' . $numberOfFields . '; i++){group = group.next();group.toggleClass(\'hide\');}';
     if (!$this->value && !isset($this->form->joomScriptLoaded)) {
         JFactory::getDocument()->addScriptDeclaration('jQuery(document).ready(function(){
   if(!jQuery(\'#' . $this->id . '\').prop(\'checked\')){jQuery(\'#db_enabled_' . $id . '\').val(\'0\');
   ' . $script . '}else{jQuery(\'#db_enabled_' . $id . '\').val(\'1\');}});');
         $this->form->joomScriptLoaded = true;
     }
     $this->element['onclick'] = $script . 'jQuery(\'#db_enabled_' . $id . '\').val(1 - jQuery(\'#db_enabled_' . $id . '\').val());';
     return parent::getInput();
 }