diff options
author | Björn Schießle <bjoern@schiessle.org> | 2015-12-14 18:28:38 +0100 |
---|---|---|
committer | Björn Schießle <bjoern@schiessle.org> | 2015-12-15 11:43:18 +0100 |
commit | 91d17790d66c26d387a8b72581558989931cdede (patch) | |
tree | cbc3234bed9187bb8a43f23b7b6b0d0167044408 /tests | |
parent | f6be4f8ec1873359680938000f45ac9c55c43fd1 (diff) | |
download | nextcloud-server-91d17790d66c26d387a8b72581558989931cdede.tar.gz nextcloud-server-91d17790d66c26d387a8b72581558989931cdede.zip |
manually backport some helper methods
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/share/helper.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/lib/share/helper.php b/tests/lib/share/helper.php index 49476e4bc43..254e85ada5a 100644 --- a/tests/lib/share/helper.php +++ b/tests/lib/share/helper.php @@ -137,4 +137,76 @@ class Test_Share_Helper extends \Test\TestCase { ['user1', 'server1', 'user2', 'http://server1', false], ]; } + + public function dataTestSplitUserRemote() { + $userPrefix = ['user@name', 'username']; + $protocols = ['', 'http://', 'https://']; + $remotes = [ + 'localhost', + 'local.host', + 'dev.local.host', + 'dev.local.host/path', + 'dev.local.host/at@inpath', + '127.0.0.1', + '::1', + '::192.0.2.128', + '::192.0.2.128/at@inpath', + ]; + + $testCases = []; + foreach ($userPrefix as $user) { + foreach ($remotes as $remote) { + foreach ($protocols as $protocol) { + $baseUrl = $user . '@' . $protocol . $remote; + + $testCases[] = [$baseUrl, $user, $protocol . $remote]; + $testCases[] = [$baseUrl . '/', $user, $protocol . $remote]; + $testCases[] = [$baseUrl . '/index.php', $user, $protocol . $remote]; + $testCases[] = [$baseUrl . '/index.php/s/token', $user, $protocol . $remote]; + } + } + } + return $testCases; + } + + /** + * @dataProvider dataTestSplitUserRemote + * + * @param string $remote + * @param string $expectedUser + * @param string $expectedUrl + */ + public function testSplitUserRemote($remote, $expectedUser, $expectedUrl) { + list($remoteUser, $remoteUrl) = \OC\Share\Helper::splitUserRemote($remote); + $this->assertSame($expectedUser, $remoteUser); + $this->assertSame($expectedUrl, $remoteUrl); + } + + public function dataTestSplitUserRemoteError() { + return array( + // Invalid path + array('user@'), + + // Invalid user + array('@server'), + array('us/er@server'), + array('us:er@server'), + + // Invalid splitting + array('user'), + array(''), + array('us/erserver'), + array('us:erserver'), + ); + } + + /** + * @dataProvider dataTestSplitUserRemoteError + * + * @param string $id + * @expectedException \OC\HintException + */ + public function testSplitUserRemoteError($id) { + \OC\Share\Helper::splitUserRemote($id); + } } |