You are here

public function ServicesClientPluginsTestCase::testServicesClientPropertyFormatter in Services Client 7.2

File

tests/plugin.test, line 276
Rules tests.

Class

ServicesClientPluginsTestCase
@file Rules tests.

Code

public function testServicesClientPropertyFormatter() {
  $this
    ->loadFiles();
  $event = $this
    ->createFakeEvent();
  $formatter = new ServicesClientPropertyFormatter($event, $event->config);
  $source = new ServicesClientMappingValue(array(
    1,
  ));
  $this
    ->assertIdentical($formatter
    ->getSummary(), '[PropertyFormatter - not configured]', 'Not configured property formatter show correct summary');
  $formatter
    ->setConfiguration(array(
    'property' => 'test',
  ) + $formatter
    ->getConfiguration());
  $this
    ->assertIdentical($formatter
    ->getSummary(), '$object-><b>test</b>', 'Not configured property formatter show correct summary');
  $result = $formatter
    ->format($source);
  $this
    ->assertIdentical($result['key'], 'test', "Property formatter set correct property name.");
  $this
    ->assertIdentical($result['value'], 1, "Property formatter set correct value.");
  $source
    ->setValue(array(
    1,
    2,
  ));
  $result = $formatter
    ->format($source);
  $this
    ->assertIdentical($result['key'], 'test', "Property formatter set correct property name.");
  $this
    ->assertIdentical($result['value'], 1, "Property formatter set correct single value for multivalue source.");
  $formatter
    ->setConfiguration(array(
    'multivalue' => 'force_array',
  ) + $formatter
    ->getConfiguration());
  $result = $formatter
    ->format($source);
  $this
    ->assertIdentical($result['key'], 'test', "Property formatter set correct property name.");
  $this
    ->assertIdentical($result['value'], array(
    1,
    2,
  ), "Property formatter set correct multi value for multivalue source.");
  $source
    ->setEmpty();
  $result = $formatter
    ->format($source);
  $this
    ->assertIdentical($result, NULL, "Property formatter: No result is returend if value is empty");
  $formatter
    ->setConfiguration(array(
    'empty' => 'null_field',
  ) + $formatter
    ->getConfiguration());
  $result = $formatter
    ->format($source);
  $this
    ->assertIdentical($result['key'], 'test', "Property formatter set correct property name.");
  $this
    ->assertIdentical($result['value'], NULL, "Property formatter: NULL is returend if value is empty and null field configured.");
  $formatter
    ->setConfiguration(array(
    'empty' => 'default_value',
    'default_value' => 1,
  ) + $formatter
    ->getConfiguration());
  $result = $formatter
    ->format($source);
  $this
    ->assertIdentical($result['key'], 'test', "Property formatter set correct property name.");
  $this
    ->assertIdentical($result['value'], 1, "Property formatter: Default value is returned when empty value and default configured.");
}