/** * Test for JForm::setField method. * * @return void */ public function testSetField() { $form = new JFormInspector('form1'); $this->assertThat($form->load(JFormDataHelper::$loadDocument), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $xml1 = simplexml_load_string('<form><field name="title" required="true" /></form>'); if ($xml1 === false) { $this->fail('Error in text XML data'); } // Test without replace. $this->assertThat($form->setField($xml1->field[0], null, false), $this->isTrue(), 'Line:' . __LINE__ . ' The setField method should return true.'); $this->assertThat($form->getFieldAttribute('title', 'required', 'default'), $this->equalTo('default'), 'Line:' . __LINE__ . ' The label should contain just the field name.'); // Test with replace. $this->assertThat($form->setField($xml1->field[0], null, true), $this->isTrue(), 'Line:' . __LINE__ . ' The setField method should return true.'); $this->assertThat($form->getFieldAttribute('title', 'required', 'default'), $this->equalTo('true'), 'Line:' . __LINE__ . ' The label should contain just the new label.'); }