|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Redmine\Tests; |
| 4 | + |
| 5 | +use Redmine\Client; |
| 6 | +use Redmine\TestClient; |
| 7 | + |
| 8 | +class ProjectXmlTest 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 | + /** |
| 18 | + * @expectedException Exception |
| 19 | + */ |
| 20 | + public function testCreateBlank() |
| 21 | + { |
| 22 | + $this->assertInstanceOf('Redmine\Api\Project', $this->client->api('project')); |
| 23 | + |
| 24 | + $xml = '<?xml version="1.0"?> |
| 25 | +<project/>'; |
| 26 | + $res = $this->client->api('project')->create(); |
| 27 | + $this->assertEquals($this->formatXml($xml), $this->formatXml($res)); |
| 28 | + } |
| 29 | + |
| 30 | + public function testCreateComplex() |
| 31 | + { |
| 32 | + $res = $this->client->api('project')->create(array( |
| 33 | + 'name' => 'some name', |
| 34 | + 'identifier' => 'the_identifier', |
| 35 | + )); |
| 36 | + |
| 37 | + $xml = '<?xml version="1.0"?> |
| 38 | +<project> |
| 39 | + <name>some name</name> |
| 40 | + <identifier>the_identifier</identifier> |
| 41 | +</project>'; |
| 42 | + $this->assertEquals($this->formatXml($xml), $this->formatXml($res)); |
| 43 | + } |
| 44 | + |
| 45 | + public function testCreateComplexWithTrackerIds() |
| 46 | + { |
| 47 | + $res = $this->client->api('project')->create(array( |
| 48 | + 'name' => 'some name', |
| 49 | + 'identifier' => 'the_identifier', |
| 50 | + 'tracker_ids' => array( |
| 51 | + 1, 2, 3 |
| 52 | + ), |
| 53 | + )); |
| 54 | + |
| 55 | + $xml = '<?xml version="1.0"?> |
| 56 | +<project> |
| 57 | + <name>some name</name> |
| 58 | + <identifier>the_identifier</identifier> |
| 59 | + <tracker_ids type="array"> |
| 60 | + <tracker>1</tracker> |
| 61 | + <tracker>2</tracker> |
| 62 | + <tracker>3</tracker> |
| 63 | + </tracker_ids> |
| 64 | +</project>'; |
| 65 | + $this->assertEquals($this->formatXml($xml), $this->formatXml($res)); |
| 66 | + } |
| 67 | + |
| 68 | + public function testUpdate() |
| 69 | + { |
| 70 | + $res = $this->client->api('project')->update(1, array( |
| 71 | + 'name' => 'different name', |
| 72 | + )); |
| 73 | + |
| 74 | + $xml = '<?xml version="1.0"?> |
| 75 | +<project> |
| 76 | + <id>1</id> |
| 77 | + <name>different name</name> |
| 78 | +</project>'; |
| 79 | + $this->assertEquals($this->formatXml($xml), $this->formatXml($res)); |
| 80 | + } |
| 81 | + |
| 82 | + private function formatXml($xml) |
| 83 | + { |
| 84 | + $dom = new \DOMDocument('1.0'); |
| 85 | + $dom->preserveWhiteSpace = false; |
| 86 | + $dom->formatOutput = true; |
| 87 | + $dom->loadXML((new \SimpleXMLElement($xml))->asXML()); |
| 88 | + |
| 89 | + return $dom->saveXML(); |
| 90 | + } |
| 91 | +} |
0 commit comments