Problem/Motivation

I would like to refactor the UserData class cos currently the get method looks like something the cat dragged in. Compare to the tidy MongoDB version which can be applied to the SQL version as well just the query is different, the result rows are not. But there are no tests. Woe.

Proposed resolution

Add tests.

Remaining tasks

Add tests.

User interface changes

API changes

Members fund testing for the Drupal project. Drupal Association Learn more

Comments

vijaycs85’s picture

chx’s picture

Assigned: Unassigned » chx

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

kiamlaluno’s picture

Version: 8.3.x-dev » 8.4.x-dev
Status: Active » Needs work
+/**
+ * @file
+ * Contains \Drupal\user\Tests\UserDataTest.
+ */

@file is not required anymore for those files.

+/**
+ * Tests the user entity class.
+ *
+ * @group user
+ * @see \Drupal\user\UserData
+ */
+class UserDataTest extends UnitTestCase {

It is testing the user.data service, not the user entity class.

Yogesh Pawar’s picture

Changes done as per comment # & also added an interdiff.

Status: Needs review » Needs work

The last submitted patch, 7: userdata_needs_testing-2373573-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kiamlaluno’s picture

Status: Needs work » Needs review

The failure doesn't show any error in the patch, but rather a problem with the testing system. I am going to force a re-test.

kiamlaluno’s picture

Status: Needs review » Needs work

PHP_CodeSniffer is suggesting to replace array() with []; there are few places where that is needed, in the patch.

This is the patch against the patch it reports.

--- modules/user/src/Tests/UserDataTest.php
+++ PHP_CodeSniffer
@@ -20,12 +20,12 @@
    * @see \Drupal\user\UserData::get()
    */
   public function testGetMethod() {
-    $database_contents = array('users_data' => $this->getDummyUserData());
+    $database_contents = ['users_data' => $this->getDummyUserData()];
     $connection = $this->getDatabase($database_contents);
     $user_data = new UserData($connection);
 
     // 1. Get all data of given module.
-    $expected = array();
+    $expected = [];
     $actual = $user_data->get('foo_module');
     $this->assertSame($expected, $actual);
 
@@ -53,7 +53,7 @@
    * @return \Drupal\Core\Database\Driver\fake\FakeConnection
    *   The database connection.
    */
-  protected function getDatabase(array $database_contents, $connection_options = array(), $prefix = '') {
+  protected function getDatabase(array $database_contents, $connection_options = [], $prefix = '') {
     return new FakeConnection($database_contents, $connection_options, $prefix);
   }
 
@@ -63,36 +63,36 @@
    * @return array
    */
   protected function getDummyUserData() {
-    return array(
-      array(
+    return [
+      [
         'module' => 'foo_module',
         'uid' => 1,
         'name' => 'key1',
         'value' => 'value1',
         'serialized' => FALSE
-      ),
-      array(
+      ],
+      [
         'module' => 'foo_module',
         'uid' => 2,
         'name' => 'key2',
         'value' => 'value2',
         'serialized' => FALSE
-      ),
-      array(
+      ],
+      [
         'module' => 'foo_module',
         'uid' => 3,
         'name' => 'key3',
         'value' => 'value3',
         'serialized' => FALSE
-      ),
-      array(
+      ],
+      [
         'module' => 'bar_module',
         'uid' => 1,
         'name' => 'key1',
         'value' => 'value1',
         'serialized' => FALSE
-      ),
-    );
+      ],
+    ];
   }
 
 }

I apologize for changing the status twice. I first didn't notice the file attached to the automatic comment.

kiamlaluno’s picture

Status: Needs work » Needs review
FileSize
2.8 KB

I also added the comma after the last array item, as per Drupal coding standards, the section about arrays.

Status: Needs review » Needs work

The last submitted patch, 11: add-tests-2373573-11.diff, failed testing. View results

kiamlaluno’s picture

I take the error is saying that core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php doesn't exist anymore.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.