public function ServicesClientHooksWebTestCase::testServicesClientHooks in Services Client 7.2
File
- tests/
services_client.test, line 564 - Tests for the Administration menu module.
Class
- ServicesClientHooksWebTestCase
- Base class for all administration menu web test cases.
Code
public function testServicesClientHooks() {
// Login admin user.
$this
->drupalLogin($this->admin);
$content_type = $this
->drupalCreateContentType(array(
'type' => 'post',
'name' => 'Post',
));
$node = $this
->drupalCreateNode(array(
'type' => 'post',
'title' => 'Test post',
));
$result = services_client_process_events('save', $node, 'node');
$this
->assertIdentical($result, array(), "No events are triggered by default.");
$event = $this
->createSCEvent();
// Add new property condition.
$conditions['status'] = $this
->addEventCondition($event, 'ServicesClientPropertyCondition', array(
'property' => 'status',
'condition' => 'equals',
'value' => '1',
));
$conditions['status'] = $this
->addEventCondition($event, 'ServicesClientPropertyCondition', array(
'property' => 'type',
'condition' => 'equals',
'value' => 'post',
));
// Add uid mapping.
$mapping['uid'] = $this
->addEventMapping($event, 'ServicesClientPropertyReader', array(
'property' => 'uid',
), 'ServicesClientPropertyFormatter', array(
'property' => 'uid',
));
$reader = array(
'field' => 'body',
'property' => 'value',
);
$formatter = array(
'field' => 'field_body',
'property' => 'value',
);
$mapping['body'] = $this
->addEventMapping($event, 'ServicesClientFieldReader', $reader, 'ServicesClientFieldFormatter', $formatter);
$formatter = array(
'field' => 'field_body_d6',
'property' => 'value',
);
$mapping['body_d6'] = $this
->addEventMapping($event, 'ServicesClientFieldReader', $reader, 'ServicesClientFieldD6Formatter', $formatter);
$this
->saveEventConfiguration($event, array(), TRUE);
$this
->enabledEvent($event);
// Test basic sync hooks
$result = services_client_process_events('save', $node, 'node');
$result = reset($result);
$this
->assertIdentical($result->object->services_client_test, TRUE, "hook_services_client_mapped_object_alter was triggered correctly.");
$this
->assertIdentical($result->object->services_client_test_name, $event->name, "Event handler is availbale in hook_services_client_mapped_object_alter.");
$this
->assertIdentical($result->object->services_client_before_request, TRUE, "hook_services_client_before_request was triggered correctly.");
$this
->assertIdentical($result->object->services_client_after_request, TRUE, "hook_services_client_after_request was triggered correctly.");
$this
->assertIdentical($result->services_client_process_events, TRUE, "hook_services_client_process_events was triggered correctly.");
$node->services_client_skip_autosync = TRUE;
$result = services_client_process_events('save', $node, 'node');
$this
->assertIdentical($result, array(), "Skip autosync hook was correctly triggered and prevented entity syncing.");
}