Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
a014b9ad
Commit
a014b9ad
authored
Jan 07, 2015
by
Morris Jobke
Browse files
Merge pull request #13140 from owncloud/issue/13139-provisioning-api-tests
Extend Test\TestCase and do not use uniqid()
parents
8e13ee26
fb37b3c6
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
apps/provisioning_api/tests/
A
pps
T
est.php
→
apps/provisioning_api/tests/
a
pps
t
est.php
View file @
a014b9ad
...
...
@@ -23,36 +23,17 @@
*
*/
class
Test_Provisioning_Api_Apps
extends
PHPUnit_Framework_TestCase
{
private
$users
=
array
();
function
setUp
()
{
OC_Group
::
createGroup
(
'admin'
);
}
/**
* Generates a temp user
* @param $num int number of users to generate
*/
function
generateUsers
(
$num
=
1
)
{
for
(
$i
=
0
;
$i
<
$num
;
$i
++
)
{
$user
=
uniqid
();
\
OC_User
::
createUser
(
$user
,
'password'
);
$this
->
users
[]
=
$user
;
$users
[]
=
$user
;
}
return
count
(
$users
)
==
1
?
reset
(
$users
)
:
$users
;
}
function
testGetAppInfo
()
{
namespace
OCA\Provisioning_API\Tests
;
class
AppsTest
extends
TestCase
{
public
function
testGetAppInfo
()
{
$result
=
\
OCA\provisioning_API\Apps
::
getAppInfo
(
array
(
'appid'
=>
'provisioning_api'
));
$this
->
assertInstanceOf
(
'OC_OCS_Result'
,
$result
);
$this
->
assertTrue
(
$result
->
succeeded
());
}
function
testGetAppInfoOnBadAppID
()
{
public
function
testGetAppInfoOnBadAppID
()
{
$result
=
\
OCA\provisioning_API\Apps
::
getAppInfo
(
array
(
'appid'
=>
'not_provisioning_api'
));
$this
->
assertInstanceOf
(
'OC_OCS_Result'
,
$result
);
...
...
@@ -100,9 +81,4 @@ class Test_Provisioning_Api_Apps extends PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
count
(
$disabled
),
count
(
$data
[
'apps'
]));
}
function
tearDown
()
{
OC_Group
::
deleteGroup
(
'admin'
);
}
}
apps/provisioning_api/tests/groups
T
est.php
→
apps/provisioning_api/tests/groups
t
est.php
View file @
a014b9ad
...
...
@@ -23,35 +23,15 @@
*
*/
class
Test_Provisioning_Api_Groups
extends
PHPUnit_Framework_TestCase
{
namespace
OCA\Provisioning_API\Tests
;
private
$users
=
array
();
public
function
setUp
()
{
// These seems to be deleted by another test.
OC_Group
::
createGroup
(
'admin'
);
}
/**
* Generates a temp user
* @param $num int number of users to generate
*/
function
generateUsers
(
$num
=
1
)
{
for
(
$i
=
0
;
$i
<
$num
;
$i
++
)
{
$user
=
uniqid
();
\
OC_User
::
createUser
(
$user
,
'password'
);
$this
->
users
[]
=
$user
;
$users
[]
=
$user
;
}
return
count
(
$users
)
==
1
?
reset
(
$users
)
:
$users
;
}
function
testGetGroupAsUser
()
{
class
GroupsTest
extends
TestCase
{
public
function
testGetGroupAsUser
()
{
$users
=
$this
->
generateUsers
(
2
);
\
OC_User
::
setUserId
(
$users
[
0
]);
$group
=
uniqid
();
$group
=
$this
->
getUniqueID
();
\
OC_Group
::
createGroup
(
$group
);
\
OC_Group
::
addToGroup
(
$users
[
1
],
$group
);
...
...
@@ -65,12 +45,12 @@ class Test_Provisioning_Api_Groups extends PHPUnit_Framework_TestCase {
}
function
testGetGroupAsSubadmin
()
{
public
function
testGetGroupAsSubadmin
()
{
$users
=
$this
->
generateUsers
(
2
);
\
OC_User
::
setUserId
(
$users
[
0
]);
$group
=
uniqid
();
$group
=
$this
->
getUniqueID
();
\
OC_Group
::
createGroup
(
$group
);
\
OC_Group
::
addToGroup
(
$users
[
0
],
$group
);
\
OC_Group
::
addToGroup
(
$users
[
1
],
$group
);
...
...
@@ -87,14 +67,14 @@ class Test_Provisioning_Api_Groups extends PHPUnit_Framework_TestCase {
}
function
testGetGroupAsIrrelevantSubadmin
()
{
public
function
testGetGroupAsIrrelevantSubadmin
()
{
$users
=
$this
->
generateUsers
(
2
);
\
OC_User
::
setUserId
(
$users
[
0
]);
$group
=
uniqid
();
$group
=
$this
->
getUniqueID
();
\
OC_Group
::
createGroup
(
$group
);
$group2
=
uniqid
();
$group2
=
$this
->
getUniqueID
();
\
OC_Group
::
createGroup
(
$group2
);
\
OC_Group
::
addToGroup
(
$users
[
1
],
$group
);
\
OC_Group
::
addToGroup
(
$users
[
0
],
$group2
);
...
...
@@ -111,12 +91,12 @@ class Test_Provisioning_Api_Groups extends PHPUnit_Framework_TestCase {
}
function
testGetGroupAsAdmin
()
{
public
function
testGetGroupAsAdmin
()
{
$users
=
$this
->
generateUsers
(
2
);
\
OC_User
::
setUserId
(
$users
[
0
]);
$group
=
uniqid
();
$group
=
$this
->
getUniqueID
();
\
OC_Group
::
createGroup
(
$group
);
\
OC_Group
::
addToGroup
(
$users
[
1
],
$group
);
...
...
@@ -132,14 +112,14 @@ class Test_Provisioning_Api_Groups extends PHPUnit_Framework_TestCase {
}
function
testGetSubAdminsOfGroup
()
{
public
function
testGetSubAdminsOfGroup
()
{
$user1
=
$this
->
generateUsers
();
$user2
=
$this
->
generateUsers
();
OC_User
::
setUserId
(
$user1
);
OC_Group
::
addToGroup
(
$user1
,
'admin'
);
$group1
=
uniqid
();
OC_Group
::
createGroup
(
$group1
);
OC_SubAdmin
::
createSubAdmin
(
$user2
,
$group1
);
\
OC_User
::
setUserId
(
$user1
);
\
OC_Group
::
addToGroup
(
$user1
,
'admin'
);
$group1
=
$this
->
getUniqueID
();
\
OC_Group
::
createGroup
(
$group1
);
\
OC_SubAdmin
::
createSubAdmin
(
$user2
,
$group1
);
$result
=
\
OCA\provisioning_api\Groups
::
getSubAdminsOfGroup
(
array
(
'groupid'
=>
$group1
,
));
...
...
@@ -147,28 +127,16 @@ class Test_Provisioning_Api_Groups extends PHPUnit_Framework_TestCase {
$this
->
assertTrue
(
$result
->
succeeded
());
$data
=
$result
->
getData
();
$this
->
assertEquals
(
$user2
,
reset
(
$data
));
OC_Group
::
deleteGroup
(
$group1
);
\
OC_Group
::
deleteGroup
(
$group1
);
$user1
=
$this
->
generateUsers
();
OC_User
::
setUserId
(
$user1
);
OC_Group
::
addToGroup
(
$user1
,
'admin'
);
\
OC_User
::
setUserId
(
$user1
);
\
OC_Group
::
addToGroup
(
$user1
,
'admin'
);
$result
=
\
OCA\provisioning_api\Groups
::
getSubAdminsOfGroup
(
array
(
'groupid'
=>
uniqid
(),
'groupid'
=>
$this
->
getUniqueID
(),
));
$this
->
assertInstanceOf
(
'OC_OCS_Result'
,
$result
);
$this
->
assertFalse
(
$result
->
succeeded
());
$this
->
assertEquals
(
101
,
$result
->
getStatusCode
());
}
/**
* Remove all the temporary users
*/
function
tearDown
()
{
foreach
(
$this
->
users
as
$user
)
{
\
OC_User
::
deleteUser
(
$user
);
}
OC_Group
::
deleteGroup
(
'admin'
);
}
}
apps/provisioning_api/tests/testcase.php
0 → 100644
View file @
a014b9ad
<?php
/**
* ownCloud
*
* @copyright (C) 2014 ownCloud, Inc.
*
* @author Tom <tom@owncloud.com>
* @author Thomas Müller <deepdiver@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace
OCA\Provisioning_API\Tests
;
abstract
class
TestCase
extends
\
Test\TestCase
{
protected
$users
=
array
();
protected
function
setUp
()
{
parent
::
setUp
();
\
OC_Group
::
createGroup
(
'admin'
);
}
/**
* Generates a temp user
* @param int $num number of users to generate
* @return array
*/
protected
function
generateUsers
(
$num
=
1
)
{
$users
=
array
();
for
(
$i
=
0
;
$i
<
$num
;
$i
++
)
{
$user
=
$this
->
getUniqueID
();
\
OC_User
::
createUser
(
$user
,
'password'
);
$this
->
users
[]
=
$user
;
$users
[]
=
$user
;
}
return
count
(
$users
)
==
1
?
reset
(
$users
)
:
$users
;
}
protected
function
tearDown
()
{
foreach
(
$this
->
users
as
$user
)
{
\
OC_User
::
deleteUser
(
$user
);
}
\
OC_Group
::
deleteGroup
(
'admin'
);
parent
::
tearDown
();
}
}
apps/provisioning_api/tests/users
T
est.php
→
apps/provisioning_api/tests/users
t
est.php
View file @
a014b9ad
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment