/Croogo/Test/Case/Model/Behavior/EncoderBehaviorTest.php
PHP | 89 lines | 69 code | 10 blank | 10 comment | 0 complexity | bd830a5b27d8147523ea4641d921f1e7 MD5 | raw file
- <?php
- App::uses('Node', 'Nodes.Model');
- App::uses('CroogoTestCase', 'Croogo.TestSuite');
- class EncoderBehaviorTest extends CroogoTestCase {
- public $fixtures = array(
- 'plugin.users.aco',
- 'plugin.users.aro',
- 'plugin.users.aros_aco',
- 'plugin.blocks.block',
- 'plugin.comments.comment',
- 'plugin.contacts.contact',
- 'plugin.translate.i18n',
- 'plugin.settings.language',
- 'plugin.menus.link',
- 'plugin.menus.menu',
- 'plugin.contacts.message',
- 'plugin.meta.meta',
- 'plugin.nodes.node',
- 'plugin.taxonomy.model_taxonomy',
- 'plugin.blocks.region',
- 'plugin.users.role',
- 'plugin.settings.setting',
- 'plugin.taxonomy.taxonomy',
- 'plugin.taxonomy.term',
- 'plugin.taxonomy.type',
- 'plugin.taxonomy.types_vocabulary',
- 'plugin.users.user',
- 'plugin.taxonomy.vocabulary',
- );
- public $Node = null;
- /**
- * setUp
- *
- * @return void
- */
- public function setUp() {
- parent::setUp();
- $this->Node = ClassRegistry::init('Nodes.Node');
- }
- /**
- * tearDown
- *
- * @return void
- */
- public function tearDown() {
- parent::tearDown();
- unset($this->Node);
- ClassRegistry::flush();
- }
- public function testEncodeWithoutKeys() {
- $array = array('hello', 'world');
- $encoded = $this->Node->encodeData($array);
- $this->assertEqual($encoded, '["hello","world"]');
- }
- public function testEncodeWithKeys() {
- $array = array(
- 'first' => 'hello',
- 'second' => 'world',
- );
- $encoded = $this->Node->encodeData($array, array(
- 'json' => true,
- 'trim' => false,
- ));
- $this->assertEqual($encoded, '{"first":"hello","second":"world"}');
- }
- public function testDecodeWithoutKeys() {
- $encoded = '["hello","world"]';
- $array = $this->Node->decodeData($encoded);
- $this->assertEqual($array, array('hello', 'world'));
- }
- public function testDecodeWithKeys() {
- $encoded = '{"first":"hello","second":"world"}';
- $array = $this->Node->decodeData($encoded);
- $this->assertEqual($array, array(
- 'first' => 'hello',
- 'second' => 'world',
- ));
- }
- }