public function ServicesClientPluginsTestCase::testServicesClientFieldReader in Services Client 7.2
File
- tests/
plugin.test, line 224 - Rules tests.
Class
- ServicesClientPluginsTestCase
- @file Rules tests.
Code
public function testServicesClientFieldReader() {
$this
->loadFiles();
$event = $this
->createFakeEvent();
$reader = new ServicesClientFieldReader($event, $event->config);
$this
->assertIdentical("[FieldReader - not configured]", $reader
->getSummary(), "Not configured field reader returns correct summary");
$config = array(
'field' => 'field_test',
'property' => 'value',
) + $reader
->getConfiguration();
$reader
->setConfiguration($config);
$this
->assertIdentical("\$source-><b>field_test[und][*][value]</b>", $reader
->getSummary(), "Configured field reader returns correct summary");
$reader
->setConfiguration(array(
'all_values' => FALSE,
) + $reader
->getConfiguration());
$this
->assertIdentical("\$source-><b>field_test[und][0][value]</b>", $reader
->getSummary(), "Configured field reader returns correct summary for single value read");
$reader
->setConfiguration(array(
'all_values' => TRUE,
) + $reader
->getConfiguration());
$source = $reader
->read(new stdClass());
$this
->assertIdentical($source
->isEmpty(), TRUE, "Non existing field will result in empty value");
$fake_entity = (object) array(
'field_test_other' => array(
LANGUAGE_NONE => array(
array(
'value' => 'test',
),
),
),
);
$source = $reader
->read($fake_entity);
$this
->assertIdentical($source
->isEmpty(), TRUE, "Non existing field will result in empty value");
$fake_entity = (object) array(
'field_test' => array(
LANGUAGE_NONE => array(
array(
'value' => 'test',
),
),
),
);
$source = $reader
->read($fake_entity);
$this
->assertIdentical($source
->isEmpty(), FALSE, "Existing field will result in non empty value");
$this
->assertIdentical($source
->getValue(), array(
'test',
), "Correct value is read from simple field.");
$reader
->setConfiguration(array(
'property' => 'tid',
) + $reader
->getConfiguration());
$source = $reader
->read($fake_entity);
$this
->assertIdentical($source
->isEmpty(), TRUE, "Existing field, non exiting property will return empty value.");
$reader
->setConfiguration(array(
'property' => 'value',
) + $reader
->getConfiguration());
$fake_entity->field_test[LANGUAGE_NONE][]['value'] = 'test2';
$source = $reader
->read($fake_entity);
$this
->assertIdentical($source
->isEmpty(), FALSE, "Existing field will result in non empty value");
$this
->assertIdentical($source
->getValue(), array(
'test',
'test2',
), "Correct value is read from multi value field.");
$fake_entity->field_test['sk'][]['value'] = 'test sk';
$source = $reader
->read($fake_entity);
$this
->assertIdentical($source
->isEmpty(), FALSE, "Existing field will result in non empty value");
$this
->assertIdentical($source
->getValue(), array(
'test',
'test2',
), "Different language value is ignored.");
$reader
->setConfiguration(array(
'language' => 'sk',
) + $reader
->getConfiguration());
$source = $reader
->read($fake_entity);
$this
->assertIdentical($source
->isEmpty(), FALSE, "Existing field (non default language) will result in non empty value");
$this
->assertIdentical($source
->getValue(), array(
'test sk',
), "Different language is read properly.");
$reader
->setConfiguration(array(
'all_values' => FALSE,
'language' => LANGUAGE_NONE,
'property' => 'value',
) + $reader
->getConfiguration());
$source = $reader
->read($fake_entity);
$this
->assertIdentical($source
->isEmpty(), FALSE, "Existing field (non default language) will result in non empty value");
$this
->assertIdentical($source
->getValue(), array(
'test',
), "Single value is read when configured to read only one.");
}