-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #877 from nextcloud/test/fix-cypress
fix(search): handle removed files gracefully
- Loading branch information
Showing
2 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace Unit\Service; | ||
|
||
use OC\Files\Node\Folder; | ||
use OC\Search\SearchQuery; | ||
use OCA\Collectives\Db\Collective; | ||
use OCA\Collectives\Search\PageContentProvider; | ||
use OCA\Collectives\Service\CollectiveHelper; | ||
use OCA\Collectives\Service\PageService; | ||
use OCA\Collectives\Service\SearchService; | ||
use OCP\App\IAppManager; | ||
use OCP\IL10N; | ||
use OCP\IURLGenerator; | ||
use OCP\IUser; | ||
use OCP\Search\ISearchQuery; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class PageContentProviderTest extends TestCase { | ||
private PageContentProvider $provider; | ||
|
||
protected function setUp(): void { | ||
$collective = new Collective(); | ||
$collective->setId(123); | ||
|
||
/** @var IL10N&MockObject $l10n */ | ||
$l10n = $this->createMock(IL10N::class); | ||
/** @var IURLGenerator&MockObject $urlGenerator */ | ||
$urlGenerator = $this->createMock(IURLGenerator::class); | ||
/** @var CollectiveHelper&MockObject $collectiveHelper */ | ||
$collectiveHelper = $this->createMock(CollectiveHelper::class); | ||
$collectiveHelper->method('getCollectivesForUser') | ||
->willReturn([$collective]); | ||
/** @var Folder&MockObject $folder */ | ||
$folder = $this->createMock(Folder::class); | ||
$folder->method('getById') | ||
->willReturn([]); | ||
/** @var PageService&MockObject $pageService */ | ||
$pageService = $this->createMock(PageService::class); | ||
$pageService->method('getCollectiveFolder') | ||
->willReturn($folder); | ||
/** @var SearchService&MockObject $indexedSearchService */ | ||
$indexedSearchService = $this->createMock(SearchService::class); | ||
$indexedSearchService->method('searchCollective') | ||
->willReturn(array(404 => 'fileData')); | ||
/** @var LoggerInterface&MockObject $logger */ | ||
$logger = $this->createMock(LoggerInterface::class); | ||
/** @var IAppManager&MockObject $appManager */ | ||
$appManager = $this->createMock(IAppManager::class); | ||
$appManager->method('isEnabledForUser') | ||
->willReturn(true); | ||
|
||
$this->provider = new PageContentProvider( | ||
$l10n, | ||
$urlGenerator, | ||
$collectiveHelper, | ||
$pageService, | ||
$indexedSearchService, | ||
$logger, | ||
$appManager | ||
); | ||
} | ||
|
||
public function testId(): void { | ||
$this->assertEquals('collectives-page-content', $this->provider->getId()); | ||
} | ||
|
||
public function testSearchWithMissingFile(): void { | ||
/** @var IUser&MockObject $user */ | ||
$user = $this->createMock(IUser::class); | ||
$user->method('getUID') | ||
->willReturn('jane'); | ||
$query = new SearchQuery( | ||
'Search me!', | ||
ISearchQuery::SORT_DATE_DESC, | ||
SearchQuery::LIMIT_DEFAULT, | ||
null, | ||
'collectives.' | ||
); | ||
$response = json_encode($this->provider->search($user, $query)); | ||
$result = json_decode($response, true); | ||
|
||
$this->assertEquals( | ||
'[]', | ||
json_encode($result['entries']) | ||
); | ||
} | ||
} |