You are here

public function ServicesClientPluginsTestCase::testServicesClientFieldD6Formatter in Services Client 7.2

File

tests/plugin.test, line 369
Rules tests.

Class

ServicesClientPluginsTestCase
@file Rules tests.

Code

public function testServicesClientFieldD6Formatter() {
  $this
    ->loadFiles();
  $event = $this
    ->createFakeEvent();
  $formatter = new ServicesClientFieldD6Formatter($event, $event->config);
  $source = new ServicesClientMappingValue(array(
    1,
  ));
  $this
    ->assertIdentical($formatter
    ->getSummary(), '[FieldD6Formatter - not configured]', 'Not configured field D6 formatter show correct summary');
  $formatter
    ->setConfiguration(array(
    'field' => 'field_test',
    'property' => 'value',
  ) + $formatter
    ->getConfiguration());
  $this
    ->assertIdentical($formatter
    ->getSummary(), '$object-><b>field_test[*][value]</b>', 'Not configured field D6 formatter show correct summary');
  $formatter
    ->setConfiguration(array(
    'multivalue' => 'force_single',
  ) + $formatter
    ->getConfiguration());
  $this
    ->assertIdentical($formatter
    ->getSummary(), '$object-><b>field_test[0][value]</b>', 'Not configured field formatter show correct summary');
  $formatter
    ->setConfiguration(array(
    'multivalue' => 'all_values',
  ) + $formatter
    ->getConfiguration());
  $result = $formatter
    ->format($source);
  $this
    ->assertIdentical($result['key'], 'field_test', "Field D6 formatter set correct field name.");
  $this
    ->assertIdentical($result['value'][0]['value'], 1, "Field D6 formatter created correct value.");
  $source
    ->setValue(array(
    1,
    2,
  ));
  $result = $formatter
    ->format($source);
  $this
    ->assertIdentical($result['key'], 'field_test', "Field formatter set correct field name.");
  $this
    ->assertIdentical(count($result['value']), 2, "Field formatter created two values.");
  $this
    ->assertIdentical($result['value'][1]['value'], 2, "Field formatter set second value correct value.");
  $source
    ->setEmpty();
  $result = $formatter
    ->format($source);
  $this
    ->assertIdentical($result, NULL, "Empty value results in NULL with default formatter configuration.");
  $formatter
    ->setConfiguration(array(
    'empty' => 'null_field',
  ) + $formatter
    ->getConfiguration());
  $result = $formatter
    ->format($source);
  $this
    ->assertIdentical($result['key'], 'field_test', "Field formatter set correct field name.");
  $this
    ->assertIdentical($result['value'], array(), "Field formatter empty value null field creates correct empty array");
  $formatter
    ->setConfiguration(array(
    'empty' => 'null_property',
  ) + $formatter
    ->getConfiguration());
  $result = $formatter
    ->format($source);
  $this
    ->assertIdentical($result['key'], 'field_test', "Field formatter set correct field name.");
  $this
    ->assertIdentical($result['value'], NULL, "Field formatter empty value null property creates correct NULL property.");
  $formatter
    ->setConfiguration(array(
    'empty' => 'default_value',
    'default_value' => 'default',
  ) + $formatter
    ->getConfiguration());
  $result = $formatter
    ->format($source);
  $this
    ->assertIdentical($result['key'], 'field_test', "Field formatter set correct field name.");
  $this
    ->assertIdentical($result['value'][0]['value'], 'default', "Field formatter empty value default value creates correct default.");
  $source
    ->setNotEmpty();
  $formatter
    ->setConfiguration(array(
    'multivalue' => 'force_single',
  ) + $formatter
    ->getConfiguration());
  $result = $formatter
    ->format($source);
  $this
    ->assertIdentical($result['key'], 'field_test', "Field formatter set correct field name.");
  $this
    ->assertIdentical(count($result['value']), 1, "Field formatter created one value when force_single is enabled.");
  $this
    ->assertTrue(empty($result['value'][1]['value']), "Field formatter sets only one value.");
}