/**
  * Tests maxLength attribute setup by JFormFieldText::setup method
  *
  * @covers JFormField::setup
  * @covers JFormField::__get
  *
  * @return void
  */
 public function testSetupMaxlength()
 {
     $field = new JFormFieldText();
     $element = simplexml_load_string('<field name="myName" type="text" maxlength="60" />');
     $this->assertThat($field->setup($element, ''), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true if successful.');
     $this->assertThat($field->maxLength, $this->equalTo(60), 'Line:' . __LINE__ . ' The property should be computed from the XML.');
 }
	/**
	 * Test the getInput method.
	 *
	 * @return void
	 */
	public function testGetInput()
	{
		$form = new JFormInspector('form1');

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

		$field = new JFormFieldText($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.
	}
示例#3
0
 public function setup(SimpleXMLElement $element, $value, $group = null)
 {
     $this->element = $element;
     $element['label'] = $this->prepareText($element['label']);
     $element['description'] = $this->prepareText($element['description']);
     $element['translateDescription'] = false;
     return parent::setup($element, $value, $group);
 }
示例#4
0
文件: created.php 项目: smhnaji/sdnet
 /**
  * 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)
 {
     $result = parent::setup($element, $value, $group);
     if ($result == true) {
         $this->format = (string) $this->element['format'] ? (string) $this->element['format'] : 'Y-m-d';
     }
     return $result;
 }
示例#5
0
 public function setup(&$element, $value, $group = null)
 {
     $return = parent::setup($element, $value, $group);
     $this->element['class'] = $this->element['class'] . ' color';
     if ($this->element['name'] != 'title_color' and $this->element['name'] != 'date_color') {
         $this->element['onchange'] = 'document.getElementById(\'jform_params_calendar_style\').value=\'custom\'';
     }
     return $return;
 }
示例#6
0
 /**
  * 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;
 }
示例#7
0
 public function setup(SimpleXMLElement $element, $value, $group = null)
 {
     $rt = parent::setup($element, $value, $group);
     $label = (string) $this->element['label'];
     if (empty($label)) {
         $option = JFactory::getApplication()->input->getCmd('option');
         $prefix = $option;
         if ($option == 'com_plugins') {
             $prefix = $this->form->getData()->get('name');
         }
         $label = strtoupper($prefix . '_' . $this->fieldname);
     }
     $this->element['label'] = $label;
     $this->element['description'] = $label . '_DESC';
     $this->description = $label . '_DESC';
     return $rt;
 }
示例#8
0
 /**
  * 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)
 {
     $result = parent::setup($element, $value, $group);
     if ($result == true) {
         // Get the client id.
         $clientId = $this->element['client_id'];
         if (!isset($clientId)) {
             $clientName = $this->element['client'];
             if (isset($clientName)) {
                 $client = JApplicationHelper::getClientInfo($clientName, true);
                 $clientId = $client->id;
             }
         }
         if (!isset($clientId) && $this->form instanceof JForm) {
             $clientId = $this->form->getValue('client_id');
         }
         $this->clientId = (int) $clientId;
     }
     return $result;
 }
示例#9
0
 /**
  * Tests the name, value, id, title, lalbel property setup by JFormField::setup method
  *
  * @param   array   $expected  @todo
  * @param   string  $element   @todo
  * @param   string  $value     @todo
  * @param   string  $group     @todo
  *
  * @return void
  *
  * @dataProvider  getSetupData
  */
 public function testSetup($expected, $element, $value, $group = null)
 {
     $field = new JFormFieldText();
     $element = simplexml_load_string($element);
     $this->assertThat($field->setup($element, $value, $group), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true if successful.');
     // Matcher for the 'label' attribute
     $matcher = array('id' => 'myId-lbl', 'tag' => 'label', 'attributes' => array('for' => 'myId', 'class' => 'hasTooltip', 'title' => '<strong>My Title</strong><br />The description.'), 'content' => 'regexp:/My Title/');
     foreach ($expected as $attr => $value) {
         // Label is html use assertTag()
         if ($attr == 'label') {
             $this->assertTag($matcher, $field->{$attr}, 'Line:' . __LINE__ . ' The ' . $attr . ' property should be computed from the XML.');
         } else {
             $this->assertThat($field->{$attr}, $this->equalTo($value), 'Line:' . __LINE__ . ' The ' . $attr . ' property should be computed from the XML.');
         }
     }
 }
示例#10
0
 public function setup(SimpleXMLElement $element, $value, $group = null)
 {
     $return = parent::setup($element, $value, $group);
     $this->element['class'] = $this->element['class'] . ' color';
     return $return;
 }
 /**
  * Tests the name, value, id, title, lalbel property setup by JFormField::setup method
  *
  * @param   array   $expected  @todo
  * @param   string  $element   @todo
  * @param   string  $value     @todo
  * @param   string  $group     @todo
  *
  * @return void
  *
  * @dataProvider  getSetupData
  */
 public function testSetup($expected, $element, $value, $group = null)
 {
     $field = new JFormFieldText();
     $element = simplexml_load_string($element);
     $this->assertThat($field->setup($element, $value, $group), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true if successful.');
     foreach ($expected as $attr => $value) {
         $this->assertThat($field->{$attr}, $this->equalTo($value), 'Line:' . __LINE__ . ' The ' . $attr . ' property should be computed from the XML.');
     }
 }