This commit is contained in:
sualko 2020-06-30 14:53:20 +02:00
Родитель c083263a50
Коммит bce9f19002
16 изменённых файлов: 82 добавлений и 77 удалений

Просмотреть файл

@ -2,21 +2,16 @@
convertErrorsToExceptions="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
colors="true"
> >
<testsuites> <testsuites>
<testsuite name="integration"> <testsuite name="integration">
<directory>./tests/integration</directory> <directory>tests/Integration</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<filter> <filter>
<whitelist processUncoveredFilesFromWhitelist="true"> <whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">lib/db</directory> <directory suffix=".php">lib</directory>
<file>lib/dblock.php</file>
<file>lib/memlock.php</file>
<file>lib/User.php</file>
<file>lib/ContactsStoreUserProvider.php</file>
<file>lib/UserManagerUserProvider.php</file>
<file>lib/rosterpush.php</file>
</whitelist> </whitelist>
</filter> </filter>
</phpunit> </phpunit>

Просмотреть файл

@ -2,26 +2,16 @@
convertErrorsToExceptions="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
colors="true"
> >
<testsuites> <testsuites>
<testsuite name="unit"> <testsuite name="unit">
<directory>./tests/unit</directory> <directory>tests/unit</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<filter> <filter>
<whitelist processUncoveredFilesFromWhitelist="true"> <whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">lib</directory> <directory suffix=".php">lib</directory>
<exclude>
<directory suffix=".php">lib/ContactsMenu</directory>
<directory suffix=".php">lib/db</directory>
<!-- The following three files are tested in the integration test suite -->
<file>lib/ilock.php</file>
<file>lib/memlock.php</file>
<file>lib/dblock.php</file>
<!-- The following two files are simple wrappers around other code -->
<file>lib/command/refreshroster.php</file>
<file>lib/Migration/RefreshRoster.php</file>
</exclude>
</whitelist> </whitelist>
</filter> </filter>
</phpunit> </phpunit>

Просмотреть файл

