public function ServicesClientPluginsTestCase::testServicesClientControl in Services Client 7.2
File
- tests/
plugin.test, line 57 - Rules tests.
Class
- ServicesClientPluginsTestCase
- @file Rules tests.
Code
public function testServicesClientControl() {
$this
->loadFiles();
$client_id = services_client_get_id();
$remote_id = $this
->randomName();
// Try adding new control data to simple entity.
$fake_entity = new stdClass();
$control = new ServicesClientControl($fake_entity, $client_id, $remote_id);
$object = new stdClass();
$control
->setData($object);
$this
->assertTrue(isset($object->_services_client), "Services client data was created.");
$this
->assertIdentical($object->_services_client['origin'], $client_id, "V1 services client origin was added.");
$this
->assertTrue(is_array($object->_services_client['visted']), "V1 list of visited sites was created.");
$this
->assertEqual(count($object->_services_client['visted']), 1, "V1 list of visited sites has one item.");
$this
->assertIdentical($object->_services_client['visted'][0], $client_id, "V1 list of visited sites has correct site.");
$this
->assertTrue(isset($object->_services_client['v2']), "V2 control data was created.");
$this
->assertIdentical($object->_services_client['v2']['id'], $client_id, "V2 services client id was added.");
if (drupal_is_cli()) {
$this
->assertIdentical($object->_services_client['v2']['source'], "cli", "V2 services client source was added.");
}
else {
$this
->assertTrue(preg_match('~^https?\\://.*~i', $object->_services_client['v2']['source']), "V2 services client source was added.");
}
$this
->assertEqual(count($object->_services_client['v2']['nodes']), 1, "V2 list of visited sites has one item.");
$this
->assertIdentical($object->_services_client['v2']['nodes'][0], $client_id, "V2 list of visited sites has correct site.");
$this
->assertIdentical($control
->shouldQueue(), FALSE, "Entity shouldn't be queued");
$this
->assertIdentical($control
->isLooping(), FALSE, "No looping when remote client id isn't in visited list.");
// Try to create control data from existing _services_client data V1 entity
$name = $this
->randomName();
$fake_entity->_services_client = array(
'origin' => $name,
'visted' => array(
$name,
$this
->randomName(),
),
);
$control = new ServicesClientControl($fake_entity, $client_id, $remote_id);
$object = new stdClass();
$control
->setData($object);
$this
->assertTrue(isset($object->_services_client), "Services client data was created.");
$this
->assertIdentical($object->_services_client['origin'], $client_id, "V1 services client origin was added.");
$this
->assertTrue(is_array($object->_services_client['visted']), "V1 list of visited sites was created.");
$this
->assertEqual(count($object->_services_client['visted']), 3, "V1 list of visited sites has two item.");
$this
->assertIdentical($object->_services_client['visted'][2], $client_id, "V1 list of visited sites has correct site.");
$this
->assertTrue(isset($object->_services_client['v2']), "V2 control data was created.");
$this
->assertIdentical($object->_services_client['v2']['id'], $client_id, "V2 services client id was added.");
if (drupal_is_cli()) {
$this
->assertIdentical($object->_services_client['v2']['source'], "cli", "V2 services client source was added.");
}
else {
$this
->assertTrue(preg_match('~^https?\\://.*~i', $object->_services_client['v2']['source']), "V2 services client source was added.");
}
$this
->assertEqual(count($object->_services_client['v2']['nodes']), 3, "V2 list of visited sites has one item.");
$this
->assertIdentical($object->_services_client['v2']['nodes'][2], $client_id, "V2 list of visited sites has correct site.");
$this
->assertIdentical($control
->shouldQueue(), TRUE, "Entity should be queued when remote id exists");
$this
->assertIdentical($control
->isLooping(), FALSE, "V1 source: No looping when remote client id isn't in visited list.");
// Try to create control data from existing _services_client data V2 entity
$name = $this
->randomName();
$fake_entity->_services_client = array(
'v2' => array(
'id' => $name,
'source' => drupal_is_cli() ? 'cli' : 'http://example.com/user',
'nodes' => array(
$name,
$this
->randomName(),
),
),
);
$control = new ServicesClientControl($fake_entity, $client_id, $remote_id);
$object = new stdClass();
$control
->setData($object);
$this
->assertTrue(isset($object->_services_client), "Services client data was created.");
$this
->assertIdentical($object->_services_client['origin'], $client_id, "V1 services client origin was added.");
$this
->assertTrue(is_array($object->_services_client['visted']), "V1 list of visited sites was created.");
$this
->assertEqual(count($object->_services_client['visted']), 3, "V1 list of visited sites has two item.");
$this
->assertIdentical($object->_services_client['visted'][2], $client_id, "V1 list of visited sites has correct site.");
$this
->assertTrue(isset($object->_services_client['v2']), "V2 control data was created.");
$this
->assertIdentical($object->_services_client['v2']['id'], $client_id, "V2 services client id was added.");
if (drupal_is_cli()) {
$this
->assertIdentical($object->_services_client['v2']['source'], "cli", "V2 services client source was added.");
}
else {
$this
->assertTrue(preg_match('~^https?\\://.*~i', $object->_services_client['v2']['source']), "V2 services client source was added.");
}
$this
->assertEqual(count($object->_services_client['v2']['nodes']), 3, "V2 list of visited sites has one item.");
$this
->assertIdentical($object->_services_client['v2']['nodes'][2], $client_id, "V2 list of visited sites has correct site.");
$this
->assertIdentical($control
->shouldQueue(), TRUE, "Entity should be queued when remote id exists");
$this
->assertIdentical($control
->isLooping(), FALSE, "V2 source: No looping when remote client id isn't in visited list.");
// Test looping detection from V2 data
$name = $this
->randomName();
$fake_entity->_services_client = array(
'origin' => $remote_id,
'visted' => array(
$remote_id,
$this
->randomName(),
),
);
$control = new ServicesClientControl($fake_entity, $client_id, $remote_id);
$this
->assertIdentical($control
->isLooping(), TRUE, "Possible loop is detected.");
// Test looping detection from V1 data
$name = $this
->randomName();
$fake_entity->_services_client = array(
'v2' => array(
'id' => $remote_id,
'source' => drupal_is_cli() ? 'cli' : 'http://example.com/user',
'nodes' => array(
$remote_id,
$this
->randomName(),
),
),
);
$control = new ServicesClientControl($fake_entity, $client_id, $remote_id);
$this
->assertIdentical($control
->isLooping(), TRUE, "Possible loop is detected.");
// V2 Test queue bypassing when data are set
$name = $this
->randomName();
$fake_entity->_services_client = array(
'v2' => array(
'id' => $name,
'source' => drupal_is_cli() ? 'cli' : 'http://example.com/user',
'nodes' => array(
$name,
$this
->randomName(),
),
'bypass_queue' => TRUE,
),
);
$control = new ServicesClientControl($fake_entity, $client_id, $remote_id);
$this
->assertIdentical($control
->shouldQueue(), FALSE, "Entity shouldn't be queued when remote id exists and bypass queue flag is enabled.");
// V1 Test queue bypassing when data are set
$name = $this
->randomName();
$fake_entity->_services_client = array(
'origin' => $name,
'visted' => array(
$name,
$this
->randomName(),
),
'bypass_queue' => TRUE,
);
$control = new ServicesClientControl($fake_entity, $client_id, $remote_id);
$this
->assertIdentical($control
->shouldQueue(), FALSE, "Entity shouldn't be queued when remote id exists and bypass queue flag is enabled.");
}