|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Redmine\Tests; |
| 4 | + |
| 5 | +use Redmine\Client; |
| 6 | +use Redmine\TestClient; |
| 7 | + |
| 8 | +class IssueXmlTest extends \PHPUnit_Framework_TestCase |
| 9 | +{ |
| 10 | + private $client; |
| 11 | + |
| 12 | + public function setup() |
| 13 | + { |
| 14 | + $this->client = new TestClient('http://test.local', 'asdf'); |
| 15 | + } |
| 16 | + |
| 17 | + public function testCreateBlank() |
| 18 | + { |
| 19 | + $this->assertInstanceOf('Redmine\Api\Issue', $this->client->api('issue')); |
| 20 | + |
| 21 | + $xml = '<?xml version="1.0"?> |
| 22 | +<issue/>'; |
| 23 | + $res = $this->client->api('issue')->create(); |
| 24 | + $this->assertEquals($this->formatXml($xml), $this->formatXml($res)); |
| 25 | + } |
| 26 | + |
| 27 | + public function testCreateComplex() |
| 28 | + { |
| 29 | + $res = $this->client->api('issue')->create(array( |
| 30 | + 'project_id' => 'test', |
| 31 | + 'subject' => 'test api (xml) 3', |
| 32 | + 'description' => 'test api', |
| 33 | + 'assigned_to_id' => 1, |
| 34 | + 'custom_fields' => array( |
| 35 | + array( |
| 36 | + 'id' => 2, |
| 37 | + 'name' => 'Issuer', |
| 38 | + 'value' => 'asdf', |
| 39 | + ), |
| 40 | + array( |
| 41 | + 'id' => 5, |
| 42 | + 'name' => 'Phone', |
| 43 | + 'value' => '9939494', |
| 44 | + ), |
| 45 | + array( |
| 46 | + 'id' => '8', |
| 47 | + 'name' => 'Email', |
| 48 | + |
| 49 | + ), |
| 50 | + ), |
| 51 | + 'watcher_user_ids' => array(), |
| 52 | + )); |
| 53 | + |
| 54 | + $xml = '<?xml version="1.0"?> |
| 55 | +<issue> |
| 56 | + <subject>test api (xml) 3</subject> |
| 57 | + <description>test api</description> |
| 58 | + <project_id>test</project_id> |
| 59 | + <assigned_to_id>1</assigned_to_id> |
| 60 | + <custom_fields type="array"> |
| 61 | + <custom_field name="Issuer" id="2"><value>asdf</value></custom_field> |
| 62 | + <custom_field name="Phone" id="5"><value>9939494</value></custom_field> |
| 63 | + <custom_field name="Email" id="8"><value>[email protected]</value></custom_field> |
| 64 | + </custom_fields> |
| 65 | +</issue>'; |
| 66 | + $this->assertEquals($this->formatXml($xml), $this->formatXml($res)); |
| 67 | + } |
| 68 | + |
| 69 | + public function testUpdateIssue() |
| 70 | + { |
| 71 | + $res = $this->client->api('issue')->update(1, array( |
| 72 | + 'subject' => 'test note (xml) 1', |
| 73 | + 'notes' => 'test note api', |
| 74 | + 'assigned_to_id' => 1, |
| 75 | + 'status_id' => 2, |
| 76 | + 'priority_id' => 5, |
| 77 | + 'due_date' => date('Y-m-d'), |
| 78 | + |
| 79 | + // not testable because this will trigger a status name to id resolving |
| 80 | + // 'status' => 'Resolved', |
| 81 | + )); |
| 82 | + $xml = '<?xml version="1.0"?> |
| 83 | +<issue> |
| 84 | + <id>1</id> |
| 85 | + <subject>test note (xml) 1</subject> |
| 86 | + <notes>test note api</notes> |
| 87 | + <priority_id>5</priority_id> |
| 88 | + <status_id>2</status_id> |
| 89 | + <assigned_to_id>1</assigned_to_id> |
| 90 | + <due_date>2014-05-13</due_date> |
| 91 | +</issue>'; |
| 92 | + $this->assertEquals($this->formatXml($xml), $this->formatXml($res)); |
| 93 | + } |
| 94 | + |
| 95 | + public function testAddNoteToIssue() |
| 96 | + { |
| 97 | + $res = $this->client->api('issue')->addNoteToIssue(1, 'some comment'); |
| 98 | + $xml = '<?xml version="1.0"?> |
| 99 | +<issue> |
| 100 | + <id>1</id> |
| 101 | + <notes>some comment</notes> |
| 102 | +</issue>'; |
| 103 | + $this->assertEquals($this->formatXml($xml), $this->formatXml($res)); |
| 104 | + } |
| 105 | + |
| 106 | + private function formatXml($xml) |
| 107 | + { |
| 108 | + $dom = new \DOMDocument('1.0'); |
| 109 | + $dom->preserveWhiteSpace = false; |
| 110 | + $dom->formatOutput = true; |
| 111 | + $dom->loadXML((new \SimpleXMLElement($xml))->asXML()); |
| 112 | + |
| 113 | + return $dom->saveXML(); |
| 114 | + } |
| 115 | +} |
0 commit comments