Example #1
0
 public function setup(&$element, $value, $group = null)
 {
     if (isset($element->content) && empty($value)) {
         $value = $element->content;
     }
     return parent::setup($element, $value, $group);
 }
	/**
	 * Test the getInput method.
	 *
	 * @return void
	 */
	public function testGetInput()
	{
		$form = new JFormInspector('form1');

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

		$field = new JFormFieldTextarea($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 rows and columns attribute setup by JFormFieldTextare::setup method
  *
  * @covers JFormField::setup
  * @covers JFormField::__get
  *
  * @return void
  */
 public function testSetupRowsColumns()
 {
     $field = new JFormFieldTextarea();
     $element = simplexml_load_string('<field name="myName" type="textarea" rows="60" cols="70" />');
     $this->assertThat($field->setup($element, ''), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true if successful.');
     $this->assertThat($field->rows, $this->equalTo(60), 'Line:' . __LINE__ . '  The property should be computed from the XML.');
     $this->assertThat($field->columns, $this->equalTo(70), 'Line:' . __LINE__ . ' The property should be computed from the XML.');
 }
 /**
  * Method to attach a JForm object to the field.
  *
  * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  * @param   mixed             $value    The form field value to validate.
  * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  *                                      For example if the field has name="foo" and the group value is set to "bar" then the
  *                                      full field name would end up being "bar[foo]".
  *
  * @return  boolean  True on success.
  *
  * @see     JFormField::setup()
  * @since   3.2
  */
 public function setup(SimpleXMLElement $element, $value, $group = null)
 {
     $return = parent::setup($element, $value, $group);
     if ($return) {
         $this->countertext = isset($this->element['countertext']) ? (string) $this->element['countertext'] : '';
         $this->countertext = JText::_($this->countertext);
         $this->maxlength = isset($this->element['maxlength']) ? (int) $this->element['maxlength'] : 0;
         $this->class .= ' charcounter';
     }
     return $return;
 }
 public function setup(SimpleXMLElement $element, $value, $group = null)
 {
     $result = parent::setup($element, $value, $group);
     if ($result == true) {
         $this->height = $this->element['height'] ? (string) $this->element['height'] : '500';
         $this->width = $this->element['width'] ? (string) $this->element['width'] : '100%';
         $this->assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id';
         $this->authorField = $this->element['created_by_field'] ? (string) $this->element['created_by_field'] : 'created_by';
         $this->asset = $this->form->getValue($this->assetField) ? $this->form->getValue($this->assetField) : (string) $this->element['asset_id'];
         $buttons = (string) $this->element['buttons'];
         $hide = (string) $this->element['hide'];
         $editorType = (string) $this->element['editor'];
         if ($buttons == 'true' || $buttons == 'yes' || $buttons == '1') {
             $this->buttons = true;
         } elseif ($buttons == 'false' || $buttons == 'no' || $buttons == '0') {
             $this->buttons = false;
         } else {
             $this->buttons = !empty($hide) ? explode(',', $buttons) : array();
         }
         $this->hide = !empty($hide) ? explode(',', (string) $this->element['hide']) : array();
         $this->editorType = !empty($editorType) ? explode('|', trim($editorType)) : array();
     }
     return $result;
 }