/** * Test for JForm::setFields method. * * @return void */ public function testSetFields() { $form = new JFormInspector('form1'); $this->assertTrue($form->load(JFormDataHelper::$loadDocument), 'Line:' . __LINE__ . ' XML string should load successfully.'); $xml1 = simplexml_load_string('<form><field name="title" required="true" /><field name="ordering" /></form>'); if ($xml1 === false) { $this->fail('Error in text XML data'); } $addFields = array(); foreach ($xml1->field as $element) { $addFields[] = $element; } // Test without replace. $this->assertTrue($form->setFields($addFields, null, false), 'Line:' . __LINE__ . ' The setFields method should return true for an existing field.'); $this->assertEquals($form->getFieldAttribute('title', 'required', 'default'), 'default', 'Line:' . __LINE__ . ' The getFieldAttribute method should return the default value if the attribute is not set.'); $this->assertNotFalse($form->getField('ordering'), 'Line:' . __LINE__ . ' The getField method does not return false when the field exists.'); }
/** * Test for JForm::setFields method. * * @return void */ public function testSetFields() { $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" /><field name="ordering" /></form>'); if ($xml1 === false) { $this->fail('Error in text XML data'); } // Test without replace. $this->assertThat( $form->setFields($xml1->field, null, false), $this->isTrue(), 'Line:' . __LINE__ . ' The setFields method should return true.' ); $this->assertThat( $form->getFieldAttribute('title', 'required', 'default'), $this->equalTo('default'), 'Line:' . __LINE__ . ' The label should contain just the field name.' ); $this->assertThat( $form->getField('ordering'), $this->logicalNot($this->isFalse()), 'Line:' . __LINE__ . ' The label should contain just the field name.' ); }