PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/Croogo/Test/Case/Model/Behavior/EncoderBehaviorTest.php

https://github.com/kareypowell/croogo
PHP | 89 lines | 69 code | 10 blank | 10 comment | 0 complexity | bd830a5b27d8147523ea4641d921f1e7 MD5 | raw file
  1. <?php
  2. App::uses('Node', 'Nodes.Model');
  3. App::uses('CroogoTestCase', 'Croogo.TestSuite');
  4. class EncoderBehaviorTest extends CroogoTestCase {
  5. public $fixtures = array(
  6. 'plugin.users.aco',
  7. 'plugin.users.aro',
  8. 'plugin.users.aros_aco',
  9. 'plugin.blocks.block',
  10. 'plugin.comments.comment',
  11. 'plugin.contacts.contact',
  12. 'plugin.translate.i18n',
  13. 'plugin.settings.language',
  14. 'plugin.menus.link',
  15. 'plugin.menus.menu',
  16. 'plugin.contacts.message',
  17. 'plugin.meta.meta',
  18. 'plugin.nodes.node',
  19. 'plugin.taxonomy.model_taxonomy',
  20. 'plugin.blocks.region',
  21. 'plugin.users.role',
  22. 'plugin.settings.setting',
  23. 'plugin.taxonomy.taxonomy',
  24. 'plugin.taxonomy.term',
  25. 'plugin.taxonomy.type',
  26. 'plugin.taxonomy.types_vocabulary',
  27. 'plugin.users.user',
  28. 'plugin.taxonomy.vocabulary',
  29. );
  30. public $Node = null;
  31. /**
  32. * setUp
  33. *
  34. * @return void
  35. */
  36. public function setUp() {
  37. parent::setUp();
  38. $this->Node = ClassRegistry::init('Nodes.Node');
  39. }
  40. /**
  41. * tearDown
  42. *
  43. * @return void
  44. */
  45. public function tearDown() {
  46. parent::tearDown();
  47. unset($this->Node);
  48. ClassRegistry::flush();
  49. }
  50. public function testEncodeWithoutKeys() {
  51. $array = array('hello', 'world');
  52. $encoded = $this->Node->encodeData($array);
  53. $this->assertEqual($encoded, '["hello","world"]');
  54. }
  55. public function testEncodeWithKeys() {
  56. $array = array(
  57. 'first' => 'hello',
  58. 'second' => 'world',
  59. );
  60. $encoded = $this->Node->encodeData($array, array(
  61. 'json' => true,
  62. 'trim' => false,
  63. ));
  64. $this->assertEqual($encoded, '{"first":"hello","second":"world"}');
  65. }
  66. public function testDecodeWithoutKeys() {
  67. $encoded = '["hello","world"]';
  68. $array = $this->Node->decodeData($encoded);
  69. $this->assertEqual($array, array('hello', 'world'));
  70. }
  71. public function testDecodeWithKeys() {
  72. $encoded = '{"first":"hello","second":"world"}';
  73. $array = $this->Node->decodeData($encoded);
  74. $this->assertEqual($array, array(
  75. 'first' => 'hello',
  76. 'second' => 'world',
  77. ));
  78. }
  79. }