-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: provokateurin <[email protected]>
- Loading branch information
1 parent
8f0bccd
commit dedc5ec
Showing
8 changed files
with
377 additions
and
1 deletion.
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
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
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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\GroupFolders\Tests\Listeners; | ||
|
||
use OCA\Circles\Events\CircleDestroyedEvent; | ||
use OCA\Circles\Model\Circle; | ||
use OCA\GroupFolders\Folder\FolderManager; | ||
use OCA\GroupFolders\Listeners\CircleDestroyedEventListener; | ||
use OCP\EventDispatcher\Event; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use Test\TestCase; | ||
|
||
class CircleDestroyedEventListenerTest extends TestCase { | ||
private FolderManager&MockObject $folderManager; | ||
private CircleDestroyedEventListener $listener; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->folderManager = $this->createMock(FolderManager::class); | ||
|
||
$this->listener = new CircleDestroyedEventListener($this->folderManager); | ||
} | ||
|
||
public function testHandleInvalid(): void { | ||
$event = $this->createMock(Event::class); | ||
|
||
$this->folderManager | ||
->expects($this->never()) | ||
->method('deleteCircle'); | ||
|
||
/** @psalm-suppress InvalidArgument on purpose */ | ||
$this->listener->handle($event); | ||
} | ||
|
||
public function testHandle(): void { | ||
$circle = $this->createMock(Circle::class); | ||
$circle | ||
->expects($this->once()) | ||
->method('getSingleId') | ||
->willReturn('123'); | ||
|
||
$event = $this->createMock(CircleDestroyedEvent::class); | ||
$event | ||
->expects($this->once()) | ||
->method('getCircle') | ||
->willReturn($circle); | ||
|
||
$this->folderManager | ||
->expects($this->once()) | ||
->method('deleteCircle') | ||
->with('123'); | ||
|
||
$this->listener->handle($event); | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\GroupFolders\Tests\Listeners; | ||
|
||
use OCA\Files\Event\LoadAdditionalScriptsEvent; | ||
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; | ||
use OCA\GroupFolders\Listeners\LoadAdditionalScriptsListener; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\Util; | ||
use Test\TestCase; | ||
|
||
class LoadAdditionalScriptsListenerTest extends TestCase { | ||
private LoadAdditionalScriptsListener $listener; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->listener = new LoadAdditionalScriptsListener(); | ||
} | ||
|
||
public static function handleProvider(): array { | ||
$expectedScripts = [ | ||
'groupfolders/l10n/en', | ||
'groupfolders/js/groupfolders-init', | ||
'groupfolders/js/groupfolders-files', | ||
]; | ||
return [ | ||
[Event::class, []], | ||
[LoadAdditionalScriptsEvent::class, $expectedScripts], | ||
[BeforeTemplateRenderedEvent::class, $expectedScripts], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider handleProvider | ||
* @param class-string<LoadAdditionalScriptsEvent|BeforeTemplateRenderedEvent> $class | ||
*/ | ||
public function testHandle(string $class, array $expectedScripts): void { | ||
$event = $this->createMock($class); | ||
|
||
$this->listener->handle($event); | ||
$this->assertEquals($expectedScripts, array_values(Util::getScripts())); | ||
} | ||
} |
Oops, something went wrong.