summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/activitymanager.php2
-rw-r--r--tests/lib/appframework/http/RequestTest.php4
-rw-r--r--tests/lib/encryption/keys/storage.php2
-rw-r--r--tests/lib/encryption/managertest.php2
-rw-r--r--tests/lib/files/pathverificationtest.php10
-rw-r--r--tests/lib/files/storage/wrapper/encryption.php2
-rw-r--r--tests/lib/helper.php23
-rw-r--r--tests/lib/http/client/clienttest.php6
-rw-r--r--tests/lib/mail/mailer.php12
-rw-r--r--tests/lib/mail/message.php2
-rw-r--r--tests/lib/ocsclienttest.php2
-rw-r--r--tests/lib/repair/cleantags.php6
-rw-r--r--tests/lib/security/hasher.php9
-rw-r--r--tests/lib/setup.php2
-rw-r--r--tests/lib/share/share.php2
-rw-r--r--tests/lib/tempmanager.php6
-rw-r--r--tests/lib/testcase.php32
17 files changed, 69 insertions, 55 deletions
diff --git a/tests/lib/activitymanager.php b/tests/lib/activitymanager.php
index d3263fa2ede..a35daeaf494 100644
--- a/tests/lib/activitymanager.php
+++ b/tests/lib/activitymanager.php
@@ -156,7 +156,7 @@ class Test_ActivityManager extends \Test\TestCase {
*/
public function testGetUserFromTokenThrowInvalidToken($token, $users) {
$this->mockRSSToken($token, $token, $users);
- \Test_Helper::invokePrivate($this->activityManager, 'getUserFromToken');
+ self::invokePrivate($this->activityManager, 'getUserFromToken');
}
public function getUserFromTokenData() {
diff --git a/tests/lib/appframework/http/RequestTest.php b/tests/lib/appframework/http/RequestTest.php
index 282d13a3397..a4bf3519bfc 100644
--- a/tests/lib/appframework/http/RequestTest.php
+++ b/tests/lib/appframework/http/RequestTest.php
@@ -797,7 +797,7 @@ class RequestTest extends \Test\TestCase {
$this->stream
);
- $this->assertNull(\Test_Helper::invokePrivate($request, 'getOverwriteHost'));
+ $this->assertNull(self::invokePrivate($request, 'getOverwriteHost'));
}
public function testGetOverwriteHostWithOverwrite() {
@@ -824,7 +824,7 @@ class RequestTest extends \Test\TestCase {
$this->stream
);
- $this->assertSame('www.owncloud.org', \Test_Helper::invokePrivate($request, 'getOverwriteHost'));
+ $this->assertSame('www.owncloud.org', self::invokePrivate($request, 'getOverwriteHost'));
}
public function testGetPathInfoWithSetEnv() {
diff --git a/tests/lib/encryption/keys/storage.php b/tests/lib/encryption/keys/storage.php
index 45cd272cca0..52717bcdc29 100644
--- a/tests/lib/encryption/keys/storage.php
+++ b/tests/lib/encryption/keys/storage.php
@@ -382,7 +382,7 @@ class StorageTest extends TestCase {
'/user1/files_encryption',
'/user1');
- \Test_Helper::invokePrivate($this->storage, 'keySetPreparation', array('/user1/files_encryption/keys/foo'));
+ self::invokePrivate($this->storage, 'keySetPreparation', array('/user1/files_encryption/keys/foo'));
}
public function mkdirCallback() {
diff --git a/tests/lib/encryption/managertest.php b/tests/lib/encryption/managertest.php
index 3b1e07ffd69..249f63a81d2 100644
--- a/tests/lib/encryption/managertest.php
+++ b/tests/lib/encryption/managertest.php
@@ -127,7 +127,7 @@ class ManagerTest extends TestCase {
$en0 = $this->manager->getEncryptionModule('ID0');
$this->assertEquals('ID0', $en0->getId());
- $en0 = \Test_Helper::invokePrivate($this->manager, 'getDefaultEncryptionModule');
+ $en0 = self::invokePrivate($this->manager, 'getDefaultEncryptionModule');
$this->assertEquals('ID0', $en0->getId());
$this->assertEquals('ID0', $this->manager->getDefaultEncryptionModuleId());
diff --git a/tests/lib/files/pathverificationtest.php b/tests/lib/files/pathverificationtest.php
index 65342c7799e..b59aceba7b1 100644
--- a/tests/lib/files/pathverificationtest.php
+++ b/tests/lib/files/pathverificationtest.php
@@ -94,7 +94,7 @@ class PathVerification extends \Test\TestCase {
$storage = new Local(['datadir' => '']);
$fileName = " 123{$fileName}456 ";
- \Test_Helper::invokePrivate($storage, 'verifyWindowsPath', [$fileName]);
+ self::invokePrivate($storage, 'verifyWindowsPath', [$fileName]);
}
public function providesInvalidCharsWindows() {
@@ -151,7 +151,7 @@ class PathVerification extends \Test\TestCase {
$storage = new Local(['datadir' => '']);
$fileName = " 123{$fileName}456 ";
- \Test_Helper::invokePrivate($storage, 'verifyWindowsPath', [$fileName]);
+ self::invokePrivate($storage, 'verifyWindowsPath', [$fileName]);
}
public function providesInvalidCharsPosix() {
@@ -200,7 +200,7 @@ class PathVerification extends \Test\TestCase {
public function testPathVerificationReservedNamesWindows($fileName) {
$storage = new Local(['datadir' => '']);
- \Test_Helper::invokePrivate($storage, 'verifyWindowsPath', [$fileName]);
+ self::invokePrivate($storage, 'verifyWindowsPath', [$fileName]);
}
public function providesReservedNamesWindows() {
@@ -236,8 +236,8 @@ class PathVerification extends \Test\TestCase {
public function testPathVerificationValidPaths($fileName) {
$storage = new Local(['datadir' => '']);
- \Test_Helper::invokePrivate($storage, 'verifyPosixPath', [$fileName]);
- \Test_Helper::invokePrivate($storage, 'verifyWindowsPath', [$fileName]);
+ self::invokePrivate($storage, 'verifyPosixPath', [$fileName]);
+ self::invokePrivate($storage, 'verifyWindowsPath', [$fileName]);
// nothing thrown
$this->assertTrue(true);
}
diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php
index d286978d926..520091df42d 100644
--- a/tests/lib/files/storage/wrapper/encryption.php
+++ b/tests/lib/files/storage/wrapper/encryption.php
@@ -355,7 +355,7 @@ class Encryption extends \Test\Files\Storage\Storage {
}
$this->assertSame($expected,
- \Test_Helper::invokePrivate($this->instance, 'copyKeys', ['/source', '/target'])
+ self::invokePrivate($this->instance, 'copyKeys', ['/source', '/target'])
);
}
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index 03c6dacde64..bd527de160d 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -509,28 +509,9 @@ class Test_Helper extends \Test\TestCase {
* @param $methodName
* @param array $parameters
* @return mixed
+ * @deprecated Please extend \Test\TestCase and use self::invokePrivate() then
*/
public static function invokePrivate($object, $methodName, array $parameters = array()) {
- $reflection = new ReflectionClass(get_class($object));
-
- if ($reflection->hasMethod($methodName)) {
- $method = $reflection->getMethod($methodName);
-
- $method->setAccessible(true);
-
- return $method->invokeArgs($object, $parameters);
- } elseif ($reflection->hasProperty($methodName)) {
- $property = $reflection->getProperty($methodName);
-
- $property->setAccessible(true);
-
- if (!empty($parameters)) {
- $property->setValue($object, array_pop($parameters));
- }
-
- return $property->getValue($object);
- }
-
- return false;
+ return parent::invokePrivate($object, $methodName, $parameters);
}
}
diff --git a/tests/lib/http/client/clienttest.php b/tests/lib/http/client/clienttest.php
index bd909769b09..c76fe0532a7 100644
--- a/tests/lib/http/client/clienttest.php
+++ b/tests/lib/http/client/clienttest.php
@@ -47,7 +47,7 @@ class ClientTest extends \Test\TestCase {
->method('getSystemValue')
->with('proxyuserpwd', null)
->willReturn(null);
- $this->assertSame('', \Test_Helper::invokePrivate($this->client, 'getProxyUri'));
+ $this->assertSame('', self::invokePrivate($this->client, 'getProxyUri'));
}
public function testGetProxyUriProxyHostEmptyPassword() {
@@ -61,7 +61,7 @@ class ClientTest extends \Test\TestCase {
->method('getSystemValue')
->with('proxyuserpwd', null)
->willReturn(null);
- $this->assertSame('foo', \Test_Helper::invokePrivate($this->client, 'getProxyUri'));
+ $this->assertSame('foo', self::invokePrivate($this->client, 'getProxyUri'));
}
public function testGetProxyUriProxyHostWithPassword() {
@@ -75,7 +75,7 @@ class ClientTest extends \Test\TestCase {
->method('getSystemValue')
->with('proxyuserpwd', null)
->willReturn('username:password');
- $this->assertSame('username:password@foo', \Test_Helper::invokePrivate($this->client, 'getProxyUri'));
+ $this->assertSame('username:password@foo', self::invokePrivate($this->client, 'getProxyUri'));
}
public function testGet() {
diff --git a/tests/lib/mail/mailer.php b/tests/lib/mail/mailer.php
index 7e5e689741a..21565f9ffb5 100644
--- a/tests/lib/mail/mailer.php
+++ b/tests/lib/mail/mailer.php
@@ -35,7 +35,7 @@ class MailerTest extends TestCase {
}
public function testGetMailInstance() {
- $this->assertEquals(\Swift_MailTransport::newInstance(), \Test_Helper::invokePrivate($this->mailer, 'getMailinstance'));
+ $this->assertEquals(\Swift_MailTransport::newInstance(), self::invokePrivate($this->mailer, 'getMailinstance'));
}
public function testGetSendMailInstanceSendMail() {
@@ -45,7 +45,7 @@ class MailerTest extends TestCase {
->with('mail_smtpmode', 'sendmail')
->will($this->returnValue('sendmail'));
- $this->assertEquals(\Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'), \Test_Helper::invokePrivate($this->mailer, 'getSendMailInstance'));
+ $this->assertEquals(\Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'), self::invokePrivate($this->mailer, 'getSendMailInstance'));
}
public function testGetSendMailInstanceSendMailQmail() {
@@ -55,11 +55,11 @@ class MailerTest extends TestCase {
->with('mail_smtpmode', 'sendmail')
->will($this->returnValue('qmail'));
- $this->assertEquals(\Swift_SendmailTransport::newInstance('/var/qmail/bin/sendmail -bs'), \Test_Helper::invokePrivate($this->mailer, 'getSendMailInstance'));
+ $this->assertEquals(\Swift_SendmailTransport::newInstance('/var/qmail/bin/sendmail -bs'), self::invokePrivate($this->mailer, 'getSendMailInstance'));
}
public function testGetInstanceDefault() {
- $this->assertInstanceOf('\Swift_MailTransport', \Test_Helper::invokePrivate($this->mailer, 'getInstance'));
+ $this->assertInstanceOf('\Swift_MailTransport', self::invokePrivate($this->mailer, 'getInstance'));
}
public function testGetInstancePhp() {
@@ -68,7 +68,7 @@ class MailerTest extends TestCase {
->method('getSystemValue')
->will($this->returnValue('php'));
- $this->assertInstanceOf('\Swift_MailTransport', \Test_Helper::invokePrivate($this->mailer, 'getInstance'));
+ $this->assertInstanceOf('\Swift_MailTransport', self::invokePrivate($this->mailer, 'getInstance'));
}
public function testGetInstanceSendmail() {
@@ -77,7 +77,7 @@ class MailerTest extends TestCase {
->method('getSystemValue')
->will($this->returnValue('sendmail'));
- $this->assertInstanceOf('\Swift_SendmailTransport', \Test_Helper::invokePrivate($this->mailer, 'getInstance'));
+ $this->assertInstanceOf('\Swift_SendmailTransport', self::invokePrivate($this->mailer, 'getInstance'));
}
public function testCreateMessage() {
diff --git a/tests/lib/mail/message.php b/tests/lib/mail/message.php
index c75cc18b650..8ee3c33627c 100644
--- a/tests/lib/mail/message.php
+++ b/tests/lib/mail/message.php
@@ -42,7 +42,7 @@ class MessageTest extends TestCase {
* @dataProvider mailAddressProvider
*/
public function testConvertAddresses($unconverted, $expected) {
- $this->assertSame($expected, \Test_Helper::invokePrivate($this->message, 'convertAddresses', array($unconverted)));
+ $this->assertSame($expected, self::invokePrivate($this->message, 'convertAddresses', array($unconverted)));
}
public function testSetFrom() {
diff --git a/tests/lib/ocsclienttest.php b/tests/lib/ocsclienttest.php
index f4bf1536291..ca8a2a2a2e8 100644
--- a/tests/lib/ocsclienttest.php
+++ b/tests/lib/ocsclienttest.php
@@ -76,7 +76,7 @@ class OCSClientTest extends \Test\TestCase {
->method('getSystemValue')
->with('appstoreurl', 'https://api.owncloud.com/v1')
->will($this->returnValue('https://api.owncloud.com/v1'));
- $this->assertSame('https://api.owncloud.com/v1', Test_Helper::invokePrivate($this->ocsClient, 'getAppStoreUrl'));
+ $this->assertSame('https://api.owncloud.com/v1', self::invokePrivate($this->ocsClient, 'getAppStoreUrl'));
}
public function testGetCategoriesDisabledAppStore() {
diff --git a/tests/lib/repair/cleantags.php b/tests/lib/repair/cleantags.php
index 75bbbd07503..b455aa870fb 100644
--- a/tests/lib/repair/cleantags.php
+++ b/tests/lib/repair/cleantags.php
@@ -64,15 +64,15 @@ class CleanTags extends \Test\TestCase {
$this->assertEntryCount('*PREFIX*vcategory_to_object', 4, 'Assert tag entries count before repair step');
$this->assertEntryCount('*PREFIX*vcategory', 4, 'Assert tag categories count before repair step');
- \Test_Helper::invokePrivate($this->repair, 'deleteOrphanFileEntries');
+ self::invokePrivate($this->repair, 'deleteOrphanFileEntries');
$this->assertEntryCount('*PREFIX*vcategory_to_object', 3, 'Assert tag entries count after cleaning file entries');
$this->assertEntryCount('*PREFIX*vcategory', 4, 'Assert tag categories count after cleaning file entries');
- \Test_Helper::invokePrivate($this->repair, 'deleteOrphanTagEntries');
+ self::invokePrivate($this->repair, 'deleteOrphanTagEntries');
$this->assertEntryCount('*PREFIX*vcategory_to_object', 2, 'Assert tag entries count after cleaning tag entries');
$this->assertEntryCount('*PREFIX*vcategory', 4, 'Assert tag categories count after cleaning tag entries');
- \Test_Helper::invokePrivate($this->repair, 'deleteOrphanCategoryEntries');
+ self::invokePrivate($this->repair, 'deleteOrphanCategoryEntries');
$this->assertEntryCount('*PREFIX*vcategory_to_object', 2, 'Assert tag entries count after cleaning category entries');
$this->assertEntryCount('*PREFIX*vcategory', 2, 'Assert tag categories count after cleaning category entries');
}
diff --git a/tests/lib/security/hasher.php b/tests/lib/security/hasher.php
index 330789c67a0..a6f7df5b79f 100644
--- a/tests/lib/security/hasher.php
+++ b/tests/lib/security/hasher.php
@@ -11,7 +11,7 @@ use OC\Security\Hasher;
/**
* Class HasherTest
*/
-class HasherTest extends \PHPUnit_Framework_TestCase {
+class HasherTest extends \Test\TestCase {
/**
* @return array
@@ -70,14 +70,15 @@ class HasherTest extends \PHPUnit_Framework_TestCase {
);
}
-
-
/** @var Hasher */
protected $hasher;
+
/** @var \OCP\IConfig */
protected $config;
protected function setUp() {
+ parent::setUp();
+
$this->config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()->getMock();
@@ -93,7 +94,7 @@ class HasherTest extends \PHPUnit_Framework_TestCase {
* @dataProvider versionHashProvider
*/
function testSplitHash($hash, $expected) {
- $relativePath = \Test_Helper::invokePrivate($this->hasher, 'splitHash', array($hash));
+ $relativePath = self::invokePrivate($this->hasher, 'splitHash', array($hash));
$this->assertSame($expected, $relativePath);
}
diff --git a/tests/lib/setup.php b/tests/lib/setup.php
index caaeec08fb3..79ca0c0be90 100644
--- a/tests/lib/setup.php
+++ b/tests/lib/setup.php
@@ -120,7 +120,7 @@ class Test_OC_Setup extends \Test\TestCase {
* If it hasn't this test will fail.
*/
public function testHtaccessIsCurrent() {
- $result = Test_Helper::invokePrivate(
+ $result = self::invokePrivate(
$this->setupClass,
'isCurrentHtaccess'
);
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index 5909102f797..f03ed43e7fc 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -1051,7 +1051,7 @@ class Test_Share extends \Test\TestCase {
*/
function testRemoveProtocolFromUrl($url, $expectedResult) {
$share = new \OC\Share\Share();
- $result = \Test_Helper::invokePrivate($share, 'removeProtocolFromUrl', array($url));
+ $result = self::invokePrivate($share, 'removeProtocolFromUrl', array($url));
$this->assertSame($expectedResult, $result);
}
diff --git a/tests/lib/tempmanager.php b/tests/lib/tempmanager.php
index 72741d0dec6..0fa025d44c8 100644
--- a/tests/lib/tempmanager.php
+++ b/tests/lib/tempmanager.php
@@ -154,7 +154,7 @@ class TempManager extends \Test\TestCase {
public function testBuildFileNameWithPostfix() {
$logger = $this->getMock('\Test\NullLogger');
- $tmpManager = \Test_Helper::invokePrivate(
+ $tmpManager = self::invokePrivate(
$this->getManager($logger),
'buildFileNameWithSuffix',
['/tmp/myTemporaryFile', 'postfix']
@@ -165,7 +165,7 @@ class TempManager extends \Test\TestCase {
public function testBuildFileNameWithoutPostfix() {
$logger = $this->getMock('\Test\NullLogger');
- $tmpManager = \Test_Helper::invokePrivate(
+ $tmpManager = self::invokePrivate(
$this->getManager($logger),
'buildFileNameWithSuffix',
['/tmp/myTemporaryFile', '']
@@ -176,7 +176,7 @@ class TempManager extends \Test\TestCase {
public function testBuildFileNameWithSuffixPathTraversal() {
$logger = $this->getMock('\Test\NullLogger');
- $tmpManager = \Test_Helper::invokePrivate(
+ $tmpManager = self::invokePrivate(
$this->getManager($logger),
'buildFileNameWithSuffix',
['foo', '../Traversal\\../FileName']
diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php
index d8595c83a91..8551edab71f 100644
--- a/tests/lib/testcase.php
+++ b/tests/lib/testcase.php
@@ -50,6 +50,38 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
}
/**
+ * Allows us to test private methods/properties
+ *
+ * @param $object
+ * @param $methodName
+ * @param array $parameters
+ * @return mixed
+ */
+ protected static function invokePrivate($object, $methodName, array $parameters = array()) {
+ $reflection = new \ReflectionClass(get_class($object));
+
+ if ($reflection->hasMethod($methodName)) {
+ $method = $reflection->getMethod($methodName);
+
+ $method->setAccessible(true);
+
+ return $method->invokeArgs($object, $parameters);
+ } elseif ($reflection->hasProperty($methodName)) {
+ $property = $reflection->getProperty($methodName);
+
+ $property->setAccessible(true);
+
+ if (!empty($parameters)) {
+ $property->setValue($object, array_pop($parameters));
+ }
+
+ return $property->getValue($object);
+ }
+
+ return false;
+ }
+
+ /**
* Returns a unique identifier as uniqid() is not reliable sometimes
*
* @param string $prefix