/** * Test addChild(). * * @covers ::addChild * @test */ public function testAddChildWithIntegerValue() { // Test values $newElementName = 'newTestChild'; $newElementValue = 125; // Perform tests $xmlElement = new SimpleXMLElement('<?xml version="1.0"?><issue></issue>'); $node = $xmlElement->addChild($newElementName, $newElementValue); $this->assertSame($newElementName, $node->getName()); $this->assertSame('125', current($node)); }
/** * Attaches Custom Fields to a create/update query * * @param SimpleXMLElement $xml XML Element the custom fields are attached to * @param array $fields array of fields to attach, each field needs name, id and value set * @return $xml Element * @see http://www.redmine.org/projects/redmine/wiki/Rest_api#Working-with-custom-fields */ protected function attachCustomFieldXML(SimpleXMLElement $xml, array $fields) { $_fields = $xml->addChild('custom_fields'); $_fields->addAttribute('type', 'array'); foreach ($fields as $field) { $_field = $_fields->addChild('custom_field'); if (isset($field['name'])) { $_field->addAttribute('name', $field['name']); } $_field->addAttribute('id', $field['id']); $_field->addChild('value', $field['value']); } return $xml; }
/** * Attaches Custom Fields to a create/update query. * * @param \SimpleXMLElement $xml XML Element the custom fields are attached to * @param array $fields array of fields to attach, each field needs name, id and value set * * @return \SimpleXMLElement $xml * * @see http://www.redmine.org/projects/redmine/wiki/Rest_api#Working-with-custom-fields */ protected function attachCustomFieldXML(\SimpleXMLElement $xml, array $fields) { $_fields = $xml->addChild('custom_fields'); $_fields->addAttribute('type', 'array'); foreach ($fields as $field) { $_field = $_fields->addChild('custom_field'); if (isset($field['name'])) { $_field->addAttribute('name', $field['name']); } if (isset($field['field_format'])) { $_field->addAttribute('field_format', $field['field_format']); } $_field->addAttribute('id', $field['id']); if (is_array($field['value'])) { $_field->addAttribute('multiple', 'true'); $_values = $_field->addChild('value'); $_values->addAttribute('type', 'array'); foreach ($field['value'] as $val) { $_values->addChild('value', $val); } } else { $_field->addChild('value', $field['value']); } } return $xml; }
/** * Attaches Custom Fields to a create/update query * * @param SimpleXMLElement $xml XML Element the custom fields are attached to * @param array $fields array of fields to attach, each field needs name, id and value set * @return $xml Element * @see http://www.redmine.org/projects/redmine/wiki/Rest_api#Working-with-custom-fields */ protected function attachCustomFieldXML($xml, $fields) { $fieldsXML = $xml->addChild('custom_fields'); $fieldsXML->addAttribute('type', 'array'); foreach ($fields as $field) { $fieldXML = $fieldsXML->addChild('custom_field'); $fieldXML->addAttribute('name', $field['name']); $fieldXML->addAttribute('id', $field['id']); $fieldXML->addChild('value', $field['value']); } return $xml; }