Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views / tests / src / Unit / Plugin / pager / PagerPluginBaseTest.php
index 555c8a404b523ea3c7eacac6a7ea3f7d8fa6d551..d94840746b39520b0168dc4da4406a86e4127df2 100644 (file)
@@ -9,6 +9,7 @@ namespace Drupal\Tests\views\Unit\Plugin\pager;
 
 use Drupal\Tests\UnitTestCase;
 use Drupal\Core\Database\StatementInterface;
+use Drupal\Core\Database\Query\Select;
 
 /**
  * @coversDefaultClass \Drupal\views\Plugin\views\pager\PagerPluginBase
@@ -195,7 +196,7 @@ class PagerPluginBaseTest extends UnitTestCase {
       // Now we are on the second page, which has just a single one left.
       [5, 6, 1, FALSE],
       // Increase the total items, so we have some available on the third page.
-      [5, 12, 1, TRUE]
+      [5, 12, 1, TRUE],
     ];
   }
 
@@ -247,6 +248,30 @@ class PagerPluginBaseTest extends UnitTestCase {
     $this->assertEquals(1, $this->pager->executeCountQuery($query));
   }
 
+  /**
+   * Tests the executeCountQuery method with an offset larger than result count.
+   *
+   * @see \Drupal\views\Plugin\views\pager\PagerPluginBase::executeCountQuery()
+   */
+  public function testExecuteCountQueryWithOffsetLargerThanResult() {
+    $statement = $this->getMock(TestStatementInterface::class);
+
+    $statement->expects($this->once())
+      ->method('fetchField')
+      ->will($this->returnValue(2));
+
+    $query = $this->getMockBuilder(Select::class)
+      ->disableOriginalConstructor()
+      ->getMock();
+
+    $query->expects($this->once())
+      ->method('execute')
+      ->will($this->returnValue($statement));
+
+    $this->pager->setOffset(3);
+    $this->assertEquals(0, $this->pager->executeCountQuery($query));
+  }
+
 }
 
 /**