format.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * Part of the Fuel framework.
  4. *
  5. * @package Fuel
  6. * @version 1.5
  7. * @author Fuel Development Team
  8. * @license MIT License
  9. * @copyright 2010 - 2013 Fuel Development Team
  10. * @link http://fuelphp.com
  11. */
  12. namespace Fuel\Core;
  13. /**
  14. * Format class tests
  15. *
  16. * @group Core
  17. * @group Format
  18. */
  19. class Test_Format extends TestCase
  20. {
  21. public static function array_provider()
  22. {
  23. return array(
  24. array(
  25. array(
  26. array('field1' => 'Value 1', 'field2' => 35, 'field3' => 123123),
  27. array('field1' => 'Value 1', 'field2' => "Value\nline 2", 'field3' => 'Value 3'),
  28. ),
  29. '"field1","field2","field3"
  30. "Value 1","35","123123"
  31. "Value 1","Value
  32. line 2","Value 3"',
  33. ),
  34. );
  35. }
  36. /**
  37. * Test for Format::forge($foo, 'csv')->to_array()
  38. *
  39. * @test
  40. * @dataProvider array_provider
  41. */
  42. public function test_from_csv($array, $csv)
  43. {
  44. $this->assertEquals($array, Format::forge($csv, 'csv')->to_array());
  45. }
  46. /**
  47. * Test for Format::forge($foo)->to_csv()
  48. *
  49. * @test
  50. * @dataProvider array_provider
  51. */
  52. public function test_to_csv($array, $csv)
  53. {
  54. $this->assertEquals($csv, Format::forge($array)->to_csv());
  55. }
  56. /**
  57. * Test for Format::forge($foo)->_from_xml()
  58. *
  59. * @test
  60. */
  61. public function test__from_xml()
  62. {
  63. $xml = '<?xml version="1.0" encoding="UTF-8"?>
  64. <phpunit colors="true" stopOnFailure="false" bootstrap="bootstrap_phpunit.php">
  65. <php>
  66. <server name="doc_root" value="../../"/>
  67. <server name="app_path" value="fuel/app"/>
  68. <server name="core_path" value="fuel/core"/>
  69. <server name="package_path" value="fuel/packages"/>
  70. </php>
  71. <testsuites>
  72. <testsuite name="core">
  73. <directory suffix=".php">../core/tests</directory>
  74. </testsuite>
  75. <testsuite name="packages">
  76. <directory suffix=".php">../packages/*/tests</directory>
  77. </testsuite>
  78. <testsuite name="app">
  79. <directory suffix=".php">../app/tests</directory>
  80. </testsuite>
  81. </testsuites>
  82. </phpunit>';
  83. $expected = array (
  84. '@attributes' => array (
  85. 'colors' => 'true',
  86. 'stopOnFailure' => 'false',
  87. 'bootstrap' => 'bootstrap_phpunit.php',
  88. ),
  89. 'php' => array (
  90. 'server' => array (
  91. 0 => array (
  92. '@attributes' => array (
  93. 'name' => 'doc_root',
  94. 'value' => '../../',
  95. ),
  96. ),
  97. 1 => array (
  98. '@attributes' => array (
  99. 'name' => 'app_path',
  100. 'value' => 'fuel/app',
  101. ),
  102. ),
  103. 2 => array (
  104. '@attributes' => array (
  105. 'name' => 'core_path',
  106. 'value' => 'fuel/core',
  107. ),
  108. ),
  109. 3 => array (
  110. '@attributes' => array (
  111. 'name' => 'package_path',
  112. 'value' => 'fuel/packages',
  113. ),
  114. ),
  115. ),
  116. ),
  117. 'testsuites' => array (
  118. 'testsuite' => array (
  119. 0 => array (
  120. '@attributes' => array (
  121. 'name' => 'core',
  122. ),
  123. 'directory' => '../core/tests',
  124. ),
  125. 1 => array (
  126. '@attributes' =>
  127. array (
  128. 'name' => 'packages',
  129. ),
  130. 'directory' => '../packages/*/tests',
  131. ),
  132. 2 => array (
  133. '@attributes' =>
  134. array (
  135. 'name' => 'app',
  136. ),
  137. 'directory' => '../app/tests',
  138. ),
  139. ),
  140. ),
  141. );
  142. $this->assertEquals(Format::forge($expected)->to_php(), Format::forge($xml, 'xml')->to_php());
  143. }
  144. function test_to_array_empty()
  145. {
  146. $array = null;
  147. $expected = array();
  148. $this->assertEquals($expected, Format::forge($array)->to_array());
  149. }
  150. }