22
33namespace Redmine \Tests \Integration ;
44
5- use DOMDocument ;
65use PHPUnit \Framework \TestCase ;
76use Redmine \Tests \Fixtures \MockClient ;
8- use SimpleXMLElement ;
97
108class IssueXmlTest extends TestCase
119{
@@ -24,12 +22,18 @@ public function testCreateBlank()
2422 $ api = $ this ->client ->getApi ('issue ' );
2523 $ this ->assertInstanceOf ('Redmine\Api\Issue ' , $ api );
2624
27- $ xml = '<?xml version="1.0"?>
28- <issue/> ' ;
2925 $ res = $ api ->create ();
30- $ res = json_decode ($ res , true );
31-
32- $ this ->assertEquals ($ this ->formatXml ($ xml ), $ this ->formatXml ($ res ['data ' ]));
26+ $ response = json_decode ($ res , true );
27+
28+ $ this ->assertEquals ('POST ' , $ response ['method ' ]);
29+ $ this ->assertEquals ('/issues.xml ' , $ response ['path ' ]);
30+ $ this ->assertXmlStringEqualsXmlString (
31+ <<< XML
32+ <?xml version="1.0"?>
33+ <issue/>
34+ XML ,
35+ $ response ['data ' ]
36+ );
3337 }
3438
3539 public function testCreateComplexWithUpload ()
@@ -48,23 +52,29 @@ public function testCreateComplexWithUpload()
4852 ],
4953 ],
5054 ]);
51- $ res = json_decode ($ res , true );
52-
53- $ xml = '<?xml version="1.0"?>
54- <issue>
55- <subject>A test issue</subject>
56- <description>Here goes the issue description</description>
57- <project_id>myproject</project_id>
58- <uploads type="array">
59- <upload>
60- <token>asdfasdfasdfasdf</token>
61- <filename>MyFile.pdf</filename>
62- <description>MyFile is better then YourFile...</description>
63- <content_type>application/pdf</content_type>
64- </upload>
65- </uploads>
66- </issue> ' ;
67- $ this ->assertEquals ($ this ->formatXml ($ xml ), $ this ->formatXml ($ res ['data ' ]));
55+ $ response = json_decode ($ res , true );
56+
57+ $ this ->assertEquals ('POST ' , $ response ['method ' ]);
58+ $ this ->assertEquals ('/issues.xml ' , $ response ['path ' ]);
59+ $ this ->assertXmlStringEqualsXmlString (
60+ <<< XML
61+ <?xml version="1.0"?>
62+ <issue>
63+ <subject>A test issue</subject>
64+ <description>Here goes the issue description</description>
65+ <project_id>myproject</project_id>
66+ <uploads type="array">
67+ <upload>
68+ <token>asdfasdfasdfasdf</token>
69+ <filename>MyFile.pdf</filename>
70+ <description>MyFile is better then YourFile...</description>
71+ <content_type>application/pdf</content_type>
72+ </upload>
73+ </uploads>
74+ </issue>
75+ XML ,
76+ $ response ['data ' ]
77+ );
6878 }
6979
7080 public function testCreateComplex ()
@@ -94,21 +104,27 @@ public function testCreateComplex()
94104 ],
95105 'watcher_user_ids ' => [],
96106 ]);
97- $ res = json_decode ($ res , true );
98-
99- $ xml = '<?xml version="1.0"?>
100- <issue>
101- <subject>test api (xml) 3</subject>
102- <description>test api</description>
103- <project_id>test</project_id>
104- <assigned_to_id>1</assigned_to_id>
105- <custom_fields type="array">
106- <custom_field name="Issuer" id="2"><value>asdf</value></custom_field>
107- <custom_field name="Phone" id="5"><value>9939494</value></custom_field>
108- <custom_field name="Email" id="8"><value>asdf@asdf.com</value></custom_field>
109- </custom_fields>
110- </issue> ' ;
111- $ this ->assertEquals ($ this ->formatXml ($ xml ), $ this ->formatXml ($ res ['data ' ]));
107+ $ response = json_decode ($ res , true );
108+
109+ $ this ->assertEquals ('POST ' , $ response ['method ' ]);
110+ $ this ->assertEquals ('/issues.xml ' , $ response ['path ' ]);
111+ $ this ->assertXmlStringEqualsXmlString (
112+ <<< XML
113+ <?xml version="1.0"?>
114+ <issue>
115+ <subject>test api (xml) 3</subject>
116+ <description>test api</description>
117+ <project_id>test</project_id>
118+ <assigned_to_id>1</assigned_to_id>
119+ <custom_fields type="array">
120+ <custom_field name="Issuer" id="2"><value>asdf</value></custom_field>
121+ <custom_field name="Phone" id="5"><value>9939494</value></custom_field>
122+ <custom_field name="Email" id="8"><value>asdf@asdf.com</value></custom_field>
123+ </custom_fields>
124+ </issue>
125+ XML ,
126+ $ response ['data ' ]
127+ );
112128 }
113129
114130 public function testCreateComplexWithLineBreakInDescription ()
@@ -138,22 +154,28 @@ public function testCreateComplexWithLineBreakInDescription()
138154 ],
139155 'watcher_user_ids ' => [],
140156 ]);
141- $ res = json_decode ($ res , true );
142-
143- $ xml = '<?xml version="1.0"?>
144- <issue>
145- <subject>test api (xml) 3</subject>
146- <description>line1
147- line2</description>
148- <project_id>test</project_id>
149- <assigned_to_id>1</assigned_to_id>
150- <custom_fields type="array">
151- <custom_field name="Issuer" id="2"><value>asdf</value></custom_field>
152- <custom_field name="Phone" id="5"><value>9939494</value></custom_field>
153- <custom_field name="Email" id="8"><value>asdf@asdf.com</value></custom_field>
154- </custom_fields>
155- </issue> ' ;
156- $ this ->assertEquals ($ this ->formatXml ($ xml ), $ this ->formatXml ($ res ['data ' ]));
157+ $ response = json_decode ($ res , true );
158+
159+ $ this ->assertEquals ('POST ' , $ response ['method ' ]);
160+ $ this ->assertEquals ('/issues.xml ' , $ response ['path ' ]);
161+ $ this ->assertXmlStringEqualsXmlString (
162+ <<< XML
163+ <?xml version="1.0"?>
164+ <issue>
165+ <subject>test api (xml) 3</subject>
166+ <description>line1
167+ line2</description>
168+ <project_id>test</project_id>
169+ <assigned_to_id>1</assigned_to_id>
170+ <custom_fields type="array">
171+ <custom_field name="Issuer" id="2"><value>asdf</value></custom_field>
172+ <custom_field name="Phone" id="5"><value>9939494</value></custom_field>
173+ <custom_field name="Email" id="8"><value>asdf@asdf.com</value></custom_field>
174+ </custom_fields>
175+ </issue>
176+ XML ,
177+ $ response ['data ' ]
178+ );
157179 }
158180
159181 public function testUpdateIssue ()
@@ -170,42 +192,44 @@ public function testUpdateIssue()
170192 // not testable because this will trigger a status name to id resolving
171193 // 'status' => 'Resolved',
172194 ]);
173- $ res = json_decode ($ res , true );
174-
175- $ xml = '<?xml version="1.0"?>
176- <issue>
177- <id>1</id>
178- <subject>test note (xml) 1</subject>
179- <notes>test note api</notes>
180- <priority_id>5</priority_id>
181- <status_id>2</status_id>
182- <assigned_to_id>1</assigned_to_id>
183- <due_date>2014-05-13</due_date>
184- </issue> ' ;
185- $ this ->assertEquals ($ this ->formatXml ($ xml ), $ this ->formatXml ($ res ['data ' ]));
195+ $ response = json_decode ($ res , true );
196+
197+ $ this ->assertEquals ('PUT ' , $ response ['method ' ]);
198+ $ this ->assertEquals ('/issues/1.xml ' , $ response ['path ' ]);
199+ $ this ->assertXmlStringEqualsXmlString (
200+ <<< XML
201+ <?xml version="1.0"?>
202+ <issue>
203+ <id>1</id>
204+ <subject>test note (xml) 1</subject>
205+ <notes>test note api</notes>
206+ <priority_id>5</priority_id>
207+ <status_id>2</status_id>
208+ <assigned_to_id>1</assigned_to_id>
209+ <due_date>2014-05-13</due_date>
210+ </issue>
211+ XML ,
212+ $ response ['data ' ]
213+ );
186214 }
187215
188216 public function testAddNoteToIssue ()
189217 {
190218 $ api = $ this ->client ->getApi ('issue ' );
191219 $ res = $ api ->addNoteToIssue (1 , 'some comment ' );
192- $ res = json_decode ($ res , true );
193-
194- $ xml = '<?xml version="1.0"?>
195- <issue>
196- <id>1</id>
197- <notes>some comment</notes>
198- </issue> ' ;
199- $ this ->assertEquals ($ this ->formatXml ($ xml ), $ this ->formatXml ($ res ['data ' ]));
200- }
201-
202- private function formatXml ($ xml )
203- {
204- $ dom = new DOMDocument ('1.0 ' );
205- $ dom ->preserveWhiteSpace = false ;
206- $ dom ->formatOutput = true ;
207- $ dom ->loadXML ((new SimpleXMLElement ($ xml ))->asXML ());
208-
209- return $ dom ->saveXML ();
220+ $ response = json_decode ($ res , true );
221+
222+ $ this ->assertEquals ('PUT ' , $ response ['method ' ]);
223+ $ this ->assertEquals ('/issues/1.xml ' , $ response ['path ' ]);
224+ $ this ->assertXmlStringEqualsXmlString (
225+ <<< XML
226+ <?xml version="1.0"?>
227+ <issue>
228+ <id>1</id>
229+ <notes>some comment</notes>
230+ </issue>
231+ XML ,
232+ $ response ['data ' ]
233+ );
210234 }
211235}
0 commit comments