updated some more modules

This commit is contained in:
Bachir Soussi Chiadmi
2017-01-22 19:41:28 +01:00
parent 8416e3eea1
commit a0fadb0757
271 changed files with 11309 additions and 2135 deletions
@@ -0,0 +1,134 @@
<?php
class CerBasicTestCase extends DrupalWebTestCase {
/**
* A user account under which the tests will be conducted.
*
* @var StdClass
*/
protected $author;
/**
* A node that references $this->author.
*
* @var StdClass
*/
protected $node;
public static function getInfo() {
return array(
'name' => 'Basic',
'description' => "Tests CER's basic CRUD functionality.",
'group' => 'CER',
);
}
public function setUp() {
// Turns out you have to enable your own module in the friggin' test, if
// you want your own classes to be available. Lawsy me and other such
// utterances...SimpleTest is teh suck.
parent::setUp('entity', 'ctools', 'entityreference', 'field_object', 'cer');
$field = array(
'type' => 'entityreference',
'cardinality' => 1,
'field_name' => 'field_author',
'settings' => array(
'target_type' => 'user',
),
);
field_create_field($field);
$instance = array(
'field_name' => $field['field_name'],
'entity_type' => 'node',
'bundle' => 'page',
);
field_create_instance($instance);
$field = array(
'type' => 'entityreference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'field_name' => 'field_pages',
'settings' => array(
'target_type' => 'node',
),
'handler_settings' => array(
'target_bundles' => array('page'),
),
);
field_create_field($field);
$instance = array(
'field_name' => $field['field_name'],
'entity_type' => 'user',
'bundle' => 'user',
);
field_create_instance($instance);
/** @var CerPreset $preset */
$preset = entity_create('cer', array());
$preset->wrapper->cer_left->set('node:page:field_author');
$preset->wrapper->cer_right->set('user:user:field_pages');
$preset->wrapper->cer_bidirectional->set(TRUE);
$preset->wrapper->cer_enabled->set(TRUE);
$preset->save();
$this->author = $this->drupalCreateUser();
$this->node = $this->drupalCreateNode(array(
'field_author' => array(
LANGUAGE_NONE => array(
array('target_id' => $this->author->uid),
),
),
));
}
public function testCreate() {
$author = $this->reload('user', $this->author);
$this->assertEqual(1, $author->field_pages->count());
$this->assertEqual($this->node->nid, $author->field_pages[0]->nid->value());
}
public function testUpdateDereference() {
// Dereference the node from the user.
$this->author->field_pages = array();
user_save($this->author);
// Reload $this->node from the database so we get the latest field values.
$this->assertNull($this->reload('node', $this->node)->field_author->value());
}
public function testUpdateChangeTarget() {
$target = $this->drupalCreateUser();
$this->node->field_author[LANGUAGE_NONE][0]['target_id'] = $target->uid;
node_save($this->node);
// The original author should no longer reference the node.
$this->assertEqual(0, $this->reload('user', $this->author)->field_pages->count());
/** @var EntityDrupalWrapper $target */
$target = $this->reload('user', $target);
$this->assertEqual(1, $target->field_pages->count());
$this->assertEqual($this->node->nid, $target->field_pages[0]->nid->value());
}
public function testDelete() {
node_delete($this->node->nid);
$this->assertEqual(0, $this->reload('user', $this->author)->field_pages->count());
}
/**
* @return EntityDrupalWrapper
*/
protected function reload($entity_type, $entity) {
list ($id) = entity_extract_IDs($entity_type, $entity);
$entities = entity_load($entity_type, array($id), NULL, TRUE);
return entity_metadata_wrapper($entity_type, $entities[$id]);
}
}
@@ -1,16 +0,0 @@
name = "CER Tests"
core = "7.x"
description = "Automated tests for CER."
hidden = TRUE
dependencies[] = simpletest
dependencies[] = cer
files[] = crud.test
files[] = fields.test
; Information added by Drupal.org packaging script on 2014-08-08
version = "7.x-2.x-dev"
core = "7.x"
project = "cer"
datestamp = "1407528862"
@@ -1 +0,0 @@
<?php
@@ -1,168 +0,0 @@
<?php
class CerCrudTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'CRUD',
'group' => 'Corresponding Entity Reference',
'description' => 'Tests basic CER functionality.',
);
}
public function setUp() {
parent::setUp('field', 'field_sql_storage', 'ctools', 'entityreference', 'cer');
field_create_field(array(
'field_name' => 'field_user',
'type' => 'entityreference',
'cardinality' => -1,
'settings' => array(
'target_type' => 'user',
),
));
field_create_field(array(
'field_name' => 'field_node',
'type' => 'entityreference',
'cardinality' => -1,
'settings' => array(
'target_type' => 'node',
),
));
field_create_instance(array(
'field_name' => 'field_user',
'entity_type' => 'node',
'bundle' => 'page',
));
field_create_instance(array(
'field_name' => 'field_node',
'entity_type' => 'user',
'bundle' => 'user',
));
db_insert('cer')->fields(array(
'entity_types_content_fields' => 'node*page*field_user*user*user*field_node',
'enabled' => TRUE,
))->execute();
}
public function testImplicitReferenceCreation() {
$uid = $this->drupalCreateUser()->uid;
$referrers = array();
for ($i = 0; $i < 5; $i++) {
$referrers[] = $this->drupalCreateNode(array(
'type' => 'page',
'field_user' => array(
'und' => array(
array('target_id' => $uid),
),
),
))->nid;
}
$references = array();
foreach (user_load($uid, TRUE)->field_node['und'] as $reference) {
$references[] = $reference['target_id'];
}
$this->assertFalse(array_diff($referrers, $references), 'Creating 5 referrers to a single entity creates 5 corresponding references on that entity.', 'CER');
}
public function testDuplicateReferencePrevention() {
$uid = $this->drupalCreateUser()->uid;
$this->drupalCreateNode(array(
'type' => 'page',
'field_user' => array(
'und' => array(
array('target_id' => $uid),
array('target_id' => $uid),
),
),
));
$account = user_load($uid, TRUE);
$this->assertEqual(sizeof($account->field_node['und']), 1, 'Creating two references to an entity from a single referrer creates one corresponding reference.', 'CER');
}
public function testExplicitReferenceCreation() {
$uid = $this->drupalCreateNode()->uid;
$node = $this->drupalCreateNode(array('type' => 'page'));
$node->field_user['und'][0]['target_id'] = $uid;
node_save($node);
$account = user_load($uid, TRUE);
$this->assertEqual($account->field_node['und'][0]['target_id'], $node->nid, 'Creating an explicit reference between to unrelated entities creates a corresponding reference.', 'CER');
}
public function testExplicitDereference() {
$uid = $this->drupalCreateUser()->uid;
$nid = $this->drupalCreateNode(array(
'type' => 'page',
'field_user' => array(
'und' => array(
array('target_id' => $uid),
),
),
))->nid;
$account = user_load($uid, TRUE);
$account->field_node = array();
user_save($account);
$node = node_load($nid, NULL, TRUE);
$this->assertFalse($node->field_user, 'Explicitly clearing a reference from the referenced entity clears the corresponding reference on the referrer.', 'CER');
}
public function testReferrerDeletion() {
$uid = $this->drupalCreateUser()->uid;
$referrers = array();
for ($i = 0; $i < 5; $i++) {
$referrers[] = $this->drupalCreateNode(array(
'type' => 'page',
'field_user' => array(
'und' => array(
array('target_id' => $uid),
),
),
))->nid;
}
node_delete($referrers[0]);
$references = array();
foreach (user_load($uid, TRUE)->field_node['und'] as $reference) {
$references[] = $reference['target_id'];
}
$this->assertFalse(in_array($referrers[0], $references), 'Deleting a referrer clears corresponding reference on the referenced entity.', 'CER');
}
public function testReferencedEntityDeletion() {
$uid = $this->drupalCreateUser()->uid;
$referrers = array();
for ($i = 0; $i < 5; $i++) {
$referrers[] = $this->drupalCreateNode(array(
'type' => 'page',
'field_user' => array(
'und' => array(
array('target_id' => $uid),
),
),
))->nid;
}
user_delete($uid);
$cleared = 0;
foreach ($referrers as $nid) {
$node = node_load($nid, NULL, TRUE);
$cleared += (int) empty($node->field_user);
}
$this->assertEqual($cleared, sizeof($referrers), 'Deleting a referenced entity clears all references to it.', 'CER');
}
}
@@ -1,67 +0,0 @@
<?php
class CerFieldTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Fields',
'group' => 'Corresponding Entity Reference',
'description' => 'Tests integration with the Field API.',
);
}
public function setUp() {
parent::setUp('field', 'field_sql_storage', 'ctools', 'entityreference', 'cer');
field_create_field(array(
'field_name' => 'field_user',
'type' => 'entityreference',
'cardinality' => -1,
'settings' => array(
'target_type' => 'user',
),
));
field_create_field(array(
'field_name' => 'field_node',
'type' => 'entityreference',
'cardinality' => -1,
'settings' => array(
'target_type' => 'node',
),
));
field_create_instance(array(
'field_name' => 'field_user',
'entity_type' => 'node',
'bundle' => 'page',
));
field_create_instance(array(
'field_name' => 'field_node',
'entity_type' => 'user',
'bundle' => 'user',
));
ctools_include('export');
$preset = ctools_export_crud_new('cer');
$preset->entity_types_content_fields = 'node*page*field_user*user*user*field_node';
$preset->enabled = TRUE;
ctools_export_crud_save('cer', $preset);
}
public function testFieldInstanceDelete() {
field_delete_instance(field_info_instance('user', 'field_node', 'user'));
$preset = cer_preset_load('node*page*field_user*user*user*field_node');
$this->assertNull($preset, 'Deleting a field instance clears CER presets for that instance.');
}
public function testFieldDelete() {
field_delete_field('field_user');
$preset = cer_preset_load('node*page*field_user*user*user*field_node');
$this->assertNull($preset, 'Deleting a field clears CER presets for that field.');
}
}