You are here

function FloatingBlockSettingsUnitTest::testFloatingBlockSettingsConversions in Floating block 7

Test _floating_block_admin_convert_array_to_text() and _floating_block_admin_convert_text_to_array().

File

tests/floating_block.test, line 25
Tests for floating_block.module.

Class

FloatingBlockSettingsUnitTest
@file Tests for floating_block.module.

Code

function testFloatingBlockSettingsConversions() {

  // Test an empty string returns an empty array.
  $floating_block_text = '';
  $floating_block_array = _floating_block_admin_convert_text_to_array($floating_block_text);
  $this
    ->assertEqual($floating_block_array, array());
  $this
    ->assertEqual(_floating_block_admin_convert_array_to_text($floating_block_array), $floating_block_text);

  // Test a single line containing a class.
  $floating_block_text = '.block-1';
  $floating_block_array = _floating_block_admin_convert_text_to_array($floating_block_text);
  $this
    ->assertEqual($floating_block_array, array(
    '.block-1' => array(),
  ));
  $this
    ->assertEqual(_floating_block_admin_convert_array_to_text($floating_block_array), $floating_block_text);

  // Test a single line containing a class and 1 extra setting.
  $floating_block_text = '.block-1|container=#main';
  $floating_block_array = _floating_block_admin_convert_text_to_array($floating_block_text);
  $this
    ->assertEqual($floating_block_array, array(
    '.block-1' => array(
      'container' => '#main',
    ),
  ));
  $this
    ->assertEqual(_floating_block_admin_convert_array_to_text($floating_block_array), $floating_block_text);

  // Test a single line containing a class and multiple extra setting.
  $floating_block_text = '.block-1|container=#main,padding_top=8,padding_bottom=4';
  $floating_block_array = _floating_block_admin_convert_text_to_array($floating_block_text);
  $this
    ->assertEqual($floating_block_array, array(
    '.block-1' => array(
      'container' => '#main',
      'padding_top' => '8',
      'padding_bottom' => '4',
    ),
  ));
  $this
    ->assertEqual(_floating_block_admin_convert_array_to_text($floating_block_array), $floating_block_text);

  // Test mutliple line configuration.
  $floating_block_text = ".block-1|container=#main,padding_top=8\n.block-2";
  $floating_block_array = _floating_block_admin_convert_text_to_array($floating_block_text);
  $this
    ->assertEqual($floating_block_array, array(
    '.block-1' => array(
      'container' => '#main',
      'padding_top' => '8',
    ),
    '.block-2' => array(),
  ));
  $this
    ->assertEqual(_floating_block_admin_convert_array_to_text($floating_block_array), $floating_block_text);
}