@ -1,6 +1,6 @@
<?php <?php
namespace OCA\OJSXC; namespace OCA\OJSXC\Tests\Integration;
use OC\Contacts\ContactsMenu\ContactsStore; use OC\Contacts\ContactsMenu\ContactsStore;
use OCA\DAV\CardDAV\AddressBookImpl; use OCA\DAV\CardDAV\AddressBookImpl;
@ -15,7 +15,7 @@ use OCA\DAV\AppInfo\Application as DavApp;
use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\CardDAV\CardDavBackend;
use PHPUnit\Framework\Constraint\IsEqual; use PHPUnit\Framework\Constraint\IsEqual;
use Sabre\VObject\Component\VCard; use Sabre\VObject\Component\VCard;
use OCA\OJSXC\Utility\TestCase; use OCA\OJSXC\Tests\Utility\TestCase;
class ContactsStoreUserProviderTest extends TestCase class ContactsStoreUserProviderTest extends TestCase
{ {

Просмотреть файл

@ -1,8 +1,8 @@
<?php <?php
namespace OCA\OJSXC\Db; namespace OCA\OJSXC\Tests\Integration\Db;
use Sabre\Xml\Writer; use Sabre\Xml\Writer;
use OCA\OJSXC\Utility\TestCase; use OCA\OJSXC\Tests\Utility\TestCase;
class IqRosterPushTest extends TestCase class IqRosterPushTest extends TestCase
{ {

Просмотреть файл

@ -1,8 +1,8 @@
<?php <?php
namespace OCA\OJSXC\Db; namespace OCA\OJSXC\Tests\Integration\Db;
use Sabre\Xml\Writer; use Sabre\Xml\Writer;
use OCA\OJSXC\Utility\TestCase; use OCA\OJSXC\Tests\Utility\TestCase;
class IqRosterTest extends TestCase class IqRosterTest extends TestCase
{ {

Просмотреть файл

@ -1,9 +1,9 @@
<?php <?php
namespace OCA\OJSXC\Db; namespace OCA\OJSXC\Tests\Integration\Db;
use OCA\OJSXC\AppInfo\Application; use OCA\OJSXC\AppInfo\Application;
use OCA\OJSXC\Utility\MapperTestUtility; use OCA\OJSXC\Tests\Utility\MapperTestUtility;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
function uniqid() function uniqid()

Просмотреть файл

@ -1,11 +1,11 @@
<?php <?php
namespace OCA\OJSXC\Db; namespace OCA\OJSXC\Tests\Integration\Db;
use OCA\OJSXC\AppInfo\Application; use OCA\OJSXC\AppInfo\Application;
use OCA\OJSXC\Db\Presence as PresenceEntity; use OCA\OJSXC\Db\Presence as PresenceEntity;
use OCA\OJSXC\NewContentContainer; use OCA\OJSXC\NewContentContainer;
use OCA\OJSXC\Utility\MapperTestUtility; use OCA\OJSXC\Tests\Utility\MapperTestUtility;
use OCA\DAV\AppInfo\Application as DavApp; use OCA\DAV\AppInfo\Application as DavApp;
$time = 0; $time = 0;

Просмотреть файл

@ -1,12 +1,12 @@
<?php <?php
namespace OCA\OJSXC\Db; namespace OCA\OJSXC\Tests\Integration\Db;
use Sabre\Xml\Reader; use Sabre\Xml\Reader;
use Sabre\Xml\Writer; use Sabre\Xml\Writer;
use Sabre\Xml\LibXMLException; use Sabre\Xml\LibXMLException;
use Sabre\Xml\ParseException; use Sabre\Xml\ParseException;
use OCA\OJSXC\Utility\TestCase; use OCA\OJSXC\Tests\Utility\TestCase;
class PresenceTest extends TestCase class PresenceTest extends TestCase
{ {

Просмотреть файл

@ -1,8 +1,8 @@
<?php <?php
namespace OCA\OJSXC\Db; namespace OCA\OJSXC\Tests\Integration\Db;
use OCA\OJSXC\Utility\MapperTestUtility; use OCA\OJSXC\Tests\Utility\MapperTestUtility;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
/** /**

Просмотреть файл

@ -1,8 +1,8 @@
<?php <?php
namespace OCA\OJSXC; namespace OCA\OJSXC\Tests\Integration;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use Test\TestCase; use PHPUnit\Framework\TestCase;
use OCA\OJSXC\AppInfo\Application; use OCA\OJSXC\AppInfo\Application;
use OCA\OJSXC\DbLock; use OCA\OJSXC\DbLock;

Просмотреть файл

@ -1,8 +1,8 @@
<?php <?php
namespace OCA\OJSXC; namespace OCA\OJSXC\Tests\Integration;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use Test\TestCase; use PHPUnit\Framework\TestCase;
use OCA\OJSXC\AppInfo\Application; use OCA\OJSXC\AppInfo\Application;
use OCA\OJSXC\MemLock; use OCA\OJSXC\MemLock;
@ -43,11 +43,6 @@ class MemLockTest extends TestCase
parent::setUp(); parent::setUp();
$app = new Application(); $app = new Application();
$this->container = $app->getContainer(); $this->container = $app->getContainer();
$version = \OC::$server->getSession()->get('OC_Version');
if ($version[0] === 8 && $version[1] == 0) {
$this->markTestSkipped();
}
} }
/** /**
@ -62,7 +57,8 @@ class MemLockTest extends TestCase
if ($cache->isAvailable()) { if ($cache->isAvailable()) {
$this->memCache = $cache->create('ojsxc'); $this->memCache = $cache->create('ojsxc');
} else { } else {
die('No memcache available'); $this->markTestSkipped();
return;
} }
$this->memLock = new MemLock( $this->memLock = new MemLock(

Просмотреть файл

@ -1,6 +1,6 @@
<?php <?php
namespace OCA\OJSXC; namespace OCA\OJSXC\Tests\Integration;
use OCA\OJSXC\AppInfo\Application; use OCA\OJSXC\AppInfo\Application;
use OCA\OJSXC\Db\IQRosterPushMapper; use OCA\OJSXC\Db\IQRosterPushMapper;

Просмотреть файл

@ -0,0 +1,20 @@
<?php
namespace OCA\OJSXC\Tests\Integration;
use OCA\OJSXC\User;
use PHPUnit\Framework\TestCase;
class UserTest extends TestCase
{
public function test()
{
$user1 = new User(" test @ 'abc", 'Test123', null);
$this->assertEquals($user1->getFullName(), 'Test123');
$this->assertEquals($user1->getUid(), '_ojsxc_esc_space_test_ojsxc_esc_space__ojsxc_esc_at__ojsxc_esc_space__ojsxc_squote_space_abc');
$user1->setUid('test1');
$user1->setFullName('test2');
$this->assertEquals($user1->getUid(), 'test1');
$this->assertEquals($user1->getFullName(), 'test2');
}
}

Просмотреть файл

@ -1,13 +1,14 @@
<?php <?php
namespace OCA\OJSXC\Utility; namespace OCA\OJSXC\Tests\Utility;
use OCA\OJSXC\AppInfo\Application; use OCA\OJSXC\AppInfo\Application;
/** /**
* @group DB * @group DB
*/ */
class MapperTestUtility extends TestCase { class MapperTestUtility extends TestCase
{
/** /**
* @var \OCP\AppFramework\IAppContainer * @var \OCP\AppFramework\IAppContainer
@ -26,7 +27,7 @@ class MapperTestUtility extends TestCase {
{ {
parent::setUp(); parent::setUp();
$app = new Application(); $app = new Application();
$this->overwriteApplicationService($app, 'Host','localhost'); $this->overwriteApplicationService($app, 'Host', 'localhost');
$this->overwriteApplicationService($app, 'UserId', 'admin'); $this->overwriteApplicationService($app, 'UserId', 'admin');
$this->container = $app->getContainer(); $this->container = $app->getContainer();
$this->mapper = $this->container[$this->mapperName]; $this->mapper = $this->container[$this->mapperName];
@ -38,18 +39,21 @@ class MapperTestUtility extends TestCase {
$con->executeQuery('DELETE FROM ' . $this->mapper->getTableName()); $con->executeQuery('DELETE FROM ' . $this->mapper->getTableName());
} }
protected function tearDown(): void { protected function tearDown(): void
{
$con = $this->container->getServer()->getDatabaseConnection(); $con = $this->container->getServer()->getDatabaseConnection();
$con->executeQuery('DELETE FROM ' . $this->mapper->getTableName()); $con->executeQuery('DELETE FROM ' . $this->mapper->getTableName());
} }
protected function fetchAll(){ protected function fetchAll()
{
$con = $this->container->getServer()->getDatabaseConnection(); $con = $this->container->getServer()->getDatabaseConnection();
$stmt = $con->executeQuery('SELECT * FROM ' . $this->mapper->getTableName()); $stmt = $con->executeQuery('SELECT * FROM ' . $this->mapper->getTableName());
$entities = []; $entities = [];
while($row = $stmt->fetch()){ while ($row = $stmt->fetch()) {
$entities[] = call_user_func($this->entityName . '::fromRow', $row);; $entities[] = call_user_func($this->entityName . '::fromRow', $row);
;
} }
$stmt->closeCursor(); $stmt->closeCursor();
@ -57,7 +61,8 @@ class MapperTestUtility extends TestCase {
return $entities; return $entities;
} }
protected function fetchAllAsArray($tableName = null){ protected function fetchAllAsArray($tableName = null)
{
if (is_null($tableName)) { if (is_null($tableName)) {
$tableName = $this->mapper->getTableName(); $tableName = $this->mapper->getTableName();
} else { } else {
@ -66,7 +71,7 @@ class MapperTestUtility extends TestCase {
$stmt = $con->executeQuery('SELECT * FROM ' . $tableName); $stmt = $con->executeQuery('SELECT * FROM ' . $tableName);
$result = []; $result = [];
while($row = $stmt->fetch()){ while ($row = $stmt->fetch()) {
$result[] = $row; $result[] = $row;
} }
$stmt->closeCursor(); $stmt->closeCursor();
@ -74,9 +79,8 @@ class MapperTestUtility extends TestCase {
return $result; return $result;
} }
public function getLastInsertedId() { public function getLastInsertedId()
{
return $this->container->getServer()->getDatabaseConnection()->lastInsertId(); return $this->container->getServer()->getDatabaseConnection()->lastInsertId();
} }
} }

Просмотреть файл

@ -1,22 +1,22 @@
<?php <?php
namespace OCA\OJSXC\Utility; namespace OCA\OJSXC\Tests\Utility;
use OCA\OJSXC\AppInfo\Application; use OCA\OJSXC\AppInfo\Application;
use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\Entity;
use Sabre\Xml\Service; use Sabre\Xml\Service;
use Test\TestCase as CoreTestCase; use PHPUnit\Framework\TestCase as CoreTestCase;
class TestCase extends CoreTestCase { class TestCase extends CoreTestCase
{
public static function assertSabreXmlEqualsXml($expected, $actual) { public static function assertSabreXmlEqualsXml($expected, $actual)
{
$service = new Service(); $service = new Service();
$parsedExpected = $service->parse("<?xml version=\"1.0\" encoding=\"utf-8\"?><unit-wrapper>" . $expected . "</unit-wrapper>"); $parsedExpected = $service->parse("<?xml version=\"1.0\" encoding=\"utf-8\"?><unit-wrapper>" . $expected . "</unit-wrapper>");
$parsedActual = $service->parse("<?xml version=\"1.0\" encoding=\"utf-8\"?><unit-wrapper>" . $actual . "</unit-wrapper>"); $parsedActual = $service->parse("<?xml version=\"1.0\" encoding=\"utf-8\"?><unit-wrapper>" . $actual . "</unit-wrapper>");
self::assertEquals($parsedExpected, $parsedActual, 'Failed asserting that two XML strings are equal.'); self::assertEquals($parsedExpected, $parsedActual, 'Failed asserting that two XML strings are equal.');
} }
/** /**
@ -24,7 +24,8 @@ class TestCase extends CoreTestCase {
* @param Entity[] $actual * @param Entity[] $actual
* @param array $fields Use camelCase for this instead of snake_case! * @param array $fields Use camelCase for this instead of snake_case!
*/ */
public static function assertObjectDbResultsEqual($expected, $actual, array $fields) { public static function assertObjectDbResultsEqual($expected, $actual, array $fields)
{
$expectedArray = []; $expectedArray = [];
$actualArray = []; $actualArray = [];
@ -39,7 +40,8 @@ class TestCase extends CoreTestCase {
self::assertArrayDbResultsEqual($expectedArray, $actualArray, $fields); self::assertArrayDbResultsEqual($expectedArray, $actualArray, $fields);
} }
public static function assertArrayDbResultsEqual(array $expected, array $actual, array $fields) { public static function assertArrayDbResultsEqual(array $expected, array $actual, array $fields)
{
$expectedFiltered = []; $expectedFiltered = [];
$actualFiltered = []; $actualFiltered = [];
@ -64,10 +66,10 @@ class TestCase extends CoreTestCase {
self::assertCount(count($expected), $actual); self::assertCount(count($expected), $actual);
self::assertEquals($expectedFiltered, $actualFiltered); self::assertEquals($expectedFiltered, $actualFiltered);
} }
public function overwriteApplicationService(Application $app, $name, $newService) { public function overwriteApplicationService(Application $app, $name, $newService)
{
$app->getContainer()->registerService($name, function () use ($newService) { $app->getContainer()->registerService($name, function () use ($newService) {
return $newService; return $newService;
}); });
@ -79,12 +81,12 @@ class TestCase extends CoreTestCase {
* @param $name * @param $name
* @param $newValue * @param $newValue
*/ */
public function setValueOfPrivateProperty($obj, $name, $newValue) { public function setValueOfPrivateProperty($obj, $name, $newValue)
{
$refl = new \ReflectionObject($obj); $refl = new \ReflectionObject($obj);
$p = $refl->getProperty($name); $p = $refl->getProperty($name);
$p->setAccessible(true); $p->setAccessible(true);
$p->setValue($obj, $newValue); $p->setValue($obj, $newValue);
$p->setAccessible(false); $p->setAccessible(false);
} }
}
}

Просмотреть файл

@ -1,13 +1,11 @@
<?php <?php
define('PHPUNIT_RUN', 1);
$nc_root = __DIR__ . '/../../..'; $nc_root = __DIR__ . '/../../..';
@include 'bootstrap-config.development.php'; @include 'bootstrap-config.development.php';
echo "Using ".realpath($nc_root)." as Nextcloud root.\n\n"; require_once $nc_root . '/lib/base.php';
try {
require_once $nc_root . '/tests/bootstrap.php';
} catch (Exception $ex) {
require_once $nc_root . '/lib/base.php';
}
require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../vendor/autoload.php';
\OC::$composerAutoloader->addPsr4('OCA\\OJSXC\\Tests\\', __DIR__, true);