示例#1
0
 /**
  * Test the JForm::mergeNode method.
  *
  * @return void
  */
 public function testMergeNodes()
 {
     // The source data.
     $xml1 = simplexml_load_string('<form><fields><field name="foo" /></fields></form>');
     // The new data for adding the field.
     $xml2 = simplexml_load_string('<form><fields><field name="foo" type="text" /><field name="soap" /></fields></form>');
     if ($xml1 === false || $xml2 === false) {
         $this->fail('Line:' . __LINE__ . ' Error in text XML data');
     }
     JFormInspector::mergeNodes($xml1->fields, $xml2->fields);
     $this->assertThat(count($xml1->xpath('fields/field')), $this->equalTo(2), 'Line:' . __LINE__ . ' The merge should have two field tags, one existing, one new.');
     $this->assertThat(count($xml1->xpath('fields/field[@name="foo"] | fields/field[@type="text"]')), $this->equalTo(1), 'Line:' . __LINE__ . ' A field of the same name should merge.');
     $this->assertThat(count($xml1->xpath('fields/field[@name="soap"]')), $this->equalTo(1), 'Line:' . __LINE__ . ' A new field should be added.');
 }