updated webform localization and phone, uuid, term_merge, spambot, performance

This commit is contained in:
Bachir Soussi Chiadmi
2016-11-05 17:14:57 +01:00
parent fdefc824d8
commit 0521608bb7
57 changed files with 3592 additions and 1629 deletions

View File

@@ -6,23 +6,28 @@
*/
/**
* Base class with some helper methods.
* UUID test helper trait.
*
* Contains methods that assist with running UUID tests.
*/
class UUIDTestCase extends DrupalWebTestCase {
/**
* {@inheritdoc}
*/
function setUp() {
parent::setUp(func_get_args());
}
trait UUIDTestHelper {
/**
* Helper function that asserts a UUID.
*/
function assertUUID($uuid, $message = NULL) {
protected function assertUuid($uuid, $message = NULL) {
$this->assertTrue(uuid_is_valid($uuid), $message);
}
}
/**
* Base class with some helper methods.
*/
abstract class UUIDTestCase extends DrupalWebTestCase {
use UUIDTestHelper;
}
/**
@@ -44,29 +49,125 @@ class UUIDAPITestCase extends UUIDTestCase {
/**
* {@inheritdoc}
*/
function setUp() {
parent::setUp('uuid');
protected function setUp() {
parent::setUp(array('uuid'));
}
/**
* Tests uuid function calls.
*/
function testAPIFunctions() {
public function testApiFunctions() {
// This is a valid UUID, we know that.
$valid_uuid = '0ab26e6b-f074-4e44-9da6-1205fa0e9761';
// Test the uuid_is_valid() function.
$this->assertUUID($valid_uuid, 'UUID validation works.');
$this->assertUuid($valid_uuid, 'UUID validation works.');
// The default generator is 'php'.
$uuid = uuid_generate();
$this->assertUUID($uuid, 'PHP generator works.');
$this->assertUuid($uuid, 'PHP generator works.');
// Test the 'mysql' generator.
variable_set('uuid_generator', 'mysql');
drupal_static_reset('uuid_generate');
$uuid = uuid_generate();
$this->assertUUID($uuid, 'MySQL generator works.');
$this->assertUuid($uuid, 'MySQL generator works.');
}
/**
* Checks that schema for tables of core entities is correctly defined.
*/
public function testSchemas() {
module_load_include('install', 'uuid');
$schemas = drupal_get_schema();
$field_info = uuid_schema_field_definition();
$key_names = array(
'base table' => 'uuid',
'revision table' => 'revision uuid',
);
foreach (uuid_get_core_entity_info() as $entity_info) {
// Test the fields in "base" and "revision" tables.
foreach ($key_names as $table_type => $key_name) {
// Table or field is not defined in entity.
if (!isset($entity_info[$table_type], $entity_info['entity keys'][$key_name])) {
// Not all entities have a revisions table.
continue;
}
$field_name = $entity_info['entity keys'][$key_name];
$table_name = $entity_info[$table_type];
if (!isset($schemas[$table_name])) {
$this->fail(sprintf('Database schema does not have a "%s" table.', $table_name));
continue;
}
$properties = array(
'field' => array('fields', $field_info),
'index' => array('indexes', array($field_name)),
);
// Check integrity of the field and index definition.
foreach ($properties as $type => $data) {
list($property, $value) = $data;
$message = sprintf('Definition of the "%s" %s in the "%s" schema', $field_name, $type, $table_name);
if (isset($schemas[$table_name][$property][$field_name])) {
$this->assertIdentical($schemas[$table_name][$property][$field_name], $value, "$message is correct.");
}
else {
$this->fail("$message does not exist.");
}
}
}
}
}
}
/**
* Tests the UUID API functions.
*/
class UUIDV5TestCase extends UUIDTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'UUID v5',
'description' => 'Tests the UUID v5 function.',
'group' => 'UUID',
);
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp(array('uuid'));
}
/**
* Tests uuid function calls.
*/
public function testV5Function() {
// DNS namespace UUID.
$dns_namespace = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
// Valid DNS generation test.
$uuid = uuid_generate_v5($dns_namespace, 'drupal.org');
$this->assertUuid($uuid, 'UUID for drupal.org is valid.');
$this->assertEqual($uuid, 'c809fd30-48df-52e3-a9f2-2cd78129b8b1', 'UUID for drupal.org is correct.');
// Invalid namespace test.
$invalid_namespace = '01234567-c7a9-feda-27e5-75d00dabc123';
$uuid = uuid_generate_v5($invalid_namespace, 'drupal.org');
$this->assertFalse($uuid, 'Invalid namespace UUID rejected.');
}
}
/**
@@ -88,14 +189,14 @@ class UUIDEntityTestCase extends UUIDTestCase {
/**
* {@inheritdoc}
*/
function setUp() {
parent::setUp('uuid');
protected function setUp() {
parent::setUp(array('uuid'));
}
/**
* Tests Entity API's UUID functions.
*/
function testEntityAPIFunctions() {
public function testEntityApiFunctions() {
// Create some entities that we will work with.
$user = $this->drupalCreateUser();
$node = $this->drupalCreateNode(array('title' => 'original title', 'uid' => $user->uid));
@@ -112,6 +213,7 @@ class UUIDEntityTestCase extends UUIDTestCase {
$vuuids = entity_get_uuid_by_id('node', array($node->vid), TRUE);
$this->assertTrue(in_array($node->vuuid, $vuuids), 'Lookup of entity revision UUID works.');
}
}
/**
@@ -133,22 +235,23 @@ class UUIDUserTestCase extends UUIDTestCase {
/**
* {@inheritdoc}
*/
function setUp() {
protected function setUp() {
$modules = array('uuid');
// Some tests depends on the optional Entity API module.
if (module_exists('entity')) {
parent::setUp('uuid', 'entity');
}
else {
parent::setUp('uuid');
$modules[] = 'entity';
}
parent::setUp($modules);
}
/**
* Test CRUD on users with UUID functions.
*/
function testUserCRUD() {
public function testUserCrud() {
$user = $this->drupalCreateUser();
$this->assertUUID($user->uuid, 'User UUID was generated.');
$this->assertUuid($user->uuid, 'User UUID was generated.');
// Test updating user.
$user_test = clone $user;
@@ -178,6 +281,7 @@ class UUIDUserTestCase extends UUIDTestCase {
$this->assertFalse($user_test, 'Deleting user with UUID worked.');
}
}
}
/**
@@ -199,14 +303,15 @@ class UUIDNodeTestCase extends UUIDTestCase {
/**
* {@inheritdoc}
*/
function setUp() {
protected function setUp() {
$modules = array('uuid');
// Some tests depends on the optional Entity API module.
if (module_exists('entity')) {
parent::setUp('uuid', 'entity');
}
else {
parent::setUp('uuid');
$modules[] = 'entity';
}
parent::setUp($modules);
}
/**
@@ -215,13 +320,13 @@ class UUIDNodeTestCase extends UUIDTestCase {
* @todo
* Break out into multiple test methods to loosen coupling between tests.
*/
function testNodeCRUD() {
public function testNodeCrud() {
// Create some entities that we will work with.
$user = $this->drupalCreateUser();
$node = $this->drupalCreateNode(array('title' => 'original title', 'uid' => $user->uid));
$this->assertUUID($node->uuid, 'Node UUID was generated.');
$this->assertUUID($node->vuuid, 'Node revision UUID was generated.');
$this->assertUuid($node->uuid, 'Node UUID was generated.');
$this->assertUuid($node->vuuid, 'Node revision UUID was generated.');
// Test node update, without creating new revision.
$node_test = clone $node;
@@ -244,7 +349,7 @@ class UUIDNodeTestCase extends UUIDTestCase {
$node_test = node_load($node->nid, FALSE, TRUE);
$this->assertEqual($node_test->uuid, $node->uuid, 'Node UUID was intact after updating, when creating new revision.');
$this->assertNotEqual($node_test->vuuid, $node->vuuid, 'A new node revision UUID was generated, when creating new revision.');
$this->assertUUID($node_test->vuuid, 'The new node revision UUID was valid.');
$this->assertUuid($node_test->vuuid, 'The new node revision UUID was valid.');
// Test entity_uuid_load().
// Save some variables that we will test against.
@@ -300,7 +405,7 @@ class UUIDNodeTestCase extends UUIDTestCase {
$this->assertEqual($node_test->title, 'newer title', 'Saving node with UUID mapped to correct node, when creating new revision.');
$this->assertEqual($node_test->uuid, $node->uuid, 'Node UUID was intact after saving with UUID, when creating new revision.');
$this->assertNotEqual($node_test->vuuid, $node->vuuid, 'A new node revison UUID was generated after saving with UUID, when creating new revision.');
$this->assertUUID($node_test->vuuid, 'New node revision UUID was valid.');
$this->assertUuid($node_test->vuuid, 'New node revision UUID was valid.');
$this->assertEqual($node_test->uid, $node->uid, "Node property 'uid' was intact after saving with UUID, when creating new revision.");
// Test the same thing again, but now triggering a new revision from a
@@ -310,12 +415,9 @@ class UUIDNodeTestCase extends UUIDTestCase {
$node_test = reset($nodes);
// Store the current local revision ID to test with later.
$vid_old1 = $node_test->vid;
$vuuid_old1 = $node_test->vuuid;
// Simulate this node coming from a remote environment by generating
// IDs that won't match. Only the UUID match at this point.
$node_test->uuid_services = TRUE;
$nid_remote = rand();
$vid_remote = rand();
$vuuid_test = uuid_generate();
$node_test->nid = $nid_test;
$node_test->vid = $vid_test;
@@ -375,6 +477,7 @@ class UUIDNodeTestCase extends UUIDTestCase {
$this->assertFalse($node_test, 'Deleting node with UUID worked.');
}
}
}
/**
@@ -385,6 +488,8 @@ class UUIDNodeTestCase extends UUIDTestCase {
*/
class UUIDCommentTestCase extends CommentHelperCase {
use UUIDTestHelper;
/**
* {@inheritdoc}
*/
@@ -396,31 +501,21 @@ class UUIDCommentTestCase extends CommentHelperCase {
);
}
/**
* Helper function that asserts a UUID.
*
* We have duplicated this function from UUIDTestCase since we have to extend
* CommentHelperCase instead.
*/
function assertUUID($uuid, $message = NULL) {
$this->assertTrue(uuid_is_valid($uuid), $message);
}
/**
* Test CRUD on comments with UUID functions.
*/
function testCommentCRUD() {
public function testCommentCrud() {
// This is sub optimal, but due to how CommentHelperCase::setUp() is
// constructed we are enforced to do this. So unfortunately this test
// depends on 'entity' module for now.
module_enable(array('uuid', 'entity'), TRUE);
module_enable(array('uuid', 'entity'));
$user = $this->drupalCreateUser();
$this->drupalLogin($user);
$node = $this->drupalCreateNode();
$return = $this->postComment($node, 'Lorem ipsum');
$comment = comment_load($return->id);
$this->assertUUID($comment->uuid, 'Comment UUID was generated.');
$this->assertUuid($comment->uuid, 'Comment UUID was generated.');
// Test updating comment.
$comment_test = clone $comment;
@@ -456,6 +551,7 @@ class UUIDCommentTestCase extends CommentHelperCase {
$this->assertFalse($comment_test, 'Deleting comment with UUID worked.');
}
}
}
/**
@@ -463,6 +559,8 @@ class UUIDCommentTestCase extends CommentHelperCase {
*/
class UUIDTaxonomyTestCase extends TaxonomyWebTestCase {
use UUIDTestHelper;
/**
* {@inheritdoc}
*/
@@ -479,38 +577,34 @@ class UUIDTaxonomyTestCase extends TaxonomyWebTestCase {
*
* A lot of code here is taken from TaxonomyTermTestCase::setUp().
*/
function setUp() {
protected function setUp() {
$modules = array('taxonomy', 'uuid');
// Some tests depends on the optional Entity API module.
if (module_exists('entity')) {
parent::setUp('taxonomy', 'uuid', 'entity');
$modules[] = 'entity';
}
else {
parent::setUp('taxonomy', 'uuid');
}
}
/**
* Helper function that asserts a UUID.
*
* We have duplicated this function from UUIDTestCase since we have to extend
* TaxonomyWebTestCase instead.
*/
function assertUUID($uuid, $message = NULL) {
$this->assertTrue(uuid_is_valid($uuid), $message);
parent::setUp($modules);
}
/**
* Test CRUD on comments with UUID functions.
*/
function testTaxonomyCRUD() {
$user = $this->drupalCreateUser(array('administer taxonomy', 'administer nodes', 'bypass node access'));
public function testTaxonomyCrud() {
$perms = array(
'administer taxonomy',
'administer nodes',
'bypass node access',
);
$user = $this->drupalCreateUser($perms);
$this->drupalLogin($user);
// Create a term by tagging a node. We'll use this node later too.
$vocabulary = new stdClass;
$vocabulary = new stdClass();
$vocabulary->vid = 1;
$term = $this->createTerm($vocabulary);
$this->assertUUID($term->uuid, 'Term UUID was generated.');
$this->assertUuid($term->uuid, 'Term UUID was generated.');
// Test updating term.
$term_test = clone $term;
@@ -542,6 +636,7 @@ class UUIDTaxonomyTestCase extends TaxonomyWebTestCase {
$this->assertFalse($term_test, 'Deleting term with UUID worked.');
}
}
}
/**
@@ -566,14 +661,14 @@ class UUIDSyncTestCase extends UUIDTestCase {
* @todo
* There are something weird around this assertion.
*/
function assertTableColumn($table, $column, $message) {
protected function assertTableColumn($table, $column, $message) {
$this->assertTrue(db_field_exists($table, $column), $message);
}
/**
* Tests creating UUIDs for entities that don't have them.
*/
function testSync() {
public function testSync() {
// These entities will not have UUID from the start, since the UUID module
// isn't installed yet.
$user = $this->drupalCreateUser();
@@ -600,11 +695,12 @@ class UUIDSyncTestCase extends UUIDTestCase {
// Test if UUID was generated for nodes.
$node_test = node_load($node->nid, FALSE, TRUE);
$this->assertUUID($node_test->uuid, 'Node UUID was generated when clicking the sync button.');
$this->assertUUID($node_test->vuuid, 'Node revision UUID was generated when clicking the sync button.');
$this->assertUuid($node_test->uuid, 'Node UUID was generated when clicking the sync button.');
$this->assertUuid($node_test->vuuid, 'Node revision UUID was generated when clicking the sync button.');
// Test if UUID was generated for users.
$user_test = user_load($user->uid, TRUE);
$this->assertUUID($user_test->uuid, 'User UUID was generated when clicking the sync button.');
$this->assertUuid($user_test->uuid, 'User UUID was generated when clicking the sync button.');
}
}