-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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: Michiel de Jong <michiel@unhosted.org>
- Loading branch information
1 parent
1ea252f
commit cf37ae8
Showing
6 changed files
with
176 additions
and
24 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
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,73 @@ | ||
<?php | ||
/** | ||
* @author Michiel de Jong <michiel@unhosted.org> | ||
* | ||
* @copyright Copyright (c) 2022, Nextcloud, Inc. | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace Test\Share20; | ||
|
||
use OCP\IServerContainer; | ||
|
||
const EXAMPLE_SHARE_TYPE = 123; | ||
const UNKNOWN_SHARE_TYPE = 456; | ||
|
||
class ExampleProvider { | ||
public function isShareTypeSupported($shareType) { | ||
return ($shareType == EXAMPLE_SHARE_TYPE); | ||
} | ||
public function identifier() { | ||
return "example"; | ||
} | ||
} | ||
|
||
/** | ||
* Class ProviderFactoryTest | ||
* | ||
* @package Test\Share20 | ||
*/ | ||
class ProviderFactoryTest extends \Test\TestCase { | ||
|
||
/** @var \OCP\IServerContainer|\PHPUnit\Framework\MockObject\MockObject */ | ||
protected $serverContainer; | ||
/** @var \OCP\Share20\ProviderFactory */ | ||
protected $factory; | ||
|
||
/** @var ExampleProvider */ | ||
protected $dynamicProvider; | ||
|
||
protected function setUp(): void { | ||
$this->dynamicProvider = new ExampleProvider(); | ||
$this->serverContainer = $this->createMock(IServerContainer::class); | ||
$this->serverContainer->method('get') | ||
->with(ExampleProvider::class) | ||
->willReturn($this->dynamicProvider); | ||
$this->factory = new \OC\Share20\ProviderFactory($this->serverContainer); | ||
$this->factory->registerProvider(ExampleProvider::class); | ||
} | ||
|
||
|
||
public function testDynamicProvider() { | ||
$provider = $this->factory->getProviderForType(EXAMPLE_SHARE_TYPE); | ||
$this->assertEquals($provider, $this->dynamicProvider); | ||
} | ||
|
||
public function testUnknownType() { | ||
$this->expectExceptionMessage('No share provider for share type 456'); | ||
$provider = $this->factory->getProviderForType(UNKNOWN_SHARE_TYPE); | ||
} | ||
} |