public function ServicesClientPluginsTestCase::testServicesClientFieldFormatter in Services Client 7.2
File
- tests/
plugin.test, line 314 - Rules tests.
Class
- ServicesClientPluginsTestCase
- @file Rules tests.
Code
public function testServicesClientFieldFormatter() {
$this
->loadFiles();
$event = $this
->createFakeEvent();
$formatter = new ServicesClientFieldFormatter($event, $event->config);
$source = new ServicesClientMappingValue(array(
1,
));
$this
->assertIdentical($formatter
->getSummary(), '[FieldFormatter - not configured]', 'Not configured field formatter show correct summary');
$formatter
->setConfiguration(array(
'field' => 'field_test',
'property' => 'value',
) + $formatter
->getConfiguration());
$this
->assertIdentical($formatter
->getSummary(), '$object-><b>field_test[und][*][value]</b>', 'Not configured field formatter show correct summary');
$formatter
->setConfiguration(array(
'multivalue' => 'force_single',
) + $formatter
->getConfiguration());
$this
->assertIdentical($formatter
->getSummary(), '$object-><b>field_test[und][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 formatter set correct field name.");
$this
->assertIdentical($result['value'][LANGUAGE_NONE][0]['value'], 1, "Field 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'][LANGUAGE_NONE]), 2, "Field formatter created two values.");
$this
->assertIdentical($result['value'][LANGUAGE_NONE][1]['value'], 2, "Field formatter set second value correct value.");
$formatter
->setConfiguration(array(
'language' => 'sk',
) + $formatter
->getConfiguration());
$result = $formatter
->format($source);
$this
->assertIdentical($result['key'], 'field_test', "Field formatter set correct field name.");
$this
->assertIdentical(count($result['value']['sk']), 2, "Field formatter created two values.");
$this
->assertIdentical($result['value']['sk'][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(
'language' => LANGUAGE_NONE,
'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'][LANGUAGE_NONE], 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'][LANGUAGE_NONE][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'][LANGUAGE_NONE]), 1, "Field formatter created one value when force_single is enabled.");
$this
->assertTrue(empty($result['value'][LANGUAGE_NONE][1]['value']), "Field formatter sets only one value.");
}