/** * {@inheritdoc} */ public function collectPage($currentPage, tubepress_spi_media_HttpFeedHandlerInterface $feedHandler) { $toReturn = new tubepress_api_media_MediaPage(); $url = $feedHandler->buildUrlForPage($currentPage); $eventArgs = array('pageNumber' => $currentPage); $url = $this->_dispatchAndReturnSubject($feedHandler, tubepress_api_event_Events::MEDIA_PAGE_HTTP_URL, $url, $eventArgs); $this->_fetchFeedAndPrepareForAnalysis($url, $feedHandler); $reportedTotalResultCount = $feedHandler->getTotalResultCount(); if ($this->_shouldLog) { $this->_logDebug(sprintf('Reported total result count is %d video(s)', $reportedTotalResultCount)); } /* * If no results, we can shortcut things here. */ if ($reportedTotalResultCount < 1) { $feedHandler->onAnalysisComplete(); $mediaItemArray = array(); } else { /* convert the feed to videos */ $mediaItemArray = $this->_feedToMediaItemArray($feedHandler); if (count($mediaItemArray) == 0) { $reportedTotalResultCount = 0; } } $toReturn->setTotalResultCount($reportedTotalResultCount); $toReturn->setItems($mediaItemArray); return $this->_dispatchAndReturnSubject($feedHandler, tubepress_api_event_Events::MEDIA_PAGE_HTTP_NEW, $toReturn, $eventArgs); }
public function onSetup() { $this->_mockContext = $this->mock(tubepress_api_options_ContextInterface::_); $this->_mockUrlFactory = $this->mock(tubepress_api_url_UrlFactoryInterface::_); $this->_mockRequestParams = $this->mock(tubepress_api_http_RequestParametersInterface::_); $this->_mockTemplating = $this->mock(tubepress_api_template_TemplatingInterface::_); $this->_mockCurrentThemeService = $this->mock('tubepress_theme_impl_CurrentThemeService'); $this->_mockTranslator = $this->mock(tubepress_api_translation_TranslatorInterface::_); $this->_mockCurrentTheme = $this->mock(tubepress_api_theme_ThemeInterface::_); $this->_mockContext->shouldReceive('get')->once()->with(tubepress_api_options_Names::GALLERY_PAGINATE_ABOVE)->andReturn(true); $this->_mockContext->shouldReceive('get')->once()->with(tubepress_api_options_Names::GALLERY_PAGINATE_BELOW)->andReturn(true); $this->_mockContext->shouldReceive('get')->once()->with(tubepress_api_options_Names::FEED_ADJUSTED_RESULTS_PER_PAGE)->andReturnNull(); $this->_mockContext->shouldReceive('get')->once()->with(tubepress_api_options_Names::FEED_RESULTS_PER_PAGE)->andReturn(4); $this->_mockMediaPage = new tubepress_api_media_MediaPage(); $this->_mockMediaPage->setTotalResultCount(500); $this->_mockFullUrl = $this->mock('tubepress_api_url_UrlInterface'); $this->_mockFullQuery = $this->mock('tubepress_api_url_QueryInterface'); $this->_mockUrlFactory->shouldReceive('fromCurrent')->once()->andReturn($this->_mockFullUrl); $this->_mockTranslator->shouldReceive('trans')->atLeast(1)->andReturnUsing(function ($original) { return "##{$original}##"; }); $this->_mockCurrentThemeService->shouldReceive('getCurrentTheme')->atLeast(1)->andReturn($this->_mockCurrentTheme); $this->_sut = new tubepress_gallery_impl_listeners_PaginationListener($this->_mockContext, $this->_mockUrlFactory, $this->_mockRequestParams, $this->_mockTemplating, $this->_mockCurrentThemeService, $this->_mockTranslator); }
public function testSetGetTotal() { $this->_sut->setTotalResultCount(501); $this->assertEquals(501, $this->_sut->getTotalResultCount()); }
public function testCapResults() { $this->_mockLogger->shouldReceive('debug')->atLeast(1); $this->_mockContext->shouldReceive('get')->once()->with(tubepress_api_options_Names::FEED_RESULT_COUNT_CAP)->andReturn(888); $videoArray = array('x', 'y'); $providerResult = new tubepress_api_media_MediaPage(); $providerResult->setTotalResultCount(999); $providerResult->setItems($videoArray); $event = $this->mock('tubepress_api_event_EventInterface'); $event->shouldReceive('getSubject')->times(3)->andReturn($providerResult); $this->_sut->capResults($event); $this->assertTrue(true); }