public function ServicesClientWebTestCase::testAddingEvent in Services Client 7.2
Test basic event configuration actions.
File
- tests/
services_client.test, line 363 - Tests for the Administration menu module.
Class
- ServicesClientWebTestCase
- Base class for all administration menu web test cases.
Code
public function testAddingEvent() {
// Login admin user.
$this
->drupalLogin($this->admin);
// Load services client page.
$this
->drupalGet('admin/structure/services_client');
$this
->assertText('There are no events to display.', "No events are created when module installed.");
$event = $this
->createSCEvent();
$this
->assertIdentical($event->disabled, TRUE, "Newly created event is disabled by default.");
// Add new property condition.
$conditions['status'] = $this
->addEventCondition($event, 'ServicesClientPropertyCondition', array(
'property' => 'status',
'condition' => 'equals',
'value' => '1',
));
// Test adding new mapping.
$reader_config = array(
'property' => 'uid',
);
$formatter_config = array(
'property' => 'uid',
);
$mapping['uid'] = $this
->addEventMapping($event, 'ServicesClientPropertyReader', $reader_config, 'ServicesClientPropertyFormatter', $formatter_config);
// Check that non-saved event doesn't have any configuration.
$event = $this
->loadEvent($event->name, TRUE);
$this
->assertIdentical($event->config, array(), "Non saved event configured event isn't changed in permanent storage.");
// Store new configuration to permanent storage.
$this
->saveEventConfiguration($event, array(), TRUE);
$this
->assertTrue(isset($event->config['condition'][$conditions['status']]), "Condition plugin was saved to event.");
$this
->assertTrue(isset($event->config['mapping'][$mapping['uid']]), "Mapping row was saved to event.");
// Test condition evalution.
$fake_entity = (object) array(
'status' => 0,
);
$handler = $event
->getHandler();
$handler
->setEntity($fake_entity);
$this
->assertIdentical($handler
->isMatching(), FALSE, 'Single non matching condition is executed correctly');
$fake_entity->status = 1;
$this
->assertIdentical($handler
->isMatching(), TRUE, 'Single matching condition is executed correctly');
$handler
->setEntity(NULL);
$this
->assertIdentical($handler
->isMatching(), FALSE, "Null entity isn't matching event.");
// Test removing event condition without token.
$this
->drupalGet($event
->getHandler()
->getUrl('plugin/condition/' . $conditions['status'] . '/remove'));
$this
->assertText('Invalid token', "When token isn't provided plugin can't be deleted.");
$this
->assertResponse(403, "No token requested resulted in 403 - access denied.");
$this
->drupalGet($event
->getHandler()
->getUrl('plugin/mapping/' . $mapping['uid'] . '/remove'));
$this
->assertText('Invalid token', "When token isn't provided plugin can't be deleted.");
$this
->assertResponse(403, "No token requested resulted in 403 - access denied.");
// Test removing event condition.
$this
->removeEventCondition($event, $conditions['status']);
// Test removing event row mapping.
$this
->removeEventMapping($event, $mapping['uid']);
// Store new configuration.
$this
->saveEventConfiguration($event, array(), TRUE);
$this
->assertIdentical($event->config['condition'], array(), "Removing condition resulted in empty conditions config array.");
$this
->assertIdentical($event->config['mapping'], array(), "Removing mapping row resulted in empty mapping config array.");
// Test field condition plugin.
$conditions['field_test'] = $this
->addEventCondition($event, 'ServicesClientFieldCondition', array(
'field' => 'field_test',
'language' => LANGUAGE_NONE,
'property' => 'value',
'condition' => 'equals',
'value' => 'myval',
));
$this
->saveEventConfiguration($event, array(), TRUE);
$handler = $event
->getHandler();
$fake_entity->field_test[LANGUAGE_NONE][0]['value'] = 'myval';
$handler
->setEntity($fake_entity);
$this
->assertIdentical($handler
->isMatching(), TRUE, 'Field condition is executed correctly when value is matching');
$fake_entity->field_test[LANGUAGE_NONE][0]['value'] = 'otherval';
$handler
->setEntity($fake_entity);
$this
->assertIdentical($handler
->isMatching(), FALSE, 'Field condition is executed correctly when value is not matching');
// Test handler tags
$this
->assertIdentical($handler
->hasTag('test'), FALSE, 'By default no tag is assigned to handler');
$handler
->addTag('test');
$this
->assertIdentical($handler
->hasTag('test'), TRUE, 'Added tag is repsonding.');
$handler
->removeTag('test');
$this
->assertIdentical($handler
->hasTag('test'), FALSE, "Removed tag isn't responding.");
}