Skip to content

Commit 9ff2eed

Browse files
committed
IHF: array_to_xml helper tests added.
1 parent 2f6f38f commit 9ff2eed

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

tests/xml/ArrayToXmlTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
class ArrayToXmlTest extends TestCase
4+
{
5+
/** @test */
6+
public function it_converts_array_to_xml()
7+
{
8+
$array = [
9+
'task' => [
10+
0 => [
11+
'to' => 'John',
12+
'from' => 'Jane',
13+
'title' => 'Go to the shop',
14+
],
15+
1 => [
16+
'to' => 'John',
17+
'from' => 'Paul',
18+
'title' => 'Finish the report',
19+
],
20+
2 => [
21+
'to' => 'Jane',
22+
'from' => 'Jeff',
23+
'title' => 'Clean the house',
24+
],
25+
],
26+
];
27+
28+
$expected = file_get_contents(__DIR__ . '/ArrayToXmlTest/without-attributes.xml');
29+
30+
$this->assertEquals($expected, array_to_xml($array));
31+
}
32+
33+
/** @test */
34+
public function is_supports_xml_attributes_in_converting()
35+
{
36+
$array = [
37+
'task' => [
38+
0 => [
39+
'to' => 'John',
40+
'from' => 'Jane',
41+
'title' => 'Go to the shop',
42+
'_attributes' => [
43+
'priority' => 'low',
44+
],
45+
],
46+
1 => [
47+
'to' => 'John',
48+
'from' => 'Paul',
49+
'title' => 'Finish the report',
50+
'_attributes' => [
51+
'priority' => 'medium',
52+
],
53+
],
54+
2 => [
55+
'to' => 'Jane',
56+
'from' => 'Jeff',
57+
'title' => 'Clean the house',
58+
'_attributes' => [
59+
'priority' => 'high',
60+
],
61+
],
62+
],
63+
];
64+
65+
$expected = file_get_contents(__DIR__ . '/ArrayToXmlTest/with-attributes.xml');
66+
67+
$this->assertEquals($expected, array_to_xml($array));
68+
}
69+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0"?>
2+
<root><task priority="low"><to>John</to><from>Jane</from><title>Go to the shop</title></task><task priority="medium"><to>John</to><from>Paul</from><title>Finish the report</title></task><task priority="high"><to>Jane</to><from>Jeff</from><title>Clean the house</title></task></root>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0"?>
2+
<root><task><to>John</to><from>Jane</from><title>Go to the shop</title></task><task><to>John</to><from>Paul</from><title>Finish the report</title></task><task><to>Jane</to><from>Jeff</from><title>Clean the house</title></task></root>

0 commit comments

Comments
 (0)