There are already a couple of @todos in ViewExectuableTest, Let's implement those and improve the test coverage.

Patch to follow shortly.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

damiankloip’s picture

Status: Active » Needs review
FileSize
8.88 KB

Here is a patch to kick things off.

damiankloip’s picture

FileSize
9.94 KB

Converted the tests to ViewUnitTestBase and added another test (from @todo of last patch) for checking the usesPager() method.

dawehner’s picture

+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.phpundefined
@@ -140,19 +161,58 @@ public function testDisplays() {
+    $view->setDisplay('invalid');
+    $this->assertEqual($view->current_display, 'default', 'If setDisplay is called with an invalid display id the default display should be used.');
+    $this->assertEqual(spl_object_hash($view->display_handler), spl_object_hash($view->displayHandlers['default']));

cool!

+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.phpundefined
@@ -140,19 +161,58 @@ public function testDisplays() {
+    $this->assertFalse($view->use_ajax);
...
+    $this->assertTrue($view->use_ajax);

As a follow up we might want getUseAjax but sure this is out of scope here.

+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.phpundefined
@@ -140,19 +161,58 @@ public function testDisplays() {
+    $this->assertNull($view->usePager());

We could document in the assertion message that the test_executable_displays view has the none pager documented.

+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.phpundefined
@@ -140,19 +161,58 @@ public function testDisplays() {
+    $view->setOffset(5);
+    $this->assertEqual($view->getOffset(), 5);

What about using random integers?

+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.phpundefined
@@ -140,19 +161,58 @@ public function testDisplays() {
+      'views_test_data' => true,
+      '#global' => true,

That's not true, it should be TRUE ;)

+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.phpundefined
@@ -140,19 +161,58 @@ public function testDisplays() {
+  public function testDestroy() {

Tim patched in another issue to protected

+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.phpundefined
@@ -202,21 +267,36 @@ public function testViewsHandlerTypes() {
+      $this->assertTrue(array_filter($validate, $match), "Error message found for $id display");

Shouldn't we use format_string instead (not sure).

damiankloip’s picture

FileSize
10.01 KB

Thanks dawehner!

Tim patched in another issue to protected

Do you know which patch? Do you think I should revert this one then? Seems weird in a cleanup of this file thought :)

I'm not sure about exactly when to use the format_string() method. I like going with a normal string as it's one less function call, and every little helps.

Sure, we should create a follow up to add the getUseAJAX method.

damiankloip’s picture

FileSize
9.98 KB

Removed the @todo I todoed already and added the format_string().

damiankloip’s picture

FileSize
10.01 KB

Sorry, going mad, with the format_string change too.

damiankloip’s picture

I created a follow up here for the getter: #1866910: Add an ajaxEnabled() method for ViewExecutable

damiankloip’s picture

It's also worth noting, switching this to use ViewUnitTestBase cut the test time from ~45 secs to ~13 secs. Not bad!

damiankloip’s picture

FileSize
4.22 KB
12.12 KB

Added some more tests for initQuery, get/setResponse, generateItemId, getPath, getUrl, get/setTitle methods.

dawehner’s picture

Great work!

+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.phpundefined
@@ -208,6 +219,44 @@ public function testPropertySettings() {
+    $path = $this->randomString(10);

any reason to use randomString and not randomName? randomString is a great source for potential random test failures, but yeah actually for paths it shouldn't be different.

+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.phpundefined
@@ -208,6 +219,44 @@ public function testPropertySettings() {
+    $url = $this->randomString(10);
...
+    $arg1 = $this->randomString(10);
...
+    $title = $this->randomString(10);

Any special reason to use randomString(10) and not randomString()?

damiankloip’s picture

FileSize
1.74 KB
12.1 KB

Yep, makes sense. I have changed those. I think that is the actual calls you meant?

tim.plunkett’s picture

+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.phpundefined
@@ -2,21 +2,24 @@
-class ViewExecutableTest extends ViewTestBase {
+class ViewExecutableTest extends ViewUnitTestBase {

+1!

+++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.phpundefined
@@ -55,7 +51,20 @@ class ViewExecutableTest extends ViewTestBase {
+    'parent_views'

Missing trailing comma

Otherwise, looks great!

damiankloip’s picture

FileSize
12.08 KB

Nice, thanks for the review!

Rerolled against HEAD and added that trailing comma.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

RTBC when green!

damiankloip’s picture

I think we are good to go then :)

tim.plunkett’s picture

#13: 1866804-13.patch queued for re-testing.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Yay test coverage!

Committed and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.