/**
  * @dataProvider provideDataMakePagingLink
  */
 public function testMakePagingLink($storage, $query, $options, $offsetKey)
 {
     $pager = new Pager($storage, $query, $options);
     $page = $pager->getPage();
     $pagingOption = $page->getPagingLinksOptions();
     foreach ($pagingOption as $option) {
         $this->assertArrayHasKey($offsetKey, $option);
         $this->assertArrayHasKey('offset-dir', $option);
         $this->assertArrayHasKey('limit', $option);
         if (isset($options['sortby'])) {
             $this->assertArrayHasKey('sortby', $option);
         }
     }
 }
 /**
  * @dataProvider optionsPassedToObjectManagerFindProvider
  */
 public function testOptionsPassedToObjectManagerFind($message, $expect, $options)
 {
     $om = $this->mockObjectManager();
     $om->expects($this->any())->method('find')->with($this->anything(), $this->callback(function ($opts) use(&$options) {
         $options = $opts;
         return true;
     }));
     $pager = new Pager($om, array('otherthing' => 42), $options);
     $page = $pager->getPage();
     $this->assertNotNull($options);
     $optionsString = json_encode($options);
     foreach ($expect as $key => $value) {
         $this->assertArrayHasKey($key, $options, $optionsString);
         $this->assertEquals($value, $options[$key], $optionsString);
     }
 }
 /**
  * Gets a set of workflow IDs
  * This filters result to only include unmoderated and locked topics.
  *
  * Also populates topicRootRevisionCache with a mapping from topic ID to the
  * PostRevision for the topic root.
  *
  * @param array $findOptions
  * @return PagerPage
  */
 protected function getPage(array $findOptions)
 {
     $pager = new Pager($this->storage->getStorage('TopicListEntry'), array('topic_list_id' => $this->workflow->getId()), $findOptions);
     $postStorage = $this->storage->getStorage('PostRevision');
     // Work around lack of $this in closures until we can use PHP 5.4+ features.
     $topicRootRevisionCache =& $this->topicRootRevisionCache;
     return $pager->getPage(function (array $found) use($postStorage, &$topicRootRevisionCache) {
         $queries = array();
         /** @var TopicListEntry[] $found */
         foreach ($found as $entry) {
             $queries[] = array('rev_type_id' => $entry->getId());
         }
         $posts = $postStorage->findMulti($queries, array('sort' => 'rev_id', 'order' => 'DESC', 'limit' => 1));
         $allowed = array();
         foreach ($posts as $queryResult) {
             $post = reset($queryResult);
             if (!$post->isModerated() || $post->isLocked()) {
                 $allowed[$post->getPostId()->getAlphadecimal()] = $post;
             }
         }
         foreach ($found as $idx => $entry) {
             if (isset($allowed[$entry->getId()->getAlphadecimal()])) {
                 $topicRootRevisionCache[$entry->getId()->getAlphadecimal()] = $allowed[$entry->getId()->getAlphadecimal()];
             } else {
                 unset($found[$idx]);
             }
         }
         return $found;
     });
 }