diff --git a/templates/main.php b/templates/main.php
index 579525daf..047404f4e 100644
--- a/templates/main.php
+++ b/templates/main.php
@@ -1,5 +1,5 @@
+script($appId, $appId . '-report-error-map-action');
diff --git a/tests/Integration/AppTest.php b/tests/Integration/AppTest.php
index 1ddc7d7a9..6c3911bd0 100644
--- a/tests/Integration/AppTest.php
+++ b/tests/Integration/AppTest.php
@@ -13,7 +13,6 @@
use OCP\AppFramework\App;
-
/**
* This test shows how to make a small Integration Test. Query your class
* directly from the container, only pass in mocks if needed and run your tests
@@ -21,15 +20,15 @@
*/
class AppTest extends \PHPUnit\Framework\TestCase {
- private $container;
+ private $container;
- protected function setUp(): void {
- $app = new App('maps');
- $this->container = $app->getContainer();
- }
+ protected function setUp(): void {
+ $app = new App('maps');
+ $this->container = $app->getContainer();
+ }
- public function testAppInstalled() {
- $appManager = $this->container->query(\OCP\App\IAppManager::class);
- $this->assertTrue($appManager->isInstalled('maps'));
- }
+ public function testAppInstalled() {
+ $appManager = $this->container->query(\OCP\App\IAppManager::class);
+ $this->assertTrue($appManager->isInstalled('maps'));
+ }
}
diff --git a/tests/Integration/Db/FavoriteShareMapperTest.php b/tests/Integration/Db/FavoriteShareMapperTest.php
index cacd6eb51..95e75ddff 100644
--- a/tests/Integration/Db/FavoriteShareMapperTest.php
+++ b/tests/Integration/Db/FavoriteShareMapperTest.php
@@ -24,7 +24,6 @@
namespace tests\Integration\Db;
-
use ChristophWurst\Nextcloud\Testing\DatabaseTransaction;
use ChristophWurst\Nextcloud\Testing\TestCase;
use OC;
@@ -33,93 +32,93 @@
use OCP\AppFramework\Db\DoesNotExistException;
class FavoriteShareMapperTest extends TestCase {
- use DatabaseTransaction;
+ use DatabaseTransaction;
- /* @var FavoriteShareMapper */
- private $mapper;
+ /* @var FavoriteShareMapper */
+ private $mapper;
- public function setUp(): void {
- parent::setUp();
+ public function setUp(): void {
+ parent::setUp();
- $this->mapper = new FavoriteShareMapper(
- OC::$server->query(\OCP\IDBConnection::class),
- OC::$server->getSecureRandom(),
- OC::$server->getRootFolder()
- );
- }
+ $this->mapper = new FavoriteShareMapper(
+ OC::$server->query(\OCP\IDBConnection::class),
+ OC::$server->getSecureRandom(),
+ OC::$server->getRootFolder()
+ );
+ }
- public function testCreateByOwnerAndTokenIsSuccessful() {
- /* @var FavoriteShare */
- $share = $this->mapper->create("testUser", "testCategory");
+ public function testCreateByOwnerAndTokenIsSuccessful() {
+ /* @var FavoriteShare */
+ $share = $this->mapper->create('testUser', 'testCategory');
- $this->assertIsString($share->getToken());
- $this->assertEquals("testUser", $share->getOwner());
- $this->assertEquals("testCategory", $share->getCategory());
- }
+ $this->assertIsString($share->getToken());
+ $this->assertEquals('testUser', $share->getOwner());
+ $this->assertEquals('testCategory', $share->getCategory());
+ }
- public function testFindByTokenIsSuccessful() {
- /* @var FavoriteShare */
- $shareExpected = $this->mapper->create("testUser", "testCategory");
+ public function testFindByTokenIsSuccessful() {
+ /* @var FavoriteShare */
+ $shareExpected = $this->mapper->create('testUser', 'testCategory');
- /* @var FavoriteShare */
- $shareActual = $this->mapper->findByToken($shareExpected->getToken());
+ /* @var FavoriteShare */
+ $shareActual = $this->mapper->findByToken($shareExpected->getToken());
- $this->assertEquals($shareExpected->getToken(), $shareActual->getToken());
- $this->assertEquals($shareExpected->getOwner(), $shareActual->getOwner());
- $this->assertEquals($shareExpected->getCategory(), $shareActual->getCategory());
- }
+ $this->assertEquals($shareExpected->getToken(), $shareActual->getToken());
+ $this->assertEquals($shareExpected->getOwner(), $shareActual->getOwner());
+ $this->assertEquals($shareExpected->getCategory(), $shareActual->getCategory());
+ }
- public function testFindByOwnerAndCategoryIsSuccessful() {
- /* @var FavoriteShare */
- $shareExpected = $this->mapper->create("testUser", "testCategory");
+ public function testFindByOwnerAndCategoryIsSuccessful() {
+ /* @var FavoriteShare */
+ $shareExpected = $this->mapper->create('testUser', 'testCategory');
- /* @var FavoriteShare */
- $shareActual = $this->mapper->findByOwnerAndCategory("testUser", "testCategory");
+ /* @var FavoriteShare */
+ $shareActual = $this->mapper->findByOwnerAndCategory('testUser', 'testCategory');
- $this->assertEquals($shareExpected->getToken(), $shareActual->getToken());
- $this->assertEquals($shareExpected->getOwner(), $shareActual->getOwner());
- $this->assertEquals($shareExpected->getCategory(), $shareActual->getCategory());
- }
+ $this->assertEquals($shareExpected->getToken(), $shareActual->getToken());
+ $this->assertEquals($shareExpected->getOwner(), $shareActual->getOwner());
+ $this->assertEquals($shareExpected->getCategory(), $shareActual->getCategory());
+ }
- public function testFindAllByOwnerIsSuccessfulAndDoesNotContainOtherShares() {
- /* @var FavoriteShare */
- $share1 = $this->mapper->create("testUser", "testCategory1");
+ public function testFindAllByOwnerIsSuccessfulAndDoesNotContainOtherShares() {
+ /* @var FavoriteShare */
+ $share1 = $this->mapper->create('testUser', 'testCategory1');
- /* @var FavoriteShare */
- $share2 = $this->mapper->create("testUser", "testCategory2");
+ /* @var FavoriteShare */
+ $share2 = $this->mapper->create('testUser', 'testCategory2');
- $this->mapper->create("testUser2", "testCategory");
+ $this->mapper->create('testUser2', 'testCategory');
- /* @var array */
- $shares = $this->mapper->findAllByOwner("testUser");
+ /* @var array */
+ $shares = $this->mapper->findAllByOwner('testUser');
- $shareTokens = array_map(function ($share) {
- return $share->getToken();
- }, $shares);
+ $shareTokens = array_map(function ($share) {
+ return $share->getToken();
+ }, $shares);
- $this->assertEquals(2, count($shareTokens));
- $this->assertContains($share1->getToken(), $shareTokens);
- $this->assertContains($share2->getToken(), $shareTokens);
- }
+ $this->assertEquals(2, count($shareTokens));
+ $this->assertContains($share1->getToken(), $shareTokens);
+ $this->assertContains($share2->getToken(), $shareTokens);
+ }
- public function testFindOrCreateByOwnerAndCategoryIsSuccessful() {
- /* @var FavoriteShare */
- $share = $this->mapper->findOrCreateByOwnerAndCategory("testUser", "testCategory");
+ public function testFindOrCreateByOwnerAndCategoryIsSuccessful() {
+ /* @var FavoriteShare */
+ $share = $this->mapper->findOrCreateByOwnerAndCategory('testUser', 'testCategory');
- $this->assertIsString($share->getToken());
- $this->assertEquals("testUser", $share->getOwner());
- $this->assertEquals("testCategory", $share->getCategory());
- }
+ $this->assertIsString($share->getToken());
+ $this->assertEquals('testUser', $share->getOwner());
+ $this->assertEquals('testCategory', $share->getCategory());
+ }
- public function testRemoveByOwnerAndCategoryIsSuccessful() {
- /* @var FavoriteShare */
- $share = $this->mapper->create("testUser", "testCategory");
+ public function testRemoveByOwnerAndCategoryIsSuccessful() {
+ /* @var FavoriteShare */
+ $share = $this->mapper->create('testUser', 'testCategory');
- $this->mapper->removeByOwnerAndCategory($share->getOwner(), $share->getCategory());
+ $this->mapper->removeByOwnerAndCategory($share->getOwner(), $share->getCategory());
- $this->expectException(DoesNotExistException::class);
+ $this->expectException(DoesNotExistException::class);
- $this->mapper->findByOwnerAndCategory($share->getOwner(), $share->getCategory());
- }
+ $this->mapper->findByOwnerAndCategory($share->getOwner(), $share->getCategory());
+ }
}
diff --git a/tests/Unit/Controller/ContactsControllerTest.php b/tests/Unit/Controller/ContactsControllerTest.php
index e2193157d..d06438c36 100644
--- a/tests/Unit/Controller/ContactsControllerTest.php
+++ b/tests/Unit/Controller/ContactsControllerTest.php
@@ -11,122 +11,116 @@
namespace OCA\Maps\Controller;
-use \OCA\Maps\AppInfo\Application;
-use \OCA\Maps\Service\DevicesService;
-use OCP\AppFramework\Http\TemplateResponse;
+use OCA\DAV\CardDAV\CardDavBackend;
+use OCA\DAV\CardDAV\ContactsManager;
use OCA\DAV\Connector\Sabre\Principal;
+use OCA\Maps\AppInfo\Application;
use OCA\Maps\Service\AddressService;
-use OCP\Files\IAppData;
-use \OCP\IServerContainer;
-use \OCP\EventDispatcher\IEventDispatcher;
-use \OCA\DAV\CardDAV\CardDavBackend;
-use OCA\DAV\CardDAV\ContactsManager;
-use OCP\IURLGenerator;
-
+use OCP\IServerContainer;
class ContactsControllerTest extends \PHPUnit\Framework\TestCase {
- private $appName;
- private $request;
- private $contacts;
+ private $appName;
+ private $request;
+ private $contacts;
private $mapFolder;
- private $container;
- private $config;
- private $app;
+ private $container;
+ private $config;
+ private $app;
- private $contactsController;
- private $contactsController2;
- private $utilsController;
- private $cdBackend;
+ private $contactsController;
+ private $contactsController2;
+ private $utilsController;
+ private $cdBackend;
private $root;
- public static function setUpBeforeClass(): void {
- $app = new Application();
- $c = $app->getContainer();
-
- $user = $c->getServer()->getUserManager()->get('test');
- $user2 = $c->getServer()->getUserManager()->get('test2');
- $user3 = $c->getServer()->getUserManager()->get('test3');
- $group = $c->getServer()->getGroupManager()->get('group1test');
- $group2 = $c->getServer()->getGroupManager()->get('group2test');
-
- // CREATE DUMMY USERS
- if ($user === null) {
- $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
- $u1->setEMailAddress('toto@toto.net');
- }
- if ($user2 === null) {
- $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
- }
- if ($user2 === null) {
- $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
- }
- if ($group === null) {
- $c->getServer()->getGroupManager()->createGroup('group1test');
- $u1 = $c->getServer()->getUserManager()->get('test');
- $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
- }
- if ($group2 === null) {
- $c->getServer()->getGroupManager()->createGroup('group2test');
- $u2 = $c->getServer()->getUserManager()->get('test2');
- $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
- }
- }
-
- protected function setUp(): void {
- $this->app = new Application();
- $c = $this->app->getContainer();
-
- $this->appName = 'maps';
- $this->request = $this->getMockBuilder('\OCP\IRequest')
- ->disableOriginalConstructor()
- ->getMock();
- $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
- ->disableOriginalConstructor()
- ->getMock();
-
- $urlGenerator = $c->getServer()->getURLGenerator();
-
- $this->contactsManager = $c->query(IServerContainer::class)->getContactsManager();
- $this->cm = $c->query(ContactsManager::class);
- $this->cm->setupContactsProvider($this->contactsManager, 'test', $urlGenerator);
-
- $this->app = new Application();
- $this->container = $this->app->getContainer();
- $c = $this->container;
- $this->config = $c->query(IServerContainer::class)->getConfig();
-
- $this->appData = $this->getMockBuilder('\OCP\Files\IAppData')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->addressService = new AddressService(
- $c->query(IServerContainer::class)->getMemCacheFactory(),
- $c->query(IServerContainer::class)->getLogger(),
- $c->query(IServerContainer::class)->getJobList(),
- $this->appData,
- $c->query(IServerContainer::class)->query(\OCP\IDBConnection::class)
- );
-
- //$this->userPrincipalBackend = new Principal(
- // $c->getServer()->getUserManager(),
- // $c->getServer()->getGroupManager(),
- // $c->getServer()->getShareManager(),
- // \OC::$server->getUserSession(),
- // $c->query(IServerContainer::class)->getConfig(),
- // \OC::$server->getAppManager()
- //);
- $this->userPrincipalBackend = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->cdBackend = $c->query(IServerContainer::class)->query(CardDavBackend::class);
+ public static function setUpBeforeClass(): void {
+ $app = new Application();
+ $c = $app->getContainer();
+
+ $user = $c->getServer()->getUserManager()->get('test');
+ $user2 = $c->getServer()->getUserManager()->get('test2');
+ $user3 = $c->getServer()->getUserManager()->get('test3');
+ $group = $c->getServer()->getGroupManager()->get('group1test');
+ $group2 = $c->getServer()->getGroupManager()->get('group2test');
+
+ // CREATE DUMMY USERS
+ if ($user === null) {
+ $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
+ $u1->setEMailAddress('toto@toto.net');
+ }
+ if ($user2 === null) {
+ $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
+ }
+ if ($user2 === null) {
+ $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
+ }
+ if ($group === null) {
+ $c->getServer()->getGroupManager()->createGroup('group1test');
+ $u1 = $c->getServer()->getUserManager()->get('test');
+ $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
+ }
+ if ($group2 === null) {
+ $c->getServer()->getGroupManager()->createGroup('group2test');
+ $u2 = $c->getServer()->getUserManager()->get('test2');
+ $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
+ }
+ }
+
+ protected function setUp(): void {
+ $this->app = new Application();
+ $c = $this->app->getContainer();
+
+ $this->appName = 'maps';
+ $this->request = $this->getMockBuilder('\OCP\IRequest')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $urlGenerator = $c->getServer()->getURLGenerator();
+
+ $this->contactsManager = $c->query(IServerContainer::class)->getContactsManager();
+ $this->cm = $c->query(ContactsManager::class);
+ $this->cm->setupContactsProvider($this->contactsManager, 'test', $urlGenerator);
+
+ $this->app = new Application();
+ $this->container = $this->app->getContainer();
+ $c = $this->container;
+ $this->config = $c->query(IServerContainer::class)->getConfig();
+
+ $this->appData = $this->getMockBuilder('\OCP\Files\IAppData')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->addressService = new AddressService(
+ $c->query(IServerContainer::class)->getMemCacheFactory(),
+ $c->query(IServerContainer::class)->getLogger(),
+ $c->query(IServerContainer::class)->getJobList(),
+ $this->appData,
+ $c->query(IServerContainer::class)->query(\OCP\IDBConnection::class)
+ );
+
+ //$this->userPrincipalBackend = new Principal(
+ // $c->getServer()->getUserManager(),
+ // $c->getServer()->getGroupManager(),
+ // $c->getServer()->getShareManager(),
+ // \OC::$server->getUserSession(),
+ // $c->query(IServerContainer::class)->getConfig(),
+ // \OC::$server->getAppManager()
+ //);
+ $this->userPrincipalBackend = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->cdBackend = $c->query(IServerContainer::class)->query(CardDavBackend::class);
$this->root = $c->query(IServerContainer::class)->getRootFolder();
$this->mapFolder = $this->createMapFolder();
- $this->contactsController = new ContactsController(
+ $this->contactsController = new ContactsController(
$this->appName,
$c->query(IServerContainer::class)->getLogger(),
$this->request,
@@ -138,33 +132,33 @@ protected function setUp(): void {
$c->query(IServerContainer::class)->getAvatarManager(),
$this->root,
$urlGenerator);
- //$this->contactsController = $this->getMockBuilder('OCA\Maps\Controller\ContactsController')
- // ->disableOriginalConstructor()
- // ->getMock();
-
- $this->contactsController2 = new ContactsController(
- $this->appName,
- $c->query(IServerContainer::class)->getLogger(),
- $this->request,
- $c->query(IServerContainer::class)->query(\OCP\IDBConnection::class),
- $this->contactsManager,
- $this->addressService,
- 'test2',
- $this->cdBackend,
- $c->query(IServerContainer::class)->getAvatarManager(),
+ //$this->contactsController = $this->getMockBuilder('OCA\Maps\Controller\ContactsController')
+ // ->disableOriginalConstructor()
+ // ->getMock();
+
+ $this->contactsController2 = new ContactsController(
+ $this->appName,
+ $c->query(IServerContainer::class)->getLogger(),
+ $this->request,
+ $c->query(IServerContainer::class)->query(\OCP\IDBConnection::class),
+ $this->contactsManager,
+ $this->addressService,
+ 'test2',
+ $this->cdBackend,
+ $c->query(IServerContainer::class)->getAvatarManager(),
$this->root,
$urlGenerator
- );
+ );
- $this->utilsController = new UtilsController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getAppManager(),
+ $this->utilsController = new UtilsController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getAppManager(),
$this->root,
- 'test'
- );
- }
+ 'test'
+ );
+ }
private function createMapFolder() {
$userFolder = $this->root->getUserFolder('test');
@@ -175,26 +169,26 @@ private function createMapFolder() {
}
}
- public static function tearDownAfterClass(): void {
- }
-
- protected function tearDown(): void {
- // in case there was a failure and something was not deleted
- }
-
- public function testAddContact() {
- $c = $this->container;
- //$this->contacts->createOrUpdate()
- //var_dump($this->contactsManager->isEnabled());
- // TODO understand why this only returns system address book
- //var_dump($this->contactsManager->getUserAddressBooks());
-
- $resp = $this->contactsController->getContacts();
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- //var_dump($data);
- }
+ public static function tearDownAfterClass(): void {
+ }
+
+ protected function tearDown(): void {
+ // in case there was a failure and something was not deleted
+ }
+
+ public function testAddContact() {
+ $c = $this->container;
+ //$this->contacts->createOrUpdate()
+ //var_dump($this->contactsManager->isEnabled());
+ // TODO understand why this only returns system address book
+ //var_dump($this->contactsManager->getUserAddressBooks());
+
+ $resp = $this->contactsController->getContacts();
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ //var_dump($data);
+ }
public function testAddContactMyMap() {
$c = $this->container;
diff --git a/tests/Unit/Controller/DevicesApiControllerTest.php b/tests/Unit/Controller/DevicesApiControllerTest.php
index 5fe28c899..519011359 100644
--- a/tests/Unit/Controller/DevicesApiControllerTest.php
+++ b/tests/Unit/Controller/DevicesApiControllerTest.php
@@ -11,394 +11,391 @@
namespace OCA\Maps\Controller;
-use OCP\Files\IRootFolder;
-use \OCP\IServerContainer;
-use \OCA\Maps\AppInfo\Application;
-use \OCA\Maps\Service\DevicesService;
-use OCP\AppFramework\Http\TemplateResponse;
-
+use OCA\Maps\AppInfo\Application;
+use OCA\Maps\Service\DevicesService;
+use OCP\IServerContainer;
class DevicesApiControllerTest extends \PHPUnit\Framework\TestCase {
- private $appName;
- private $request;
- private $contacts;
+ private $appName;
+ private $request;
+ private $contacts;
- private $container;
- private $config;
- private $app;
+ private $container;
+ private $config;
+ private $app;
- private $devicesApiController;
- private $devicesApiController2;
- private $utilsController;
+ private $devicesApiController;
+ private $devicesApiController2;
+ private $utilsController;
private $root;
- public static function setUpBeforeClass(): void {
- $app = new Application();
- $c = $app->getContainer();
-
- $user = $c->getServer()->getUserManager()->get('test');
- $user2 = $c->getServer()->getUserManager()->get('test2');
- $user3 = $c->getServer()->getUserManager()->get('test3');
- $group = $c->getServer()->getGroupManager()->get('group1test');
- $group2 = $c->getServer()->getGroupManager()->get('group2test');
-
- // CREATE DUMMY USERS
- if ($user === null) {
- $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
- $u1->setEMailAddress('toto@toto.net');
- }
- if ($user2 === null) {
- $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
- }
- if ($user2 === null) {
- $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
- }
- if ($group === null) {
- $c->getServer()->getGroupManager()->createGroup('group1test');
- $u1 = $c->getServer()->getUserManager()->get('test');
- $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
- }
- if ($group2 === null) {
- $c->getServer()->getGroupManager()->createGroup('group2test');
- $u2 = $c->getServer()->getUserManager()->get('test2');
- $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
- }
- }
-
- protected function setUp(): void {
- $this->appName = 'maps';
- $this->request = $this->getMockBuilder('\OCP\IRequest')
- ->disableOriginalConstructor()
- ->getMock();
- $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->app = new Application();
- $this->container = $this->app->getContainer();
- $c = $this->container;
- $this->config = $c->query(IServerContainer::class)->getConfig();
+ public static function setUpBeforeClass(): void {
+ $app = new Application();
+ $c = $app->getContainer();
+
+ $user = $c->getServer()->getUserManager()->get('test');
+ $user2 = $c->getServer()->getUserManager()->get('test2');
+ $user3 = $c->getServer()->getUserManager()->get('test3');
+ $group = $c->getServer()->getGroupManager()->get('group1test');
+ $group2 = $c->getServer()->getGroupManager()->get('group2test');
+
+ // CREATE DUMMY USERS
+ if ($user === null) {
+ $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
+ $u1->setEMailAddress('toto@toto.net');
+ }
+ if ($user2 === null) {
+ $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
+ }
+ if ($user2 === null) {
+ $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
+ }
+ if ($group === null) {
+ $c->getServer()->getGroupManager()->createGroup('group1test');
+ $u1 = $c->getServer()->getUserManager()->get('test');
+ $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
+ }
+ if ($group2 === null) {
+ $c->getServer()->getGroupManager()->createGroup('group2test');
+ $u2 = $c->getServer()->getUserManager()->get('test2');
+ $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
+ }
+ }
+
+ protected function setUp(): void {
+ $this->appName = 'maps';
+ $this->request = $this->getMockBuilder('\OCP\IRequest')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->app = new Application();
+ $this->container = $this->app->getContainer();
+ $c = $this->container;
+ $this->config = $c->query(IServerContainer::class)->getConfig();
$this->root = $c->query(IServerContainer::class)->getRootFolder();
- $this->devicesApiController = new DevicesApiController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class),
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getShareManager(),
- $c->getServer()->getAppManager(),
- $c->getServer()->getUserManager(),
- $c->getServer()->getGroupManager(),
- $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
- $c->query(IServerContainer::class)->getLogger(),
- $c->query(DevicesService::class),
- 'test'
- );
-
- $this->devicesApiController2 = new DevicesApiController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class),
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getShareManager(),
- $c->getServer()->getAppManager(),
- $c->getServer()->getUserManager(),
- $c->getServer()->getGroupManager(),
- $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
- $c->query(IServerContainer::class)->getLogger(),
- $c->query(DevicesService::class),
- 'test2'
- );
-
- $this->utilsController = new UtilsController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getAppManager(),
+ $this->devicesApiController = new DevicesApiController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class),
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getShareManager(),
+ $c->getServer()->getAppManager(),
+ $c->getServer()->getUserManager(),
+ $c->getServer()->getGroupManager(),
+ $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
+ $c->query(IServerContainer::class)->getLogger(),
+ $c->query(DevicesService::class),
+ 'test'
+ );
+
+ $this->devicesApiController2 = new DevicesApiController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class),
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getShareManager(),
+ $c->getServer()->getAppManager(),
+ $c->getServer()->getUserManager(),
+ $c->getServer()->getGroupManager(),
+ $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
+ $c->query(IServerContainer::class)->getLogger(),
+ $c->query(DevicesService::class),
+ 'test2'
+ );
+
+ $this->utilsController = new UtilsController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getAppManager(),
$this->root,
- 'test'
- );
-
- // delete
- $resp = $this->devicesApiController->getDevices('1.0');
- $data = $resp->getData();
- foreach ($data as $device) {
- $resp = $this->devicesApiController->deleteDevice($device['id']);
- }
- }
-
- public static function tearDownAfterClass(): void {
- }
-
- protected function tearDown(): void {
- // in case there was a failure and something was not deleted
- }
-
- public function testAddPoints() {
- $resp = $this->devicesApiController->getDevices('1.0');
- $data = $resp->getData();
- foreach ($data as $device) {
- $resp = $this->devicesApiController->deleteDevice($device['id']);
- }
-
- // delete device that does not exist
- $resp = $this->devicesApiController->deleteDevice(0);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('No such device', $data);
-
- // correct values
- $resp = $this->devicesApiController->addDevicePoint('1.0', 1.1, 2.2, 12345, 'testDevice', 1000, 99, 50);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $deviceId = $data['deviceId'];
- $pointId = $data['pointId'];
-
- $_SERVER['HTTP_USER_AGENT'] = 'testBrowser';
- $ts = (new \DateTime())->getTimestamp();
- $resp = $this->devicesApiController->addDevicePoint('1.0', 1.2, 2.3, null, null, 1001, 100, 5);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $deviceId2 = $data['deviceId'];
- $pointId2 = $data['pointId'];
- // test user agent is correct
- $resp = $this->devicesApiController->getDevices('1.0');
- $data = $resp->getData();
- $d2Found = false;
- foreach ($data as $device) {
- if ($device['id'] === $deviceId2) {
- $this->assertEquals('testBrowser', $device['user_agent']);
- $d2Found = true;
- }
- }
- $this->assertEquals(true, $d2Found);
-
- // This happens with a request such as /api/1.0/devices?lat=1.1&lng=2.2×tamp=&user_agent=testDevice&altitude=&battery=&accuracy=
- $resp = $this->devicesApiController->addDevicePoint('1.0', 1.1, 2.2, '', 'testDevice', '', '', '');
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $deviceId3 = $data['deviceId'];
- $pointId3 = $data['pointId'];
-
- // test point values
- $resp = $this->devicesApiController->getDevicePoints($deviceId2);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals(true, count($data) === 1);
- $this->assertEquals(true, $data[0]['timestamp'] >= $ts);
-
- // invalid values
- $resp = $this->devicesApiController->addDevicePoint('1.0', 'aaa', 2.2, 12345, 'testDevice', 1000, 99, 50);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('Invalid values', $data);
-
- $resp = $this->devicesApiController->addDevicePoint('1.0', 1.1, 'aaa', 12345, 'testDevice', 1000, 99, 50);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('Invalid values', $data);
- }
-
- public function testEditDevice() {
- $resp = $this->devicesApiController->getDevices('1.0');
- $data = $resp->getData();
- foreach ($data as $device) {
- $resp = $this->devicesApiController->deleteDevice($device['id']);
- }
-
- $resp = $this->devicesApiController->addDevicePoint('1.0', 1.1, 2.2, 12345, 'testDevice', 1000, 99, 50);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $deviceId = $data['deviceId'];
- $pointId = $data['pointId'];
-
- $resp = $this->devicesApiController->editDevice($deviceId, '#001122');
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals('#001122', $data['color']);
-
- $resp = $this->devicesApiController->editDevice(0, '#001122');
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
-
- $resp = $this->devicesApiController->editDevice($deviceId, '');
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- }
-
- //public function testImportExportDevices() {
- // $resp = $this->devicesApiController->getDevices('1.0');
- // $data = $resp->getData();
- // foreach ($data as $device) {
- // $resp = $this->devicesApiController->deleteDevice($device['id']);
- // }
-
- // $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
- // $content1 = file_get_contents('tests/test_files/devicesOk.gpx');
- // $userfolder->newFile('devicesOk.gpx')->putContent($content1);
-
- // $resp = $this->devicesApiController->importDevices('/devicesOk.gpx');
- // $status = $resp->getStatus();
- // $this->assertEquals(200, $status);
- // $data = $resp->getData();
- // $this->assertEquals(2, $data);
-
- // $resp = $this->devicesApiController->importDevices('/doesNotExist.gpx');
- // $status = $resp->getStatus();
- // $this->assertEquals(400, $status);
- // $data = $resp->getData();
- // $this->assertEquals('File does not exist', $data);
-
- // $resp = $this->devicesApiController->importDevices('/nc.jpg');
- // $status = $resp->getStatus();
- // $this->assertEquals(400, $status);
-
- // $resp = $this->devicesApiController->importDevices('/Maps');
- // $status = $resp->getStatus();
- // $this->assertEquals(400, $status);
-
- // // get ids
- // $devices = [];
- // $resp = $this->devicesApiController->getDevices('1.0');
- // $data = $resp->getData();
- // foreach ($data as $device) {
- // $id = $device['id'];
- // $devices[$id] = $device;
- // }
- // // get number of points
- // foreach ($devices as $id=>$device) {
- // $resp = $this->devicesApiController->getDevicePoints($id);
- // $status = $resp->getStatus();
- // $this->assertEquals(200, $status);
- // $data = $resp->getData();
- // $devices[$id]['nbPoints'] = count($data);
- // }
-
- // // export and compare
- // $ids = array_keys($devices);
- // $resp = $this->devicesApiController->exportDevices($ids, null, null, true);
- // $status = $resp->getStatus();
- // $this->assertEquals(200, $status);
- // $exportPath = $resp->getData();
- // $this->assertEquals(true, $userfolder->nodeExists($exportPath));
-
- // // parse xml and compare number of devices and points
- // $xmLData = $userfolder->get($exportPath)->getContent();
- // $xml = simplexml_load_string($xmLData);
- // $trks = $xml->trk;
- // // number of devices
- // $this->assertEquals(count($ids), count($trks));
- // $pointCountExport = [];
- // // count exported points per device
- // foreach ($trks as $trk) {
- // $name = (string)$trk->name[0];
- // $pointCountExport[$name] = count($trk->trkseg[0]->trkpt);
- // }
- // // check that it matches the data in the DB
- // foreach ($devices as $id => $device) {
- // $this->assertEquals($device['nbPoints'], $pointCountExport[$device['user_agent']]);
- // }
-
- // // export error
- // $resp = $this->devicesApiController->exportDevices(null, null, null, true);
- // $status = $resp->getStatus();
- // $this->assertEquals(400, $status);
- // $data = $resp->getData();
- // $this->assertEquals('No device to export', $data);
-
- // $userfolder->get('/Maps')->delete();
- // $userfolder->newFile('Maps')->putContent('dummy content');
- // $resp = $this->devicesApiController->exportDevices($ids, null, null, true);
- // $status = $resp->getStatus();
- // $this->assertEquals(400, $status);
- // $data = $resp->getData();
- // $this->assertEquals('/Maps is not a directory', $data);
- // $userfolder->get('/Maps')->delete();
-
- // // delete all points
- // $resp = $this->devicesApiController->getDevices('1.0');
- // $data = $resp->getData();
- // foreach ($data as $device) {
- // $resp = $this->devicesApiController->deleteDevice($device['id']);
- // }
-
- // // and then try to export
- // $resp = $this->devicesApiController->exportDevices($ids, null, null, true);
- // $status = $resp->getStatus();
- // $this->assertEquals(400, $status);
- // $data = $resp->getData();
- // $this->assertEquals('Nothing to export', $data);
- //}
-
- public function testEditDevices() {
- $this->assertEquals(true, 1==1);
- //// valid edition
- //$resp = $this->favoritesController->addFavorite('a', 3.1, 4.1, 'cat1', null, null);
- //$favId = $resp->getData()['id'];
-
- //$resp = $this->favoritesController->editFavorite($favId, 'aa', 3.2, 4.2, 'cat2', 'comment', 'ext');
- //$status = $resp->getStatus();
- //$this->assertEquals(200, $status);
- //$data = $resp->getData();
- //$this->assertEquals($favId, $data['id']);
-
- //$resp = $this->favoritesController->getFavorites();
- //$favs = $resp->getData();
- //$seen = false;
- //foreach ($favs as $fav) {
- // if ($fav['id'] === $favId) {
- // $seen = true;
- // $this->assertEquals('aa', $fav['name']);
- // $this->assertEquals(3.2, $fav['lat']);
- // $this->assertEquals(4.2, $fav['lng']);
- // $this->assertEquals('cat2', $fav['category']);
- // $this->assertEquals('comment', $fav['comment']);
- // $this->assertEquals('ext', $fav['extensions']);
- // }
- //}
- //$this->assertEquals(true, $seen);
-
- //// invalid edition
- //$resp = $this->favoritesController->editFavorite($favId, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
- //$status = $resp->getStatus();
- //$this->assertEquals(400, $status);
- //$data = $resp->getData();
- //$this->assertEquals('invalid values', $data);
-
- //$resp = $this->favoritesController->editFavorite(-1, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
- //$this->assertEquals(400, $status);
- //$data = $resp->getData();
- //$this->assertEquals('No such favorite', $data);
-
- //// rename category
- //$resp = $this->favoritesController->addFavorite('b', 3.1, 4.2, 'cat1', null, null);
- //$resp = $this->favoritesController->addFavorite('one', 3.1, 4.2, 'cat2', null, null);
-
- //$resp = $this->favoritesController->renameCategories(['cat1'], 'cat1RENAMED');
- //$status = $resp->getStatus();
- //$this->assertEquals(200, $status);
- //$data = $resp->getData();
- //$this->assertEquals('RENAMED', $data);
- //// check if renaming worked
- //$resp = $this->favoritesController->getFavorites();
- //$favs = $resp->getData();
- //$seen = false;
- //foreach ($favs as $fav) {
- // if ($fav['name'] === 'b') {
- // $seen = true;
- // $this->assertEquals('cat1RENAMED', $fav['category']);
- // }
- //}
- //$this->assertEquals(true, $seen);
- }
+ 'test'
+ );
+
+ // delete
+ $resp = $this->devicesApiController->getDevices('1.0');
+ $data = $resp->getData();
+ foreach ($data as $device) {
+ $resp = $this->devicesApiController->deleteDevice($device['id']);
+ }
+ }
+
+ public static function tearDownAfterClass(): void {
+ }
+
+ protected function tearDown(): void {
+ // in case there was a failure and something was not deleted
+ }
+
+ public function testAddPoints() {
+ $resp = $this->devicesApiController->getDevices('1.0');
+ $data = $resp->getData();
+ foreach ($data as $device) {
+ $resp = $this->devicesApiController->deleteDevice($device['id']);
+ }
+
+ // delete device that does not exist
+ $resp = $this->devicesApiController->deleteDevice(0);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('No such device', $data);
+
+ // correct values
+ $resp = $this->devicesApiController->addDevicePoint('1.0', 1.1, 2.2, 12345, 'testDevice', 1000, 99, 50);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $deviceId = $data['deviceId'];
+ $pointId = $data['pointId'];
+
+ $_SERVER['HTTP_USER_AGENT'] = 'testBrowser';
+ $ts = (new \DateTime())->getTimestamp();
+ $resp = $this->devicesApiController->addDevicePoint('1.0', 1.2, 2.3, null, null, 1001, 100, 5);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $deviceId2 = $data['deviceId'];
+ $pointId2 = $data['pointId'];
+ // test user agent is correct
+ $resp = $this->devicesApiController->getDevices('1.0');
+ $data = $resp->getData();
+ $d2Found = false;
+ foreach ($data as $device) {
+ if ($device['id'] === $deviceId2) {
+ $this->assertEquals('testBrowser', $device['user_agent']);
+ $d2Found = true;
+ }
+ }
+ $this->assertEquals(true, $d2Found);
+
+ // This happens with a request such as /api/1.0/devices?lat=1.1&lng=2.2×tamp=&user_agent=testDevice&altitude=&battery=&accuracy=
+ $resp = $this->devicesApiController->addDevicePoint('1.0', 1.1, 2.2, '', 'testDevice', '', '', '');
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $deviceId3 = $data['deviceId'];
+ $pointId3 = $data['pointId'];
+
+ // test point values
+ $resp = $this->devicesApiController->getDevicePoints($deviceId2);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals(true, count($data) === 1);
+ $this->assertEquals(true, $data[0]['timestamp'] >= $ts);
+
+ // invalid values
+ $resp = $this->devicesApiController->addDevicePoint('1.0', 'aaa', 2.2, 12345, 'testDevice', 1000, 99, 50);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('Invalid values', $data);
+
+ $resp = $this->devicesApiController->addDevicePoint('1.0', 1.1, 'aaa', 12345, 'testDevice', 1000, 99, 50);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('Invalid values', $data);
+ }
+
+ public function testEditDevice() {
+ $resp = $this->devicesApiController->getDevices('1.0');
+ $data = $resp->getData();
+ foreach ($data as $device) {
+ $resp = $this->devicesApiController->deleteDevice($device['id']);
+ }
+
+ $resp = $this->devicesApiController->addDevicePoint('1.0', 1.1, 2.2, 12345, 'testDevice', 1000, 99, 50);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $deviceId = $data['deviceId'];
+ $pointId = $data['pointId'];
+
+ $resp = $this->devicesApiController->editDevice($deviceId, '#001122');
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals('#001122', $data['color']);
+
+ $resp = $this->devicesApiController->editDevice(0, '#001122');
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+
+ $resp = $this->devicesApiController->editDevice($deviceId, '');
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ }
+
+ //public function testImportExportDevices() {
+ // $resp = $this->devicesApiController->getDevices('1.0');
+ // $data = $resp->getData();
+ // foreach ($data as $device) {
+ // $resp = $this->devicesApiController->deleteDevice($device['id']);
+ // }
+
+ // $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
+ // $content1 = file_get_contents('tests/test_files/devicesOk.gpx');
+ // $userfolder->newFile('devicesOk.gpx')->putContent($content1);
+
+ // $resp = $this->devicesApiController->importDevices('/devicesOk.gpx');
+ // $status = $resp->getStatus();
+ // $this->assertEquals(200, $status);
+ // $data = $resp->getData();
+ // $this->assertEquals(2, $data);
+
+ // $resp = $this->devicesApiController->importDevices('/doesNotExist.gpx');
+ // $status = $resp->getStatus();
+ // $this->assertEquals(400, $status);
+ // $data = $resp->getData();
+ // $this->assertEquals('File does not exist', $data);
+
+ // $resp = $this->devicesApiController->importDevices('/nc.jpg');
+ // $status = $resp->getStatus();
+ // $this->assertEquals(400, $status);
+
+ // $resp = $this->devicesApiController->importDevices('/Maps');
+ // $status = $resp->getStatus();
+ // $this->assertEquals(400, $status);
+
+ // // get ids
+ // $devices = [];
+ // $resp = $this->devicesApiController->getDevices('1.0');
+ // $data = $resp->getData();
+ // foreach ($data as $device) {
+ // $id = $device['id'];
+ // $devices[$id] = $device;
+ // }
+ // // get number of points
+ // foreach ($devices as $id=>$device) {
+ // $resp = $this->devicesApiController->getDevicePoints($id);
+ // $status = $resp->getStatus();
+ // $this->assertEquals(200, $status);
+ // $data = $resp->getData();
+ // $devices[$id]['nbPoints'] = count($data);
+ // }
+
+ // // export and compare
+ // $ids = array_keys($devices);
+ // $resp = $this->devicesApiController->exportDevices($ids, null, null, true);
+ // $status = $resp->getStatus();
+ // $this->assertEquals(200, $status);
+ // $exportPath = $resp->getData();
+ // $this->assertEquals(true, $userfolder->nodeExists($exportPath));
+
+ // // parse xml and compare number of devices and points
+ // $xmLData = $userfolder->get($exportPath)->getContent();
+ // $xml = simplexml_load_string($xmLData);
+ // $trks = $xml->trk;
+ // // number of devices
+ // $this->assertEquals(count($ids), count($trks));
+ // $pointCountExport = [];
+ // // count exported points per device
+ // foreach ($trks as $trk) {
+ // $name = (string)$trk->name[0];
+ // $pointCountExport[$name] = count($trk->trkseg[0]->trkpt);
+ // }
+ // // check that it matches the data in the DB
+ // foreach ($devices as $id => $device) {
+ // $this->assertEquals($device['nbPoints'], $pointCountExport[$device['user_agent']]);
+ // }
+
+ // // export error
+ // $resp = $this->devicesApiController->exportDevices(null, null, null, true);
+ // $status = $resp->getStatus();
+ // $this->assertEquals(400, $status);
+ // $data = $resp->getData();
+ // $this->assertEquals('No device to export', $data);
+
+ // $userfolder->get('/Maps')->delete();
+ // $userfolder->newFile('Maps')->putContent('dummy content');
+ // $resp = $this->devicesApiController->exportDevices($ids, null, null, true);
+ // $status = $resp->getStatus();
+ // $this->assertEquals(400, $status);
+ // $data = $resp->getData();
+ // $this->assertEquals('/Maps is not a directory', $data);
+ // $userfolder->get('/Maps')->delete();
+
+ // // delete all points
+ // $resp = $this->devicesApiController->getDevices('1.0');
+ // $data = $resp->getData();
+ // foreach ($data as $device) {
+ // $resp = $this->devicesApiController->deleteDevice($device['id']);
+ // }
+
+ // // and then try to export
+ // $resp = $this->devicesApiController->exportDevices($ids, null, null, true);
+ // $status = $resp->getStatus();
+ // $this->assertEquals(400, $status);
+ // $data = $resp->getData();
+ // $this->assertEquals('Nothing to export', $data);
+ //}
+
+ public function testEditDevices() {
+ $this->assertEquals(true, 1 == 1);
+ //// valid edition
+ //$resp = $this->favoritesController->addFavorite('a', 3.1, 4.1, 'cat1', null, null);
+ //$favId = $resp->getData()['id'];
+
+ //$resp = $this->favoritesController->editFavorite($favId, 'aa', 3.2, 4.2, 'cat2', 'comment', 'ext');
+ //$status = $resp->getStatus();
+ //$this->assertEquals(200, $status);
+ //$data = $resp->getData();
+ //$this->assertEquals($favId, $data['id']);
+
+ //$resp = $this->favoritesController->getFavorites();
+ //$favs = $resp->getData();
+ //$seen = false;
+ //foreach ($favs as $fav) {
+ // if ($fav['id'] === $favId) {
+ // $seen = true;
+ // $this->assertEquals('aa', $fav['name']);
+ // $this->assertEquals(3.2, $fav['lat']);
+ // $this->assertEquals(4.2, $fav['lng']);
+ // $this->assertEquals('cat2', $fav['category']);
+ // $this->assertEquals('comment', $fav['comment']);
+ // $this->assertEquals('ext', $fav['extensions']);
+ // }
+ //}
+ //$this->assertEquals(true, $seen);
+
+ //// invalid edition
+ //$resp = $this->favoritesController->editFavorite($favId, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
+ //$status = $resp->getStatus();
+ //$this->assertEquals(400, $status);
+ //$data = $resp->getData();
+ //$this->assertEquals('invalid values', $data);
+
+ //$resp = $this->favoritesController->editFavorite(-1, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
+ //$this->assertEquals(400, $status);
+ //$data = $resp->getData();
+ //$this->assertEquals('No such favorite', $data);
+
+ //// rename category
+ //$resp = $this->favoritesController->addFavorite('b', 3.1, 4.2, 'cat1', null, null);
+ //$resp = $this->favoritesController->addFavorite('one', 3.1, 4.2, 'cat2', null, null);
+
+ //$resp = $this->favoritesController->renameCategories(['cat1'], 'cat1RENAMED');
+ //$status = $resp->getStatus();
+ //$this->assertEquals(200, $status);
+ //$data = $resp->getData();
+ //$this->assertEquals('RENAMED', $data);
+ //// check if renaming worked
+ //$resp = $this->favoritesController->getFavorites();
+ //$favs = $resp->getData();
+ //$seen = false;
+ //foreach ($favs as $fav) {
+ // if ($fav['name'] === 'b') {
+ // $seen = true;
+ // $this->assertEquals('cat1RENAMED', $fav['category']);
+ // }
+ //}
+ //$this->assertEquals(true, $seen);
+ }
}
diff --git a/tests/Unit/Controller/DevicesControllerTest.php b/tests/Unit/Controller/DevicesControllerTest.php
index 63b154f71..15e120f85 100644
--- a/tests/Unit/Controller/DevicesControllerTest.php
+++ b/tests/Unit/Controller/DevicesControllerTest.php
@@ -11,423 +11,421 @@
namespace OCA\Maps\Controller;
+use OCA\Maps\AppInfo\Application;
use OCA\Maps\DB\DeviceShareMapper;
+use OCA\Maps\Service\DevicesService;
use OCP\Files\IRootFolder;
-use \OCP\IServerContainer;
-use \OCA\Maps\AppInfo\Application;
-use \OCA\Maps\Service\DevicesService;
-use OCP\AppFramework\Http\TemplateResponse;
-
+use OCP\IServerContainer;
class DevicesControllerTest extends \PHPUnit\Framework\TestCase {
- private $appName;
- private $request;
- private $contacts;
+ private $appName;
+ private $request;
+ private $contacts;
- private $container;
- private $config;
- private $app;
+ private $container;
+ private $config;
+ private $app;
- private $devicesController;
- private $devicesController2;
- private $utilsController;
+ private $devicesController;
+ private $devicesController2;
+ private $utilsController;
private $root;
- public static function setUpBeforeClass(): void {
- $app = new Application();
- $c = $app->getContainer();
-
- $user = $c->getServer()->getUserManager()->get('test');
- $user2 = $c->getServer()->getUserManager()->get('test2');
- $user3 = $c->getServer()->getUserManager()->get('test3');
- $group = $c->getServer()->getGroupManager()->get('group1test');
- $group2 = $c->getServer()->getGroupManager()->get('group2test');
-
- // CREATE DUMMY USERS
- if ($user === null) {
- $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
- $u1->setEMailAddress('toto@toto.net');
- }
- if ($user2 === null) {
- $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
- }
- if ($user2 === null) {
- $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
- }
- if ($group === null) {
- $c->getServer()->getGroupManager()->createGroup('group1test');
- $u1 = $c->getServer()->getUserManager()->get('test');
- $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
- }
- if ($group2 === null) {
- $c->getServer()->getGroupManager()->createGroup('group2test');
- $u2 = $c->getServer()->getUserManager()->get('test2');
- $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
- }
- }
-
- protected function setUp(): void {
- $this->appName = 'maps';
- $this->request = $this->getMockBuilder('\OCP\IRequest')
- ->disableOriginalConstructor()
- ->getMock();
- $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->app = new Application();
- $this->container = $this->app->getContainer();
- $c = $this->container;
- $this->config = $c->query(IServerContainer::class)->getConfig();
+ public static function setUpBeforeClass(): void {
+ $app = new Application();
+ $c = $app->getContainer();
+
+ $user = $c->getServer()->getUserManager()->get('test');
+ $user2 = $c->getServer()->getUserManager()->get('test2');
+ $user3 = $c->getServer()->getUserManager()->get('test3');
+ $group = $c->getServer()->getGroupManager()->get('group1test');
+ $group2 = $c->getServer()->getGroupManager()->get('group2test');
+
+ // CREATE DUMMY USERS
+ if ($user === null) {
+ $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
+ $u1->setEMailAddress('toto@toto.net');
+ }
+ if ($user2 === null) {
+ $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
+ }
+ if ($user2 === null) {
+ $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
+ }
+ if ($group === null) {
+ $c->getServer()->getGroupManager()->createGroup('group1test');
+ $u1 = $c->getServer()->getUserManager()->get('test');
+ $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
+ }
+ if ($group2 === null) {
+ $c->getServer()->getGroupManager()->createGroup('group2test');
+ $u2 = $c->getServer()->getUserManager()->get('test2');
+ $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
+ }
+ }
+
+ protected function setUp(): void {
+ $this->appName = 'maps';
+ $this->request = $this->getMockBuilder('\OCP\IRequest')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->app = new Application();
+ $this->container = $this->app->getContainer();
+ $c = $this->container;
+ $this->config = $c->query(IServerContainer::class)->getConfig();
$this->root = $c->query(IServerContainer::class)->getRootFolder();
- $this->devicesController = new DevicesController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class),
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getShareManager(),
- $c->getServer()->getAppManager(),
- $c->getServer()->getUserManager(),
- $c->getServer()->getGroupManager(),
- $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
- $c->query(IServerContainer::class)->getLogger(),
- $c->query(DevicesService::class),
+ $this->devicesController = new DevicesController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class),
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getShareManager(),
+ $c->getServer()->getAppManager(),
+ $c->getServer()->getUserManager(),
+ $c->getServer()->getGroupManager(),
+ $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
+ $c->query(IServerContainer::class)->getLogger(),
+ $c->query(DevicesService::class),
$c->query(DeviceShareMapper::class),
- $c->query(IServerContainer::class)->getDateTimeZone(),
+ $c->query(IServerContainer::class)->getDateTimeZone(),
$c->query(IRootFolder::class),
- 'test'
- );
-
- $this->devicesController2 = new DevicesController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class),
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getShareManager(),
- $c->getServer()->getAppManager(),
- $c->getServer()->getUserManager(),
- $c->getServer()->getGroupManager(),
- $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
- $c->query(IServerContainer::class)->getLogger(),
- $c->query(DevicesService::class),
+ 'test'
+ );
+
+ $this->devicesController2 = new DevicesController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class),
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getShareManager(),
+ $c->getServer()->getAppManager(),
+ $c->getServer()->getUserManager(),
+ $c->getServer()->getGroupManager(),
+ $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
+ $c->query(IServerContainer::class)->getLogger(),
+ $c->query(DevicesService::class),
$c->query(DeviceShareMapper::class),
- $c->query(IServerContainer::class)->getDateTimeZone(),
+ $c->query(IServerContainer::class)->getDateTimeZone(),
$c->query(IRootFolder::class),
- 'test2'
- );
-
- $this->utilsController = new UtilsController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getAppManager(),
+ 'test2'
+ );
+
+ $this->utilsController = new UtilsController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getAppManager(),
$this->root,
- 'test'
- );
-
- // delete
- $resp = $this->devicesController->getDevices();
- $data = $resp->getData();
- foreach ($data as $device) {
- $resp = $this->devicesController->deleteDevice($device['id']);
- }
- }
-
- public static function tearDownAfterClass(): void {
- //$app = new Application();
- //$c = $app->getContainer();
- //$user = $c->getServer()->getUserManager()->get('test');
- //$user->delete();
- //$user = $c->getServer()->getUserManager()->get('test2');
- //$user->delete();
- //$user = $c->getServer()->getUserManager()->get('test3');
- //$user->delete();
- //$c->getServer()->getGroupManager()->get('group1test')->delete();
- //$c->getServer()->getGroupManager()->get('group2test')->delete();
- }
-
- protected function tearDown(): void {
- // in case there was a failure and something was not deleted
- }
-
- public function testAddPoints() {
- $resp = $this->devicesController->getDevices();
- $data = $resp->getData();
- foreach ($data as $device) {
- $resp = $this->devicesController->deleteDevice($device['id']);
- }
-
- // delete device that does not exist
- $resp = $this->devicesController->deleteDevice(0);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('No such device', $data);
-
- // correct values
- $resp = $this->devicesController->addDevicePoint(1.1, 2.2, 12345, 'testDevice', 1000, 99, 50);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $deviceId = $data['deviceId'];
- $pointId = $data['pointId'];
-
- $_SERVER['HTTP_USER_AGENT'] = 'testBrowser';
- $ts = (new \DateTime())->getTimestamp();
- $resp = $this->devicesController->addDevicePoint(1.2, 2.3, null, null, 1001, 100, 5);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $deviceId2 = $data['deviceId'];
- $pointId2 = $data['pointId'];
- // test user agent is correct
- $resp = $this->devicesController->getDevices();
- $data = $resp->getData();
- $d2Found = false;
- foreach ($data as $device) {
- if ($device['id'] === $deviceId2) {
- $this->assertEquals('testBrowser', $device['user_agent']);
- $d2Found = true;
- }
- }
- $this->assertEquals(true, $d2Found);
-
- // test point values
- $resp = $this->devicesController->getDevicePoints($deviceId2);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals(true, count($data) === 1);
- $this->assertEquals(true, $data[0]['timestamp'] >= $ts);
-
- // test missing values
- $resp = $this->devicesController->addDevicePoint(1.1, 2.2, 12346, 'testDevice', null, null, null);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
-
- $resp = $this->devicesController->addDevicePoint(1.1, 2.2, 12347, 'testDevice', '', '', '');
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
-
- $resp = $this->devicesController->addDevicePoint(1.1, 2.2, 12348, 'testDevice', 'a', 'b', 'c');
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
-
- $resp = $this->devicesController->getDevicePoints($deviceId);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals(true, count($data) === 4);
-
- // invalid values
- $resp = $this->devicesController->addDevicePoint('aaa', 2.2, 12345, 'testDevice', 1000, 99, 50);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('Invalid values', $data);
-
- $resp = $this->devicesController->addDevicePoint(1.1, 'aaa', 12345, 'testDevice', 1000, 99, 50);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('Invalid values', $data);
- }
-
- public function testEditDevice() {
- $resp = $this->devicesController->getDevices();
- $data = $resp->getData();
- foreach ($data as $device) {
- $resp = $this->devicesController->deleteDevice($device['id']);
- }
-
- $resp = $this->devicesController->addDevicePoint(1.1, 2.2, 12345, 'testDevice', 1000, 99, 50);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $deviceId = $data['deviceId'];
- $pointId = $data['pointId'];
-
- $resp = $this->devicesController->editDevice($deviceId, '#001122', 'editedDevice');
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals('#001122', $data['color']);
- $this->assertEquals('editedDevice', $data['user_agent']);
-
- $resp = $this->devicesController->editDevice(0, '#001122', 'editedDevice');
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
-
- $resp = $this->devicesController->editDevice($deviceId, '', '');
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- }
-
- public function testImportExportDevices() {
- $resp = $this->devicesController->getDevices();
- $data = $resp->getData();
- foreach ($data as $device) {
- $resp = $this->devicesController->deleteDevice($device['id']);
- }
-
- $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
- $content1 = file_get_contents('tests/test_files/devicesOk.gpx');
- $userfolder->newFile('devicesOk.gpx')->putContent($content1);
-
- $resp = $this->devicesController->importDevices('/devicesOk.gpx');
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals(2, $data);
-
- $resp = $this->devicesController->importDevices('/doesNotExist.gpx');
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('File does not exist', $data);
-
- $resp = $this->devicesController->importDevices('/nc.jpg');
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
-
- $resp = $this->devicesController->importDevices('/Maps');
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
-
- // get ids
- $devices = [];
- $resp = $this->devicesController->getDevices();
- $data = $resp->getData();
- foreach ($data as $device) {
- $id = $device['id'];
- $devices[$id] = $device;
- }
- // get number of points
- foreach ($devices as $id=>$device) {
- $resp = $this->devicesController->getDevicePoints($id);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $devices[$id]['nbPoints'] = count($data);
- }
-
- // export and compare
- $ids = array_keys($devices);
- $resp = $this->devicesController->exportDevices($ids, null, null, true);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $exportPath = $resp->getData();
- $this->assertEquals(true, $userfolder->nodeExists($exportPath));
-
- // parse xml and compare number of devices and points
- $xmLData = $userfolder->get($exportPath)->getContent();
- $xml = simplexml_load_string($xmLData);
- $trks = $xml->trk;
- // number of devices
- $this->assertEquals(count($ids), count($trks));
- $pointCountExport = [];
- // count exported points per device
- foreach ($trks as $trk) {
- $name = (string)$trk->name[0];
- $pointCountExport[$name] = count($trk->trkseg[0]->trkpt);
- }
- // check that it matches the data in the DB
- foreach ($devices as $id => $device) {
- $this->assertEquals($device['nbPoints'], $pointCountExport[$device['user_agent']]);
- }
-
- // export error
- $resp = $this->devicesController->exportDevices(null, null, null, true);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('No device to export', $data);
-
- $userfolder->get('/Maps')->delete();
- $userfolder->newFile('Maps')->putContent('dummy content');
- $resp = $this->devicesController->exportDevices($ids, null, null, true);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('/Maps is not a directory', $data);
- $userfolder->get('/Maps')->delete();
-
- // delete all points
- $resp = $this->devicesController->getDevices();
- $data = $resp->getData();
- foreach ($data as $device) {
- $resp = $this->devicesController->deleteDevice($device['id']);
- }
-
- // and then try to export
- $resp = $this->devicesController->exportDevices($ids, null, null, true);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('Nothing to export', $data);
- }
-
- public function testEditDevices() {
- $this->assertEquals(true, 1==1);
- //// valid edition
- //$resp = $this->favoritesController->addFavorite('a', 3.1, 4.1, 'cat1', null, null);
- //$favId = $resp->getData()['id'];
-
- //$resp = $this->favoritesController->editFavorite($favId, 'aa', 3.2, 4.2, 'cat2', 'comment', 'ext');
- //$status = $resp->getStatus();
- //$this->assertEquals(200, $status);
- //$data = $resp->getData();
- //$this->assertEquals($favId, $data['id']);
-
- //$resp = $this->favoritesController->getFavorites();
- //$favs = $resp->getData();
- //$seen = false;
- //foreach ($favs as $fav) {
- // if ($fav['id'] === $favId) {
- // $seen = true;
- // $this->assertEquals('aa', $fav['name']);
- // $this->assertEquals(3.2, $fav['lat']);
- // $this->assertEquals(4.2, $fav['lng']);
- // $this->assertEquals('cat2', $fav['category']);
- // $this->assertEquals('comment', $fav['comment']);
- // $this->assertEquals('ext', $fav['extensions']);
- // }
- //}
- //$this->assertEquals(true, $seen);
-
- //// invalid edition
- //$resp = $this->favoritesController->editFavorite($favId, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
- //$status = $resp->getStatus();
- //$this->assertEquals(400, $status);
- //$data = $resp->getData();
- //$this->assertEquals('invalid values', $data);
-
- //$resp = $this->favoritesController->editFavorite(-1, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
- //$this->assertEquals(400, $status);
- //$data = $resp->getData();
- //$this->assertEquals('No such favorite', $data);
-
- //// rename category
- //$resp = $this->favoritesController->addFavorite('b', 3.1, 4.2, 'cat1', null, null);
- //$resp = $this->favoritesController->addFavorite('one', 3.1, 4.2, 'cat2', null, null);
-
- //$resp = $this->favoritesController->renameCategories(['cat1'], 'cat1RENAMED');
- //$status = $resp->getStatus();
- //$this->assertEquals(200, $status);
- //$data = $resp->getData();
- //$this->assertEquals('RENAMED', $data);
- //// check if renaming worked
- //$resp = $this->favoritesController->getFavorites();
- //$favs = $resp->getData();
- //$seen = false;
- //foreach ($favs as $fav) {
- // if ($fav['name'] === 'b') {
- // $seen = true;
- // $this->assertEquals('cat1RENAMED', $fav['category']);
- // }
- //}
- //$this->assertEquals(true, $seen);
- }
+ 'test'
+ );
+
+ // delete
+ $resp = $this->devicesController->getDevices();
+ $data = $resp->getData();
+ foreach ($data as $device) {
+ $resp = $this->devicesController->deleteDevice($device['id']);
+ }
+ }
+
+ public static function tearDownAfterClass(): void {
+ //$app = new Application();
+ //$c = $app->getContainer();
+ //$user = $c->getServer()->getUserManager()->get('test');
+ //$user->delete();
+ //$user = $c->getServer()->getUserManager()->get('test2');
+ //$user->delete();
+ //$user = $c->getServer()->getUserManager()->get('test3');
+ //$user->delete();
+ //$c->getServer()->getGroupManager()->get('group1test')->delete();
+ //$c->getServer()->getGroupManager()->get('group2test')->delete();
+ }
+
+ protected function tearDown(): void {
+ // in case there was a failure and something was not deleted
+ }
+
+ public function testAddPoints() {
+ $resp = $this->devicesController->getDevices();
+ $data = $resp->getData();
+ foreach ($data as $device) {
+ $resp = $this->devicesController->deleteDevice($device['id']);
+ }
+
+ // delete device that does not exist
+ $resp = $this->devicesController->deleteDevice(0);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('No such device', $data);
+
+ // correct values
+ $resp = $this->devicesController->addDevicePoint(1.1, 2.2, 12345, 'testDevice', 1000, 99, 50);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $deviceId = $data['deviceId'];
+ $pointId = $data['pointId'];
+
+ $_SERVER['HTTP_USER_AGENT'] = 'testBrowser';
+ $ts = (new \DateTime())->getTimestamp();
+ $resp = $this->devicesController->addDevicePoint(1.2, 2.3, null, null, 1001, 100, 5);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $deviceId2 = $data['deviceId'];
+ $pointId2 = $data['pointId'];
+ // test user agent is correct
+ $resp = $this->devicesController->getDevices();
+ $data = $resp->getData();
+ $d2Found = false;
+ foreach ($data as $device) {
+ if ($device['id'] === $deviceId2) {
+ $this->assertEquals('testBrowser', $device['user_agent']);
+ $d2Found = true;
+ }
+ }
+ $this->assertEquals(true, $d2Found);
+
+ // test point values
+ $resp = $this->devicesController->getDevicePoints($deviceId2);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals(true, count($data) === 1);
+ $this->assertEquals(true, $data[0]['timestamp'] >= $ts);
+
+ // test missing values
+ $resp = $this->devicesController->addDevicePoint(1.1, 2.2, 12346, 'testDevice', null, null, null);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+
+ $resp = $this->devicesController->addDevicePoint(1.1, 2.2, 12347, 'testDevice', '', '', '');
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+
+ $resp = $this->devicesController->addDevicePoint(1.1, 2.2, 12348, 'testDevice', 'a', 'b', 'c');
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+
+ $resp = $this->devicesController->getDevicePoints($deviceId);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals(true, count($data) === 4);
+
+ // invalid values
+ $resp = $this->devicesController->addDevicePoint('aaa', 2.2, 12345, 'testDevice', 1000, 99, 50);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('Invalid values', $data);
+
+ $resp = $this->devicesController->addDevicePoint(1.1, 'aaa', 12345, 'testDevice', 1000, 99, 50);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('Invalid values', $data);
+ }
+
+ public function testEditDevice() {
+ $resp = $this->devicesController->getDevices();
+ $data = $resp->getData();
+ foreach ($data as $device) {
+ $resp = $this->devicesController->deleteDevice($device['id']);
+ }
+
+ $resp = $this->devicesController->addDevicePoint(1.1, 2.2, 12345, 'testDevice', 1000, 99, 50);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $deviceId = $data['deviceId'];
+ $pointId = $data['pointId'];
+
+ $resp = $this->devicesController->editDevice($deviceId, '#001122', 'editedDevice');
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals('#001122', $data['color']);
+ $this->assertEquals('editedDevice', $data['user_agent']);
+
+ $resp = $this->devicesController->editDevice(0, '#001122', 'editedDevice');
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+
+ $resp = $this->devicesController->editDevice($deviceId, '', '');
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ }
+
+ public function testImportExportDevices() {
+ $resp = $this->devicesController->getDevices();
+ $data = $resp->getData();
+ foreach ($data as $device) {
+ $resp = $this->devicesController->deleteDevice($device['id']);
+ }
+
+ $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
+ $content1 = file_get_contents('tests/test_files/devicesOk.gpx');
+ $userfolder->newFile('devicesOk.gpx')->putContent($content1);
+
+ $resp = $this->devicesController->importDevices('/devicesOk.gpx');
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals(2, $data);
+
+ $resp = $this->devicesController->importDevices('/doesNotExist.gpx');
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('File does not exist', $data);
+
+ $resp = $this->devicesController->importDevices('/nc.jpg');
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+
+ $resp = $this->devicesController->importDevices('/Maps');
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+
+ // get ids
+ $devices = [];
+ $resp = $this->devicesController->getDevices();
+ $data = $resp->getData();
+ foreach ($data as $device) {
+ $id = $device['id'];
+ $devices[$id] = $device;
+ }
+ // get number of points
+ foreach ($devices as $id => $device) {
+ $resp = $this->devicesController->getDevicePoints($id);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $devices[$id]['nbPoints'] = count($data);
+ }
+
+ // export and compare
+ $ids = array_keys($devices);
+ $resp = $this->devicesController->exportDevices($ids, null, null, true);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $exportPath = $resp->getData();
+ $this->assertEquals(true, $userfolder->nodeExists($exportPath));
+
+ // parse xml and compare number of devices and points
+ $xmLData = $userfolder->get($exportPath)->getContent();
+ $xml = simplexml_load_string($xmLData);
+ $trks = $xml->trk;
+ // number of devices
+ $this->assertEquals(count($ids), count($trks));
+ $pointCountExport = [];
+ // count exported points per device
+ foreach ($trks as $trk) {
+ $name = (string)$trk->name[0];
+ $pointCountExport[$name] = count($trk->trkseg[0]->trkpt);
+ }
+ // check that it matches the data in the DB
+ foreach ($devices as $id => $device) {
+ $this->assertEquals($device['nbPoints'], $pointCountExport[$device['user_agent']]);
+ }
+
+ // export error
+ $resp = $this->devicesController->exportDevices(null, null, null, true);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('No device to export', $data);
+
+ $userfolder->get('/Maps')->delete();
+ $userfolder->newFile('Maps')->putContent('dummy content');
+ $resp = $this->devicesController->exportDevices($ids, null, null, true);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('/Maps is not a directory', $data);
+ $userfolder->get('/Maps')->delete();
+
+ // delete all points
+ $resp = $this->devicesController->getDevices();
+ $data = $resp->getData();
+ foreach ($data as $device) {
+ $resp = $this->devicesController->deleteDevice($device['id']);
+ }
+
+ // and then try to export
+ $resp = $this->devicesController->exportDevices($ids, null, null, true);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('Nothing to export', $data);
+ }
+
+ public function testEditDevices() {
+ $this->assertEquals(true, 1 == 1);
+ //// valid edition
+ //$resp = $this->favoritesController->addFavorite('a', 3.1, 4.1, 'cat1', null, null);
+ //$favId = $resp->getData()['id'];
+
+ //$resp = $this->favoritesController->editFavorite($favId, 'aa', 3.2, 4.2, 'cat2', 'comment', 'ext');
+ //$status = $resp->getStatus();
+ //$this->assertEquals(200, $status);
+ //$data = $resp->getData();
+ //$this->assertEquals($favId, $data['id']);
+
+ //$resp = $this->favoritesController->getFavorites();
+ //$favs = $resp->getData();
+ //$seen = false;
+ //foreach ($favs as $fav) {
+ // if ($fav['id'] === $favId) {
+ // $seen = true;
+ // $this->assertEquals('aa', $fav['name']);
+ // $this->assertEquals(3.2, $fav['lat']);
+ // $this->assertEquals(4.2, $fav['lng']);
+ // $this->assertEquals('cat2', $fav['category']);
+ // $this->assertEquals('comment', $fav['comment']);
+ // $this->assertEquals('ext', $fav['extensions']);
+ // }
+ //}
+ //$this->assertEquals(true, $seen);
+
+ //// invalid edition
+ //$resp = $this->favoritesController->editFavorite($favId, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
+ //$status = $resp->getStatus();
+ //$this->assertEquals(400, $status);
+ //$data = $resp->getData();
+ //$this->assertEquals('invalid values', $data);
+
+ //$resp = $this->favoritesController->editFavorite(-1, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
+ //$this->assertEquals(400, $status);
+ //$data = $resp->getData();
+ //$this->assertEquals('No such favorite', $data);
+
+ //// rename category
+ //$resp = $this->favoritesController->addFavorite('b', 3.1, 4.2, 'cat1', null, null);
+ //$resp = $this->favoritesController->addFavorite('one', 3.1, 4.2, 'cat2', null, null);
+
+ //$resp = $this->favoritesController->renameCategories(['cat1'], 'cat1RENAMED');
+ //$status = $resp->getStatus();
+ //$this->assertEquals(200, $status);
+ //$data = $resp->getData();
+ //$this->assertEquals('RENAMED', $data);
+ //// check if renaming worked
+ //$resp = $this->favoritesController->getFavorites();
+ //$favs = $resp->getData();
+ //$seen = false;
+ //foreach ($favs as $fav) {
+ // if ($fav['name'] === 'b') {
+ // $seen = true;
+ // $this->assertEquals('cat1RENAMED', $fav['category']);
+ // }
+ //}
+ //$this->assertEquals(true, $seen);
+ }
}
diff --git a/tests/Unit/Controller/FavoritesApiControllerTest.php b/tests/Unit/Controller/FavoritesApiControllerTest.php
index e5eed8b9f..1018874a7 100644
--- a/tests/Unit/Controller/FavoritesApiControllerTest.php
+++ b/tests/Unit/Controller/FavoritesApiControllerTest.php
@@ -11,242 +11,233 @@
namespace OCA\Maps\Controller;
-use \OCP\IServerContainer;
-use \OCA\Maps\AppInfo\Application;
-use \OCA\Maps\Service\FavoritesService;
-use OCP\AppFramework\Http\TemplateResponse;
-
-
-class FavoritesApiControllerTest extends \PHPUnit\Framework\TestCase
-{
- private $appName;
- private $request;
- private $contacts;
-
- private $container;
- private $config;
- private $app;
- private $root;
-
- private $favoritesApiController;
- private $favoritesApiController2;
- private $utilsController;
-
- public static function setUpBeforeClass(): void
- {
- $app = new Application();
- $c = $app->getContainer();
-
- $user = $c->getServer()->getUserManager()->get('test');
- $user2 = $c->getServer()->getUserManager()->get('test2');
- $user3 = $c->getServer()->getUserManager()->get('test3');
- $group = $c->getServer()->getGroupManager()->get('group1test');
- $group2 = $c->getServer()->getGroupManager()->get('group2test');
-
- // CREATE DUMMY USERS
- if ($user === null) {
- $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
- $u1->setEMailAddress('toto@toto.net');
- }
- if ($user2 === null) {
- $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
- }
- if ($user2 === null) {
- $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
- }
- if ($group === null) {
- $c->getServer()->getGroupManager()->createGroup('group1test');
- $u1 = $c->getServer()->getUserManager()->get('test');
- $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
- }
- if ($group2 === null) {
- $c->getServer()->getGroupManager()->createGroup('group2test');
- $u2 = $c->getServer()->getUserManager()->get('test2');
- $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
- }
- }
-
- protected function setUp(): void
- {
- $this->appName = 'maps';
- $this->request = $this->getMockBuilder('\OCP\IRequest')
- ->disableOriginalConstructor()
- ->getMock();
- $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->app = new Application();
- $this->container = $this->app->getContainer();
- $c = $this->container;
- $this->config = $c->query(IServerContainer::class)->getConfig();
- $this->root = $c->query(IServerContainer::class)->getRootFolder();
-
- $this->favoritesApiController = new FavoritesApiController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class),
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getShareManager(),
- $c->getServer()->getAppManager(),
- $c->getServer()->getUserManager(),
- $c->getServer()->getGroupManager(),
- $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
- $c->query(IServerContainer::class)->getLogger(),
- $c->query(FavoritesService::class),
- 'test'
- );
-
- $this->favoritesApiController2 = new FavoritesApiController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class),
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getShareManager(),
- $c->getServer()->getAppManager(),
- $c->getServer()->getUserManager(),
- $c->getServer()->getGroupManager(),
- $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
- $c->query(IServerContainer::class)->getLogger(),
- $c->query(FavoritesService::class),
- 'test2'
- );
-
- $this->utilsController = new UtilsController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getAppManager(),
- $this->root,
- 'test'
- );
- }
-
- public static function tearDownAfterClass(): void
- {
- //$app = new Application();
- //$c = $app->getContainer();
- //$user = $c->getServer()->getUserManager()->get('test');
- //$user->delete();
- //$user = $c->getServer()->getUserManager()->get('test2');
- //$user->delete();
- //$user = $c->getServer()->getUserManager()->get('test3');
- //$user->delete();
- //$c->getServer()->getGroupManager()->get('group1test')->delete();
- //$c->getServer()->getGroupManager()->get('group2test')->delete();
- }
-
- protected function tearDown(): void
- {
- // in case there was a failure and something was not deleted
- $resp = $this->favoritesApiController->getFavorites('1.0');
- $data = $resp->getData();
- foreach ($data as $fav) {
- $resp = $this->favoritesApiController->deleteFavorite($fav['id']);
- }
- }
-
- public function testAddFavorites()
- {
- // correct values
- $resp = $this->favoritesApiController->addFavorite('1.0', 'one', 3.1, 4.2, '', null, null);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals('one', $data['name']);
- $id1 = $data['id'];
-
- $resp = $this->favoritesApiController->addFavorite('1.0', '', 3.1, 4.2, '', null, null);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals('', $data['name']);
- $id2 = $data['id'];
-
- // Invalid values
- $resp = $this->favoritesApiController->addFavorite('1.0', 'one', 'lat', 4.2, '', null, null);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
-
- $resp = $this->favoritesApiController->addFavorite('1.0', 'one', 3.1, 'lon', '', null, null);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
-
- // get favorites
- $resp = $this->favoritesApiController->getFavorites('1.0');
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals(2, count($data));
-
- //// get favorites using etag
- //$etag = $resp->getEtag();
- //var_dump($etag);
- //$this->request->setHeader('If-None-Match', '"'.$etag.'"');
- //$resp = $this->favoritesApiController->getFavorites('1.0');
- //$status = $resp->getStatus();
- //$this->assertEquals(200, $status);
- //$data = $resp->getData();
- //$this->assertEquals(2, count($data));
-
- // delete created favorites
- $resp = $this->favoritesApiController->deleteFavorite($id1);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals('DELETED', $data);
-
- $resp = $this->favoritesApiController->deleteFavorite($id2);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals('DELETED', $data);
-
- // delete something that does not exist
- $resp = $this->favoritesApiController->deleteFavorite($id2);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- }
-
- public function testEditFavorites()
- {
- // valid edition
- $resp = $this->favoritesApiController->addFavorite('1.0', 'a', 3.1, 4.1, 'cat1', null, null);
- $favId = $resp->getData()['id'];
-
- $resp = $this->favoritesApiController->editFavorite($favId, 'aa', 3.2, 4.2, 'cat2', 'comment', 'ext');
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals($favId, $data['id']);
-
- $resp = $this->favoritesApiController->getFavorites('1.0');
- $favs = $resp->getData();
- $seen = false;
- foreach ($favs as $fav) {
- if ($fav['id'] === $favId) {
- $seen = true;
- $this->assertEquals('aa', $fav['name']);
- $this->assertEquals(3.2, $fav['lat']);
- $this->assertEquals(4.2, $fav['lng']);
- $this->assertEquals('cat2', $fav['category']);
- $this->assertEquals('comment', $fav['comment']);
- $this->assertEquals('ext', $fav['extensions']);
- }
- }
- $this->assertEquals(true, $seen);
-
- // invalid edition
- $resp = $this->favoritesApiController->editFavorite($favId, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('Invalid values', $data);
-
- $resp = $this->favoritesApiController->editFavorite(-1, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('No such favorite', $data);
- }
+use OCA\Maps\AppInfo\Application;
+use OCA\Maps\Service\FavoritesService;
+use OCP\IServerContainer;
+
+class FavoritesApiControllerTest extends \PHPUnit\Framework\TestCase {
+ private $appName;
+ private $request;
+ private $contacts;
+
+ private $container;
+ private $config;
+ private $app;
+ private $root;
+
+ private $favoritesApiController;
+ private $favoritesApiController2;
+ private $utilsController;
+
+ public static function setUpBeforeClass(): void {
+ $app = new Application();
+ $c = $app->getContainer();
+
+ $user = $c->getServer()->getUserManager()->get('test');
+ $user2 = $c->getServer()->getUserManager()->get('test2');
+ $user3 = $c->getServer()->getUserManager()->get('test3');
+ $group = $c->getServer()->getGroupManager()->get('group1test');
+ $group2 = $c->getServer()->getGroupManager()->get('group2test');
+
+ // CREATE DUMMY USERS
+ if ($user === null) {
+ $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
+ $u1->setEMailAddress('toto@toto.net');
+ }
+ if ($user2 === null) {
+ $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
+ }
+ if ($user2 === null) {
+ $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
+ }
+ if ($group === null) {
+ $c->getServer()->getGroupManager()->createGroup('group1test');
+ $u1 = $c->getServer()->getUserManager()->get('test');
+ $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
+ }
+ if ($group2 === null) {
+ $c->getServer()->getGroupManager()->createGroup('group2test');
+ $u2 = $c->getServer()->getUserManager()->get('test2');
+ $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
+ }
+ }
+
+ protected function setUp(): void {
+ $this->appName = 'maps';
+ $this->request = $this->getMockBuilder('\OCP\IRequest')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->app = new Application();
+ $this->container = $this->app->getContainer();
+ $c = $this->container;
+ $this->config = $c->query(IServerContainer::class)->getConfig();
+ $this->root = $c->query(IServerContainer::class)->getRootFolder();
+
+ $this->favoritesApiController = new FavoritesApiController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class),
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getShareManager(),
+ $c->getServer()->getAppManager(),
+ $c->getServer()->getUserManager(),
+ $c->getServer()->getGroupManager(),
+ $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
+ $c->query(IServerContainer::class)->getLogger(),
+ $c->query(FavoritesService::class),
+ 'test'
+ );
+
+ $this->favoritesApiController2 = new FavoritesApiController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class),
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getShareManager(),
+ $c->getServer()->getAppManager(),
+ $c->getServer()->getUserManager(),
+ $c->getServer()->getGroupManager(),
+ $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
+ $c->query(IServerContainer::class)->getLogger(),
+ $c->query(FavoritesService::class),
+ 'test2'
+ );
+
+ $this->utilsController = new UtilsController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getAppManager(),
+ $this->root,
+ 'test'
+ );
+ }
+
+ public static function tearDownAfterClass(): void {
+ //$app = new Application();
+ //$c = $app->getContainer();
+ //$user = $c->getServer()->getUserManager()->get('test');
+ //$user->delete();
+ //$user = $c->getServer()->getUserManager()->get('test2');
+ //$user->delete();
+ //$user = $c->getServer()->getUserManager()->get('test3');
+ //$user->delete();
+ //$c->getServer()->getGroupManager()->get('group1test')->delete();
+ //$c->getServer()->getGroupManager()->get('group2test')->delete();
+ }
+
+ protected function tearDown(): void {
+ // in case there was a failure and something was not deleted
+ $resp = $this->favoritesApiController->getFavorites('1.0');
+ $data = $resp->getData();
+ foreach ($data as $fav) {
+ $resp = $this->favoritesApiController->deleteFavorite($fav['id']);
+ }
+ }
+
+ public function testAddFavorites() {
+ // correct values
+ $resp = $this->favoritesApiController->addFavorite('1.0', 'one', 3.1, 4.2, '', null, null);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals('one', $data['name']);
+ $id1 = $data['id'];
+
+ $resp = $this->favoritesApiController->addFavorite('1.0', '', 3.1, 4.2, '', null, null);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals('', $data['name']);
+ $id2 = $data['id'];
+
+ // Invalid values
+ $resp = $this->favoritesApiController->addFavorite('1.0', 'one', 'lat', 4.2, '', null, null);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+
+ $resp = $this->favoritesApiController->addFavorite('1.0', 'one', 3.1, 'lon', '', null, null);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+
+ // get favorites
+ $resp = $this->favoritesApiController->getFavorites('1.0');
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals(2, count($data));
+
+ //// get favorites using etag
+ //$etag = $resp->getEtag();
+ //var_dump($etag);
+ //$this->request->setHeader('If-None-Match', '"'.$etag.'"');
+ //$resp = $this->favoritesApiController->getFavorites('1.0');
+ //$status = $resp->getStatus();
+ //$this->assertEquals(200, $status);
+ //$data = $resp->getData();
+ //$this->assertEquals(2, count($data));
+
+ // delete created favorites
+ $resp = $this->favoritesApiController->deleteFavorite($id1);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals('DELETED', $data);
+
+ $resp = $this->favoritesApiController->deleteFavorite($id2);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals('DELETED', $data);
+
+ // delete something that does not exist
+ $resp = $this->favoritesApiController->deleteFavorite($id2);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ }
+
+ public function testEditFavorites() {
+ // valid edition
+ $resp = $this->favoritesApiController->addFavorite('1.0', 'a', 3.1, 4.1, 'cat1', null, null);
+ $favId = $resp->getData()['id'];
+
+ $resp = $this->favoritesApiController->editFavorite($favId, 'aa', 3.2, 4.2, 'cat2', 'comment', 'ext');
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals($favId, $data['id']);
+
+ $resp = $this->favoritesApiController->getFavorites('1.0');
+ $favs = $resp->getData();
+ $seen = false;
+ foreach ($favs as $fav) {
+ if ($fav['id'] === $favId) {
+ $seen = true;
+ $this->assertEquals('aa', $fav['name']);
+ $this->assertEquals(3.2, $fav['lat']);
+ $this->assertEquals(4.2, $fav['lng']);
+ $this->assertEquals('cat2', $fav['category']);
+ $this->assertEquals('comment', $fav['comment']);
+ $this->assertEquals('ext', $fav['extensions']);
+ }
+ }
+ $this->assertEquals(true, $seen);
+
+ // invalid edition
+ $resp = $this->favoritesApiController->editFavorite($favId, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('Invalid values', $data);
+
+ $resp = $this->favoritesApiController->editFavorite(-1, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('No such favorite', $data);
+ }
}
diff --git a/tests/Unit/Controller/FavoritesControllerTest.php b/tests/Unit/Controller/FavoritesControllerTest.php
index a0648f2af..73f13044c 100644
--- a/tests/Unit/Controller/FavoritesControllerTest.php
+++ b/tests/Unit/Controller/FavoritesControllerTest.php
@@ -13,215 +13,208 @@
namespace OCA\Maps\Controller;
-use \OCA\Maps\AppInfo\Application;
+use OCA\Maps\AppInfo\Application;
use OCA\Maps\DB\FavoriteShareMapper;
-use \OCA\Maps\Service\FavoritesService;
+use OCA\Maps\Service\FavoritesService;
use OCP\AppFramework\Http;
-use \OCP\IServerContainer;
-
-class FavoritesControllerTest extends \PHPUnit\Framework\TestCase
-{
- private $appName;
- private $request;
- private $contacts;
-
- private $container;
- private $config;
- private $app;
-
- private $pageController;
- private $pageController2;
- private $utilsController;
- private $root;
-
- /* @var FavoritesController */
- private $favoritesController;
-
- /* @var FavoritesController */
- private $favoritesController2;
-
- public static function setUpBeforeClass(): void
- {
- $app = new Application();
- $c = $app->getContainer();
-
- $user = $c->getServer()->getUserManager()->get('test');
- $user2 = $c->getServer()->getUserManager()->get('test2');
- $user3 = $c->getServer()->getUserManager()->get('test3');
- $group = $c->getServer()->getGroupManager()->get('group1test');
- $group2 = $c->getServer()->getGroupManager()->get('group2test');
-
- // CREATE DUMMY USERS
- if ($user === null) {
- $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
- $u1->setEMailAddress('toto@toto.net');
- }
- if ($user2 === null) {
- $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
- }
- if ($user2 === null) {
- $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
- }
- if ($group === null) {
- $c->getServer()->getGroupManager()->createGroup('group1test');
- $u1 = $c->getServer()->getUserManager()->get('test');
- $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
- }
- if ($group2 === null) {
- $c->getServer()->getGroupManager()->createGroup('group2test');
- $u2 = $c->getServer()->getUserManager()->get('test2');
- $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
- }
- }
-
- protected function setUp(): void
- {
- $this->appName = 'maps';
- $this->request = $this->getMockBuilder('\OCP\IRequest')
- ->disableOriginalConstructor()
- ->getMock();
- $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->app = new Application();
- $this->container = $this->app->getContainer();
- $c = $this->container;
- $this->config = $c->query(IServerContainer::class)->getConfig();
- $this->root = $c->query(IServerContainer::class)->getRootFolder();
-
- $this->favoritesController = new FavoritesController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class),
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getShareManager(),
- $c->getServer()->getAppManager(),
- $c->getServer()->getUserManager(),
- $c->getServer()->getGroupManager(),
- $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
- $c->query(IServerContainer::class)->getLogger(),
- $c->query(FavoritesService::class),
- $c->query(IServerContainer::class)->getDateTimeZone(),
- $c->query(FavoriteShareMapper::class),
- 'test'
- );
-
- $this->favoritesController2 = new FavoritesController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class),
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getShareManager(),
- $c->getServer()->getAppManager(),
- $c->getServer()->getUserManager(),
- $c->getServer()->getGroupManager(),
- $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
- $c->query(IServerContainer::class)->getLogger(),
- $c->query(FavoritesService::class),
- $c->query(IServerContainer::class)->getDateTimeZone(),
- $c->query(FavoriteShareMapper::class),
- 'test2'
- );
-
- $this->utilsController = new UtilsController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getAppManager(),
- $this->root,
- 'test'
- );
- $this->mapFolder = $this->createMapFolder();
- }
-
- private function createMapFolder() {
- $userFolder = $this->root->getUserFolder('test');
- if ($userFolder->nodeExists('Map')) {
- return $userFolder->get('Map')->delete();
+use OCP\IServerContainer;
+
+class FavoritesControllerTest extends \PHPUnit\Framework\TestCase {
+ private $appName;
+ private $request;
+ private $contacts;
+
+ private $container;
+ private $config;
+ private $app;
+
+ private $pageController;
+ private $pageController2;
+ private $utilsController;
+ private $root;
+
+ /* @var FavoritesController */
+ private $favoritesController;
+
+ /* @var FavoritesController */
+ private $favoritesController2;
+
+ public static function setUpBeforeClass(): void {
+ $app = new Application();
+ $c = $app->getContainer();
+
+ $user = $c->getServer()->getUserManager()->get('test');
+ $user2 = $c->getServer()->getUserManager()->get('test2');
+ $user3 = $c->getServer()->getUserManager()->get('test3');
+ $group = $c->getServer()->getGroupManager()->get('group1test');
+ $group2 = $c->getServer()->getGroupManager()->get('group2test');
+
+ // CREATE DUMMY USERS
+ if ($user === null) {
+ $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
+ $u1->setEMailAddress('toto@toto.net');
+ }
+ if ($user2 === null) {
+ $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
+ }
+ if ($user2 === null) {
+ $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
+ }
+ if ($group === null) {
+ $c->getServer()->getGroupManager()->createGroup('group1test');
+ $u1 = $c->getServer()->getUserManager()->get('test');
+ $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
+ }
+ if ($group2 === null) {
+ $c->getServer()->getGroupManager()->createGroup('group2test');
+ $u2 = $c->getServer()->getUserManager()->get('test2');
+ $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
+ }
}
- return $userFolder->newFolder('Map');
- }
-
- public static function tearDownAfterClass(): void
- {
- //$app = new Application();
- //$c = $app->getContainer();
- //$user = $c->getServer()->getUserManager()->get('test');
- //$user->delete();
- //$user = $c->getServer()->getUserManager()->get('test2');
- //$user->delete();
- //$user = $c->getServer()->getUserManager()->get('test3');
- //$user->delete();
- //$c->getServer()->getGroupManager()->get('group1test')->delete();
- //$c->getServer()->getGroupManager()->get('group2test')->delete();
- }
-
- protected function tearDown(): void
- {
- // in case there was a failure and something was not deleted
- $resp = $this->favoritesController->getFavorites();
- $data = $resp->getData();
- foreach ($data as $fav) {
- $resp = $this->favoritesController->deleteFavorite($fav['id']);
- }
- }
-
- public function testAddFavorites()
- {
- // correct values
- $resp = $this->favoritesController->addFavorite('one', 3.1, 4.2, '', null, null);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals('one', $data['name']);
- $id1 = $data['id'];
-
- $resp = $this->favoritesController->addFavorite('', 3.1, 4.2, '', null, null);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals('', $data['name']);
- $id2 = $data['id'];
-
- // invalid values
-/* ToDo: Probably test for type error
- $resp = $this->favoritesController->addFavorite('one', 'lat', 4.2, '', null, null);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
-
- $resp = $this->favoritesController->addFavorite('one', 3.1, 'lon', '', null, null);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);*/
-
- // get favorites
- $resp = $this->favoritesController->getFavorites();
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals(2, count($data));
-
- // delete created favorites
- $resp = $this->favoritesController->deleteFavorite($id1);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals('DELETED', $data);
-
- $resp = $this->favoritesController->deleteFavorite($id2);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals('DELETED', $data);
-
- // delete something that does not exist
- $resp = $this->favoritesController->deleteFavorite($id2);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- }
-
- public function testAddFavoritesMyMap()
- {
+
+ protected function setUp(): void {
+ $this->appName = 'maps';
+ $this->request = $this->getMockBuilder('\OCP\IRequest')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->app = new Application();
+ $this->container = $this->app->getContainer();
+ $c = $this->container;
+ $this->config = $c->query(IServerContainer::class)->getConfig();
+ $this->root = $c->query(IServerContainer::class)->getRootFolder();
+
+ $this->favoritesController = new FavoritesController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class),
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getShareManager(),
+ $c->getServer()->getAppManager(),
+ $c->getServer()->getUserManager(),
+ $c->getServer()->getGroupManager(),
+ $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
+ $c->query(IServerContainer::class)->getLogger(),
+ $c->query(FavoritesService::class),
+ $c->query(IServerContainer::class)->getDateTimeZone(),
+ $c->query(FavoriteShareMapper::class),
+ 'test'
+ );
+
+ $this->favoritesController2 = new FavoritesController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class),
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getShareManager(),
+ $c->getServer()->getAppManager(),
+ $c->getServer()->getUserManager(),
+ $c->getServer()->getGroupManager(),
+ $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
+ $c->query(IServerContainer::class)->getLogger(),
+ $c->query(FavoritesService::class),
+ $c->query(IServerContainer::class)->getDateTimeZone(),
+ $c->query(FavoriteShareMapper::class),
+ 'test2'
+ );
+
+ $this->utilsController = new UtilsController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getAppManager(),
+ $this->root,
+ 'test'
+ );
+ $this->mapFolder = $this->createMapFolder();
+ }
+
+ private function createMapFolder() {
+ $userFolder = $this->root->getUserFolder('test');
+ if ($userFolder->nodeExists('Map')) {
+ return $userFolder->get('Map')->delete();
+ }
+ return $userFolder->newFolder('Map');
+ }
+
+ public static function tearDownAfterClass(): void {
+ //$app = new Application();
+ //$c = $app->getContainer();
+ //$user = $c->getServer()->getUserManager()->get('test');
+ //$user->delete();
+ //$user = $c->getServer()->getUserManager()->get('test2');
+ //$user->delete();
+ //$user = $c->getServer()->getUserManager()->get('test3');
+ //$user->delete();
+ //$c->getServer()->getGroupManager()->get('group1test')->delete();
+ //$c->getServer()->getGroupManager()->get('group2test')->delete();
+ }
+
+ protected function tearDown(): void {
+ // in case there was a failure and something was not deleted
+ $resp = $this->favoritesController->getFavorites();
+ $data = $resp->getData();
+ foreach ($data as $fav) {
+ $resp = $this->favoritesController->deleteFavorite($fav['id']);
+ }
+ }
+
+ public function testAddFavorites() {
+ // correct values
+ $resp = $this->favoritesController->addFavorite('one', 3.1, 4.2, '', null, null);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals('one', $data['name']);
+ $id1 = $data['id'];
+
+ $resp = $this->favoritesController->addFavorite('', 3.1, 4.2, '', null, null);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals('', $data['name']);
+ $id2 = $data['id'];
+
+ // invalid values
+ /* ToDo: Probably test for type error
+ $resp = $this->favoritesController->addFavorite('one', 'lat', 4.2, '', null, null);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+
+ $resp = $this->favoritesController->addFavorite('one', 3.1, 'lon', '', null, null);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);*/
+
+ // get favorites
+ $resp = $this->favoritesController->getFavorites();
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals(2, count($data));
+
+ // delete created favorites
+ $resp = $this->favoritesController->deleteFavorite($id1);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals('DELETED', $data);
+
+ $resp = $this->favoritesController->deleteFavorite($id2);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals('DELETED', $data);
+
+ // delete something that does not exist
+ $resp = $this->favoritesController->deleteFavorite($id2);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ }
+
+ public function testAddFavoritesMyMap() {
$myMapId = $this->mapFolder->getId();
// correct values
$resp = $this->favoritesController->addFavorite('one', 3.1, 4.2, '', null, null, $myMapId);
@@ -281,169 +274,166 @@ public function testAddFavoritesMyMap()
$this->assertEquals(400, $status);
}
- public function testImportExportFavorites()
- {
- $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
- $content1 = file_get_contents('tests/test_files/favoritesOk.gpx');
- $newFile = $userfolder->newFile('favoritesOk.gpx');
- $newFile->putContent($content1);
-
- $resp = $this->favoritesController->importFavorites('/favoritesOk.gpx');
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals(27, $data['nbImported']);
-
- // get favorites
- $resp = $this->favoritesController->getFavorites();
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals(27, count($data));
- $nbFavorites = count($data);
- $categoryCount = [];
- foreach ($data as $fav) {
- $categoryCount[$fav['category']] = isset($categoryCount[$fav['category']]) ? ($categoryCount[$fav['category']] + 1) : 1;
- }
- $categories = array_keys($categoryCount);
-
- // import errors
- $userfolder->newFile('dummy.pdf')->putContent('dummy content');
-
- $resp = $this->favoritesController->importFavorites('/dummy.gpx');
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('File does not exist', $data);
-
- $resp = $this->favoritesController->importFavorites('/dummy.pdf');
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('Invalid file extension', $data);
-
- // export and compare
- $resp = $this->favoritesController->exportFavorites($categories, null, null, true);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $exportPath = $resp->getData();
- $this->assertEquals(true, $userfolder->nodeExists($exportPath));
-
- // parse xml and compare number of favorite for each category
- $xmLData = $userfolder->get($exportPath)->getContent();
- $xml = simplexml_load_string($xmLData);
- $wpts = $xml->wpt;
- $this->assertEquals($nbFavorites, count($wpts));
- $categoryCountExport = [];
- foreach ($wpts as $wpt) {
- $cat = (string)$wpt->type[0];
- $categoryCountExport[$cat] = isset($categoryCountExport[$cat]) ? ($categoryCountExport[$cat] + 1) : 1;
- }
- foreach ($categoryCount as $cat => $nb) {
- $this->assertEquals($categoryCountExport[$cat], $nb);
- }
-
- // export error
- $resp = $this->favoritesController->exportFavorites(null, null, null, true);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('Nothing to export', $data);
-
- $userfolder->get('/Maps')->delete();
- $userfolder->newFile('Maps')->putContent('dummy content');
- $resp = $this->favoritesController->exportFavorites($categories, null, null, true);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('/Maps is not a directory', $data);
- $userfolder->get('/Maps')->delete();
-
- // delete all favorites
- $resp = $this->favoritesController->getFavorites();
- $data = $resp->getData();
- $favIds = [];
- foreach ($data as $fav) {
- array_push($favIds, $fav['id']);
- }
- $resp = $this->favoritesController->deleteFavorites($favIds);
-
- // and then try to export
- $resp = $this->favoritesController->exportFavorites($categories, null, null, true);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('Nothing to export', $data);
- }
-
-
-
- public function testEditFavorites()
- {
- // valid edition
- $resp = $this->favoritesController->addFavorite('a', 3.1, 4.1, 'cat1', null, null);
- $favId = $resp->getData()['id'];
-
- $resp = $this->favoritesController->editFavorite($favId, 'aa', 3.2, 4.2, 'cat2', 'comment', 'ext');
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals($favId, $data['id']);
-
- $resp = $this->favoritesController->getFavorites();
- $favs = $resp->getData();
- $seen = false;
- foreach ($favs as $fav) {
- if ($fav['id'] === $favId) {
- $seen = true;
- $this->assertEquals('aa', $fav['name']);
- $this->assertEquals(3.2, $fav['lat']);
- $this->assertEquals(4.2, $fav['lng']);
- $this->assertEquals('cat2', $fav['category']);
- $this->assertEquals('comment', $fav['comment']);
- $this->assertEquals('ext', $fav['extensions']);
- }
- }
- $this->assertEquals(true, $seen);
-
- // invalid edition
-//ToDo: Probably test for type errors
-//
-// $resp = $this->favoritesController->editFavorite($favId, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
-// $status = $resp->getStatus();
-// $this->assertEquals(400, $status);
-// $data = $resp->getData();
-// $this->assertEquals('Invalid values', $data);
-//
-// $resp = $this->favoritesController->editFavorite(-1, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
-// $this->assertEquals(400, $status);
-// $data = $resp->getData();
-// $this->assertEquals('No such favorite', $data);
-
- // rename category
- $resp = $this->favoritesController->addFavorite('b', 3.1, 4.2, 'cat1', null, null);
- $resp = $this->favoritesController->addFavorite('one', 3.1, 4.2, 'cat2', null, null);
-
- $resp = $this->favoritesController->renameCategories(['cat1'], 'cat1RENAMED');
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals('RENAMED', $data);
- // check if renaming worked
- $resp = $this->favoritesController->getFavorites();
- $favs = $resp->getData();
- $seen = false;
- foreach ($favs as $fav) {
- if ($fav['name'] === 'b') {
- $seen = true;
- $this->assertEquals('cat1RENAMED', $fav['category']);
- }
- }
- $this->assertEquals(true, $seen);
- }
-
- public function testEditFavoritesMyMap()
- {
+ public function testImportExportFavorites() {
+ $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
+ $content1 = file_get_contents('tests/test_files/favoritesOk.gpx');
+ $newFile = $userfolder->newFile('favoritesOk.gpx');
+ $newFile->putContent($content1);
+
+ $resp = $this->favoritesController->importFavorites('/favoritesOk.gpx');
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals(27, $data['nbImported']);
+
+ // get favorites
+ $resp = $this->favoritesController->getFavorites();
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals(27, count($data));
+ $nbFavorites = count($data);
+ $categoryCount = [];
+ foreach ($data as $fav) {
+ $categoryCount[$fav['category']] = isset($categoryCount[$fav['category']]) ? ($categoryCount[$fav['category']] + 1) : 1;
+ }
+ $categories = array_keys($categoryCount);
+
+ // import errors
+ $userfolder->newFile('dummy.pdf')->putContent('dummy content');
+
+ $resp = $this->favoritesController->importFavorites('/dummy.gpx');
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('File does not exist', $data);
+
+ $resp = $this->favoritesController->importFavorites('/dummy.pdf');
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('Invalid file extension', $data);
+
+ // export and compare
+ $resp = $this->favoritesController->exportFavorites($categories, null, null, true);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $exportPath = $resp->getData();
+ $this->assertEquals(true, $userfolder->nodeExists($exportPath));
+
+ // parse xml and compare number of favorite for each category
+ $xmLData = $userfolder->get($exportPath)->getContent();
+ $xml = simplexml_load_string($xmLData);
+ $wpts = $xml->wpt;
+ $this->assertEquals($nbFavorites, count($wpts));
+ $categoryCountExport = [];
+ foreach ($wpts as $wpt) {
+ $cat = (string)$wpt->type[0];
+ $categoryCountExport[$cat] = isset($categoryCountExport[$cat]) ? ($categoryCountExport[$cat] + 1) : 1;
+ }
+ foreach ($categoryCount as $cat => $nb) {
+ $this->assertEquals($categoryCountExport[$cat], $nb);
+ }
+
+ // export error
+ $resp = $this->favoritesController->exportFavorites(null, null, null, true);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('Nothing to export', $data);
+
+ $userfolder->get('/Maps')->delete();
+ $userfolder->newFile('Maps')->putContent('dummy content');
+ $resp = $this->favoritesController->exportFavorites($categories, null, null, true);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('/Maps is not a directory', $data);
+ $userfolder->get('/Maps')->delete();
+
+ // delete all favorites
+ $resp = $this->favoritesController->getFavorites();
+ $data = $resp->getData();
+ $favIds = [];
+ foreach ($data as $fav) {
+ array_push($favIds, $fav['id']);
+ }
+ $resp = $this->favoritesController->deleteFavorites($favIds);
+
+ // and then try to export
+ $resp = $this->favoritesController->exportFavorites($categories, null, null, true);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('Nothing to export', $data);
+ }
+
+
+
+ public function testEditFavorites() {
+ // valid edition
+ $resp = $this->favoritesController->addFavorite('a', 3.1, 4.1, 'cat1', null, null);
+ $favId = $resp->getData()['id'];
+
+ $resp = $this->favoritesController->editFavorite($favId, 'aa', 3.2, 4.2, 'cat2', 'comment', 'ext');
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals($favId, $data['id']);
+
+ $resp = $this->favoritesController->getFavorites();
+ $favs = $resp->getData();
+ $seen = false;
+ foreach ($favs as $fav) {
+ if ($fav['id'] === $favId) {
+ $seen = true;
+ $this->assertEquals('aa', $fav['name']);
+ $this->assertEquals(3.2, $fav['lat']);
+ $this->assertEquals(4.2, $fav['lng']);
+ $this->assertEquals('cat2', $fav['category']);
+ $this->assertEquals('comment', $fav['comment']);
+ $this->assertEquals('ext', $fav['extensions']);
+ }
+ }
+ $this->assertEquals(true, $seen);
+
+ // invalid edition
+ //ToDo: Probably test for type errors
+ //
+ // $resp = $this->favoritesController->editFavorite($favId, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
+ // $status = $resp->getStatus();
+ // $this->assertEquals(400, $status);
+ // $data = $resp->getData();
+ // $this->assertEquals('Invalid values', $data);
+ //
+ // $resp = $this->favoritesController->editFavorite(-1, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext');
+ // $this->assertEquals(400, $status);
+ // $data = $resp->getData();
+ // $this->assertEquals('No such favorite', $data);
+
+ // rename category
+ $resp = $this->favoritesController->addFavorite('b', 3.1, 4.2, 'cat1', null, null);
+ $resp = $this->favoritesController->addFavorite('one', 3.1, 4.2, 'cat2', null, null);
+
+ $resp = $this->favoritesController->renameCategories(['cat1'], 'cat1RENAMED');
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals('RENAMED', $data);
+ // check if renaming worked
+ $resp = $this->favoritesController->getFavorites();
+ $favs = $resp->getData();
+ $seen = false;
+ foreach ($favs as $fav) {
+ if ($fav['name'] === 'b') {
+ $seen = true;
+ $this->assertEquals('cat1RENAMED', $fav['category']);
+ }
+ }
+ $this->assertEquals(true, $seen);
+ }
+
+ public function testEditFavoritesMyMap() {
$this->mapFolder = $this->createMapFolder();
$myMapId = $this->mapFolder->getId();
// valid edition
@@ -473,16 +463,16 @@ public function testEditFavoritesMyMap()
// invalid edition
//todo: check for type error
-// $resp = $this->favoritesController->editFavorite($favId, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext', $myMapId);
-// $status = $resp->getStatus();
-// $this->assertEquals(400, $status);
-// $data = $resp->getData();
-// $this->assertEquals('invalid values', $data);
-//
-// $resp = $this->favoritesController->editFavorite(-1, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext', $myMapId);
-// $this->assertEquals(400, $status);
-// $data = $resp->getData();
-// $this->assertEquals('no such favorite', $data);
+ // $resp = $this->favoritesController->editFavorite($favId, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext', $myMapId);
+ // $status = $resp->getStatus();
+ // $this->assertEquals(400, $status);
+ // $data = $resp->getData();
+ // $this->assertEquals('invalid values', $data);
+ //
+ // $resp = $this->favoritesController->editFavorite(-1, 'aa', 'invalid lat', 4.2, 'cat2', 'comment', 'ext', $myMapId);
+ // $this->assertEquals(400, $status);
+ // $data = $resp->getData();
+ // $this->assertEquals('no such favorite', $data);
// rename category
$resp = $this->favoritesController->addFavorite('b', 3.1, 4.2, 'cat1', null, null, $myMapId);
@@ -506,110 +496,110 @@ public function testEditFavoritesMyMap()
$this->assertEquals(true, $seen);
}
- public function testShareUnShareCategory() {
- $categoryName = 'test3458565';
-
- $id = $this->favoritesController
- ->addFavorite('Test', 0, 0, $categoryName, "", null)
- ->getData()['id'];
+ public function testShareUnShareCategory() {
+ $categoryName = 'test3458565';
- $response1 = $this->favoritesController->shareCategory($categoryName);
- $response2 = $this->favoritesController->unShareCategory($categoryName);
+ $id = $this->favoritesController
+ ->addFavorite('Test', 0, 0, $categoryName, '', null)
+ ->getData()['id'];
- $this->favoritesController->deleteFavorite($id);
+ $response1 = $this->favoritesController->shareCategory($categoryName);
+ $response2 = $this->favoritesController->unShareCategory($categoryName);
- $this->assertEquals(Http::STATUS_OK, $response1->getStatus());
- $this->assertEquals(Http::STATUS_OK, $response2->getStatus());
+ $this->favoritesController->deleteFavorite($id);
- $this->assertIsString($response1->getData()->getToken());
- $this->assertTrue($response2->getData()['did_exist']);
- }
+ $this->assertEquals(Http::STATUS_OK, $response1->getStatus());
+ $this->assertEquals(Http::STATUS_OK, $response2->getStatus());
- public function testShareUnShareCategoryNotAuthorized() {
- $categoryName = 'test3458565';
+ $this->assertIsString($response1->getData()->getToken());
+ $this->assertTrue($response2->getData()['did_exist']);
+ }
- $id = $this->favoritesController2
- ->addFavorite("Test2", 0, 0, $categoryName, "", null)
- ->getData()['id'];
+ public function testShareUnShareCategoryNotAuthorized() {
+ $categoryName = 'test3458565';
- $response1 = $this->favoritesController->shareCategory($categoryName);
- $response2 = $this->favoritesController->unShareCategory($categoryName);
+ $id = $this->favoritesController2
+ ->addFavorite('Test2', 0, 0, $categoryName, '', null)
+ ->getData()['id'];
- $this->favoritesController->deleteFavorite($id);
+ $response1 = $this->favoritesController->shareCategory($categoryName);
+ $response2 = $this->favoritesController->unShareCategory($categoryName);
- $this->assertEquals(Http::STATUS_BAD_REQUEST, $response1->getStatus());
- $this->assertEquals(Http::STATUS_BAD_REQUEST, $response2->getStatus());
- }
+ $this->favoritesController->deleteFavorite($id);
- public function testShareUnShareNonExistentCategory() {
- $categoryName = 'non_existent';
+ $this->assertEquals(Http::STATUS_BAD_REQUEST, $response1->getStatus());
+ $this->assertEquals(Http::STATUS_BAD_REQUEST, $response2->getStatus());
+ }
- $response1 = $this->favoritesController->shareCategory($categoryName);
- $response2 = $this->favoritesController->unShareCategory($categoryName);
+ public function testShareUnShareNonExistentCategory() {
+ $categoryName = 'non_existent';
- $this->favoritesController->unShareCategory($categoryName);
+ $response1 = $this->favoritesController->shareCategory($categoryName);
+ $response2 = $this->favoritesController->unShareCategory($categoryName);
- $this->assertEquals(Http::STATUS_BAD_REQUEST, $response1->getStatus());
- $this->assertEquals(Http::STATUS_BAD_REQUEST, $response2->getStatus());
- }
+ $this->favoritesController->unShareCategory($categoryName);
- public function testGetSharedCategories() {
- $categoryNames = ['test345456', 'test2345465', 'test65765'];
- $ids = [];
+ $this->assertEquals(Http::STATUS_BAD_REQUEST, $response1->getStatus());
+ $this->assertEquals(Http::STATUS_BAD_REQUEST, $response2->getStatus());
+ }
- foreach ($categoryNames as $categoryName) {
- array_push(
- $ids,
- $this->favoritesController
- ->addFavorite("Test", 0, 0, $categoryName, "", null)
- ->getData()['id']
- );
- $this->favoritesController->shareCategory($categoryName);
- }
+ public function testGetSharedCategories() {
+ $categoryNames = ['test345456', 'test2345465', 'test65765'];
+ $ids = [];
+
+ foreach ($categoryNames as $categoryName) {
+ array_push(
+ $ids,
+ $this->favoritesController
+ ->addFavorite('Test', 0, 0, $categoryName, '', null)
+ ->getData()['id']
+ );
+ $this->favoritesController->shareCategory($categoryName);
+ }
- $categories = $this->favoritesController->getSharedCategories();
+ $categories = $this->favoritesController->getSharedCategories();
- $this->assertIsArray($categories->getData());
+ $this->assertIsArray($categories->getData());
- $mappedCategories = array_map(function ($el) {
- return $el->getCategory();
- }, $categories->getData());
+ $mappedCategories = array_map(function ($el) {
+ return $el->getCategory();
+ }, $categories->getData());
- foreach ($categoryNames as $categoryName) {
- $this->assertContains($categoryName, $mappedCategories);
- }
+ foreach ($categoryNames as $categoryName) {
+ $this->assertContains($categoryName, $mappedCategories);
+ }
- foreach ($categoryNames as $categoryName) {
- $this->favoritesController->unShareCategory($categoryName);
- }
+ foreach ($categoryNames as $categoryName) {
+ $this->favoritesController->unShareCategory($categoryName);
+ }
- foreach ($ids as $id) {
- $this->favoritesController->deleteFavorite($id);
- }
- }
+ foreach ($ids as $id) {
+ $this->favoritesController->deleteFavorite($id);
+ }
+ }
- public function testFavoriteShareIsRenamedCorrectly() {
- $categoryName = 'test03059035';
- $newCategoryName = 'test097876';
+ public function testFavoriteShareIsRenamedCorrectly() {
+ $categoryName = 'test03059035';
+ $newCategoryName = 'test097876';
- $id = $this->favoritesController
- ->addFavorite("Test", 0, 0, $categoryName, "", null)
- ->getData()['id'];
+ $id = $this->favoritesController
+ ->addFavorite('Test', 0, 0, $categoryName, '', null)
+ ->getData()['id'];
- $this->favoritesController->shareCategory($categoryName);
+ $this->favoritesController->shareCategory($categoryName);
- $this->favoritesController->renameCategories([$categoryName], $newCategoryName);
+ $this->favoritesController->renameCategories([$categoryName], $newCategoryName);
- $shares = $this->favoritesController->getSharedCategories()->getData();
+ $shares = $this->favoritesController->getSharedCategories()->getData();
- $shareNames = array_map(function($el) {
- return $el->getCategory();
- }, $shares);
+ $shareNames = array_map(function ($el) {
+ return $el->getCategory();
+ }, $shares);
- $this->favoritesController->deleteFavorite($id);
- $this->favoritesController->unShareCategory($newCategoryName);
+ $this->favoritesController->deleteFavorite($id);
+ $this->favoritesController->unShareCategory($newCategoryName);
- $this->assertContains($newCategoryName, $shareNames);
- $this->assertNotContains($categoryName, $shareNames);
- }
+ $this->assertContains($newCategoryName, $shareNames);
+ $this->assertNotContains($categoryName, $shareNames);
+ }
}
diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php
index a3a550ec1..bc44384c7 100644
--- a/tests/Unit/Controller/PageControllerTest.php
+++ b/tests/Unit/Controller/PageControllerTest.php
@@ -11,53 +11,52 @@
namespace OCA\Maps\Controller;
-use \OCA\Maps\AppInfo\Application;
-use \OCP\AppFramework\Http\TemplateResponse;
-use \OCP\EventDispatcher\IEventDispatcher;
-use \OCP\IServerContainer;
-
+use OCA\Maps\AppInfo\Application;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\IServerContainer;
class PageControllerTest extends \PHPUnit\Framework\TestCase {
- private $controller;
- private $userId = 'john';
- private $config;
+ private $controller;
+ private $userId = 'john';
+ private $config;
private $eventDispatcher;
- private $app;
- private $container;
-
- protected function setUp(): void {
- $request = $this->getMockBuilder('OCP\IRequest')->getMock();
- $initialStateService = $this->getMockBuilder('OCP\IInitialStateService')->getMock();
- $this->app = new Application();
- $this->container = $this->app->getContainer();
- $c = $this->container;
- $this->config = $c->query(IServerContainer::class)->getConfig();
+ private $app;
+ private $container;
+
+ protected function setUp(): void {
+ $request = $this->getMockBuilder('OCP\IRequest')->getMock();
+ $initialStateService = $this->getMockBuilder('OCP\IInitialStateService')->getMock();
+ $this->app = new Application();
+ $this->container = $this->app->getContainer();
+ $c = $this->container;
+ $this->config = $c->query(IServerContainer::class)->getConfig();
$this->eventDispatcher = $c->query(IServerContainer::class)->query(IEventDispatcher::class);
- $this->oldGHValue = $this->config->getAppValue('maps', 'graphhopperURL');
- $this->config->setAppValue('maps', 'graphhopperURL', 'https://graphhopper.com:8080');
+ $this->oldGHValue = $this->config->getAppValue('maps', 'graphhopperURL');
+ $this->config->setAppValue('maps', 'graphhopperURL', 'https://graphhopper.com:8080');
- $this->controller = new PageController(
- 'maps', $request, $this->eventDispatcher, $this->config, $initialStateService, $this->userId
- );
- }
+ $this->controller = new PageController(
+ 'maps', $request, $this->eventDispatcher, $this->config, $initialStateService, $this->userId
+ );
+ }
- protected function tearDown(): void {
- $this->config->setAppValue('maps', 'graphhopperURL', $this->oldGHValue);
- }
+ protected function tearDown(): void {
+ $this->config->setAppValue('maps', 'graphhopperURL', $this->oldGHValue);
+ }
- public function testIndex() {
- $result = $this->controller->index();
+ public function testIndex() {
+ $result = $this->controller->index();
- $this->assertEquals('main', $result->getTemplateName());
- $this->assertTrue($result instanceof TemplateResponse);
- }
+ $this->assertEquals('main', $result->getTemplateName());
+ $this->assertTrue($result instanceof TemplateResponse);
+ }
- public function testOpenGeoLink() {
- $result = $this->controller->openGeoLink('geo:1.1,2.2');
+ public function testOpenGeoLink() {
+ $result = $this->controller->openGeoLink('geo:1.1,2.2');
- $this->assertEquals('main', $result->getTemplateName());
- $this->assertTrue($result instanceof TemplateResponse);
- }
+ $this->assertEquals('main', $result->getTemplateName());
+ $this->assertTrue($result instanceof TemplateResponse);
+ }
}
diff --git a/tests/Unit/Controller/PhotosControllerTest.php b/tests/Unit/Controller/PhotosControllerTest.php
index a3ee4aac6..1e46d9514 100644
--- a/tests/Unit/Controller/PhotosControllerTest.php
+++ b/tests/Unit/Controller/PhotosControllerTest.php
@@ -11,207 +11,203 @@
namespace OCA\Maps\Controller;
-use \OCA\Maps\AppInfo\Application;
-use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCA\Maps\AppInfo\Application;
+use OCA\Maps\DB\GeophotoMapper;
use OCA\Maps\Service\GeophotoService;
use OCA\Maps\Service\PhotofilesService;
-use OCA\Maps\Service\TracksService;
-use OCA\Maps\Service\DevicesService;
-use OCA\Maps\DB\GeophotoMapper;
-use OCP\AppFramework\Http\TemplateResponse;
-use \OCP\IServerContainer;
-
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IServerContainer;
class PhotosControllerTest extends \PHPUnit\Framework\TestCase {
- private $appName;
- private $request;
- private $contacts;
+ private $appName;
+ private $request;
+ private $contacts;
- private $container;
- private $config;
- private $app;
+ private $container;
+ private $config;
+ private $app;
- private $photosController;
- private $photosController2;
- private $utilsController;
+ private $photosController;
+ private $photosController2;
+ private $utilsController;
- private $photoFileService;
+ private $photoFileService;
private $GeoPhotosService;
- public static function setUpBeforeClass(): void {
- $app = new Application();
- $c = $app->getContainer();
-
- $user = $c->getServer()->getUserManager()->get('test');
- $user2 = $c->getServer()->getUserManager()->get('test2');
- $user3 = $c->getServer()->getUserManager()->get('test3');
- $group = $c->getServer()->getGroupManager()->get('group1test');
- $group2 = $c->getServer()->getGroupManager()->get('group2test');
-
- // CREATE DUMMY USERS
- if ($user === null) {
- $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
- $u1->setEMailAddress('toto@toto.net');
- }
- if ($user2 === null) {
- $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
- }
- if ($user2 === null) {
- $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
- }
- if ($group === null) {
- $c->getServer()->getGroupManager()->createGroup('group1test');
- $u1 = $c->getServer()->getUserManager()->get('test');
- $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
- }
- if ($group2 === null) {
- $c->getServer()->getGroupManager()->createGroup('group2test');
- $u2 = $c->getServer()->getUserManager()->get('test2');
- $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
- }
- }
-
- protected function setUp(): void {
- $this->appName = 'maps';
- $this->request = $this->getMockBuilder('\OCP\IRequest')
- ->disableOriginalConstructor()
- ->getMock();
- $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->app = new Application();
- $this->container = $this->app->getContainer();
- $c = $this->container;
- $this->config = $c->query(IServerContainer::class)->getConfig();
-
- $this->rootFolder = $c->query(IServerContainer::class)->getRootFolder();
+ public static function setUpBeforeClass(): void {
+ $app = new Application();
+ $c = $app->getContainer();
+
+ $user = $c->getServer()->getUserManager()->get('test');
+ $user2 = $c->getServer()->getUserManager()->get('test2');
+ $user3 = $c->getServer()->getUserManager()->get('test3');
+ $group = $c->getServer()->getGroupManager()->get('group1test');
+ $group2 = $c->getServer()->getGroupManager()->get('group2test');
+
+ // CREATE DUMMY USERS
+ if ($user === null) {
+ $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
+ $u1->setEMailAddress('toto@toto.net');
+ }
+ if ($user2 === null) {
+ $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
+ }
+ if ($user2 === null) {
+ $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
+ }
+ if ($group === null) {
+ $c->getServer()->getGroupManager()->createGroup('group1test');
+ $u1 = $c->getServer()->getUserManager()->get('test');
+ $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
+ }
+ if ($group2 === null) {
+ $c->getServer()->getGroupManager()->createGroup('group2test');
+ $u2 = $c->getServer()->getUserManager()->get('test2');
+ $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
+ }
+ }
+
+ protected function setUp(): void {
+ $this->appName = 'maps';
+ $this->request = $this->getMockBuilder('\OCP\IRequest')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->app = new Application();
+ $this->container = $this->app->getContainer();
+ $c = $this->container;
+ $this->config = $c->query(IServerContainer::class)->getConfig();
+
+ $this->rootFolder = $c->query(IServerContainer::class)->getRootFolder();
$this->GeoPhotosService = $c->query(GeoPhotoService::class);
- $this->photoFileService = new PhotoFilesService(
- $c->query(IServerContainer::class)->getLogger(),
+ $this->photoFileService = new PhotoFilesService(
+ $c->query(IServerContainer::class)->getLogger(),
$c->query(IServerContainer::class)->getMemCacheFactory(),
- $this->rootFolder,
- $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
- $c->query(GeophotoMapper::class),
- $c->query(IServerContainer::class)->getShareManager(),
- $c->query(\OCP\BackgroundJob\IJobList::class)
- );
-
- $this->photosController = new PhotosController(
- $this->appName,
- $c->query(IServerContainer::class)->getLogger(),
- $this->request,
- $this->GeoPhotosService,
- $this->photoFileService,
+ $this->rootFolder,
+ $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
+ $c->query(GeophotoMapper::class),
+ $c->query(IServerContainer::class)->getShareManager(),
+ $c->query(\OCP\BackgroundJob\IJobList::class)
+ );
+
+ $this->photosController = new PhotosController(
+ $this->appName,
+ $c->query(IServerContainer::class)->getLogger(),
+ $this->request,
+ $this->GeoPhotosService,
+ $this->photoFileService,
$this->rootFolder,
'test'
- );
-
- $this->photosController2 = new PhotosController(
- $this->appName,
- $c->query(IServerContainer::class)->getLogger(),
- $this->request,
- $c->query(GeoPhotoService::class),
- $this->photoFileService,
+ );
+
+ $this->photosController2 = new PhotosController(
+ $this->appName,
+ $c->query(IServerContainer::class)->getLogger(),
+ $this->request,
+ $c->query(GeoPhotoService::class),
+ $this->photoFileService,
$this->rootFolder,
- 'test2'
- );
-
- $this->utilsController = new UtilsController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getAppManager(),
+ 'test2'
+ );
+
+ $this->utilsController = new UtilsController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getAppManager(),
$this->rootFolder,
- 'test'
- );
-
- $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
- // delete files
- if ($userfolder->nodeExists('nc.jpg')) {
- $file = $userfolder->get('nc.jpg');
- $file->delete();
- }
- if ($userfolder->nodeExists('nut.jpg')) {
- $file = $userfolder->get('nut.jpg');
- $file->delete();
- }
- // delete db
- $qb = $c->query(IServerContainer::class)->query(\OCP\IDBConnection::class)->getQueryBuilder();
- $qb->delete('maps_photos')
- ->where(
- $qb->expr()->eq('user_id', $qb->createNamedParameter('test', IQueryBuilder::PARAM_STR))
- );
- $req = $qb->execute();
- $qb = $qb->resetQueryParts();
- }
-
- public static function tearDownAfterClass(): void {
- //$app = new Application();
- //$c = $app->getContainer();
- //$user = $c->getServer()->getUserManager()->get('test');
- //$user->delete();
- //$user = $c->getServer()->getUserManager()->get('test2');
- //$user->delete();
- //$user = $c->getServer()->getUserManager()->get('test3');
- //$user->delete();
- //$c->getServer()->getGroupManager()->get('group1test')->delete();
- //$c->getServer()->getGroupManager()->get('group2test')->delete();
- }
-
- protected function tearDown(): void {
- // in case there was a failure and something was not deleted
- }
-
- public function testAddGetPhotos() {
- $c = $this->app->getContainer();
-
- $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
-
- $filename = 'tests/test_files/nc.jpg';
- $handle = fopen($filename, 'rb');
- $content1 = fread($handle, filesize($filename));
- fclose($handle);
- $file = $userfolder->newFile('nc.jpgg');
- $fp = $file->fopen('wb');
- fwrite($fp, $content1);
- fclose($fp);
- $file->touch();
- // rename
- $file = $userfolder->get('nc.jpgg');
- $file->move($userfolder->getPath().'/nc.jpg');
- $file = $userfolder->get('nc.jpg');
- $file->touch();
+ 'test'
+ );
+
+ $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
+ // delete files
+ if ($userfolder->nodeExists('nc.jpg')) {
+ $file = $userfolder->get('nc.jpg');
+ $file->delete();
+ }
+ if ($userfolder->nodeExists('nut.jpg')) {
+ $file = $userfolder->get('nut.jpg');
+ $file->delete();
+ }
+ // delete db
+ $qb = $c->query(IServerContainer::class)->query(\OCP\IDBConnection::class)->getQueryBuilder();
+ $qb->delete('maps_photos')
+ ->where(
+ $qb->expr()->eq('user_id', $qb->createNamedParameter('test', IQueryBuilder::PARAM_STR))
+ );
+ $req = $qb->execute();
+ $qb = $qb->resetQueryParts();
+ }
+
+ public static function tearDownAfterClass(): void {
+ //$app = new Application();
+ //$c = $app->getContainer();
+ //$user = $c->getServer()->getUserManager()->get('test');
+ //$user->delete();
+ //$user = $c->getServer()->getUserManager()->get('test2');
+ //$user->delete();
+ //$user = $c->getServer()->getUserManager()->get('test3');
+ //$user->delete();
+ //$c->getServer()->getGroupManager()->get('group1test')->delete();
+ //$c->getServer()->getGroupManager()->get('group2test')->delete();
+ }
+
+ protected function tearDown(): void {
+ // in case there was a failure and something was not deleted
+ }
+
+ public function testAddGetPhotos() {
+ $c = $this->app->getContainer();
+
+ $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
+
+ $filename = 'tests/test_files/nc.jpg';
+ $handle = fopen($filename, 'rb');
+ $content1 = fread($handle, filesize($filename));
+ fclose($handle);
+ $file = $userfolder->newFile('nc.jpgg');
+ $fp = $file->fopen('wb');
+ fwrite($fp, $content1);
+ fclose($fp);
+ $file->touch();
+ // rename
+ $file = $userfolder->get('nc.jpgg');
+ $file->move($userfolder->getPath().'/nc.jpg');
+ $file = $userfolder->get('nc.jpg');
+ $file->touch();
$this->photoFileService->addPhotoNow($file, 'test');
- $filename = 'tests/test_files/nut.jpg';
- $handle = fopen($filename, 'rb');
- $content1 = fread($handle, filesize($filename));
- fclose($handle);
- $file = $userfolder->newFile('nut.jpgg');
- $fp = $file->fopen('wb');
- fwrite($fp, $content1);
- fclose($fp);
- $file->touch();
- // rename
- $file = $userfolder->get('nut.jpgg');
- $file->move($userfolder->getPath().'/nut.jpg');
- $file = $userfolder->get('nut.jpg');
- $file->touch();
-
- // following section is not valid anymore
- // TODO fix photo scan (or make it really better) and then adjust tests ;-)
- $this->photoFileService->addPhotoNow($file, 'test');
+ $filename = 'tests/test_files/nut.jpg';
+ $handle = fopen($filename, 'rb');
+ $content1 = fread($handle, filesize($filename));
+ fclose($handle);
+ $file = $userfolder->newFile('nut.jpgg');
+ $fp = $file->fopen('wb');
+ fwrite($fp, $content1);
+ fclose($fp);
+ $file->touch();
+ // rename
+ $file = $userfolder->get('nut.jpgg');
+ $file->move($userfolder->getPath().'/nut.jpg');
+ $file = $userfolder->get('nut.jpg');
+ $file->touch();
+
+ // following section is not valid anymore
+ // TODO fix photo scan (or make it really better) and then adjust tests ;-)
+ $this->photoFileService->addPhotoNow($file, 'test');
$this->GeoPhotosService->clearCache();
- $resp = $this->photosController->getPhotos();
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertCount(1, $data);
- $this->assertEquals('/nc.jpg', $data[0]->path);
+ $resp = $this->photosController->getPhotos();
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertCount(1, $data);
+ $this->assertEquals('/nc.jpg', $data[0]->path);
//Test .nomedia respected
$this->GeoPhotosService->clearCache();
@@ -243,13 +239,13 @@ public function testAddGetPhotos() {
$this->assertEquals(0, count($data));
$file->delete();
- // non localized without track
+ // non localized without track
$this->GeoPhotosService->clearCache();
- $resp = $this->photosController->getNonLocalizedPhotos();
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertCount(0, $data);
+ $resp = $this->photosController->getNonLocalizedPhotos();
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertCount(0, $data);
// with track
$filename = 'tests/test_files/testFile1_locationNut.gpx';
@@ -273,7 +269,7 @@ public function testAddGetPhotos() {
$this->assertStringStartsWith('track:', array_key_first($data));
$dataForTrack = array_shift($data);
$this->assertCount(1, $dataForTrack);
- $this->assertEquals('/nut.jpg', $dataForTrack[0]->path);
+ $this->assertEquals('/nut.jpg', $dataForTrack[0]->path);
//Test .nomedia respected
$this->GeoPhotosService->clearCache();
@@ -315,19 +311,19 @@ public function testAddGetPhotos() {
$this->assertEquals(0, count($data));
$file->delete();
- // place photos
- $resp = $this->photosController->placePhotos(['/nut.jpg'], [1.2345], [9.8765]);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertCount(1, $data);
+ // place photos
+ $resp = $this->photosController->placePhotos(['/nut.jpg'], [1.2345], [9.8765]);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertCount(1, $data);
$this->GeoPhotosService->clearCache();
- $resp = $this->photosController->getPhotos();
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertCount(2, $data);
+ $resp = $this->photosController->getPhotos();
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertCount(2, $data);
$this->GeoPhotosService->clearCache();
$resp = $this->photosController->getNonLocalizedPhotos();
@@ -336,19 +332,19 @@ public function testAddGetPhotos() {
$data = $resp->getData();
$this->assertCount(0, $data);
- // reset coords
- $resp = $this->photosController->resetPhotosCoords(['/nut.jpg']);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertCount(1, $data);
+ // reset coords
+ $resp = $this->photosController->resetPhotosCoords(['/nut.jpg']);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertCount(1, $data);
$this->GeoPhotosService->clearCache();
- $resp = $this->photosController->getPhotos();
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertCount(1, $data);
+ $resp = $this->photosController->getPhotos();
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertCount(1, $data);
//Test usage of cache adding photo
$resp = $this->photosController->placePhotos(['/nut.jpg'], [1.2345], [9.8765]);
@@ -371,6 +367,6 @@ public function testAddGetPhotos() {
$data = $resp->getData();
$this->assertCount(0, $data);
- }
+ }
}
diff --git a/tests/Unit/Controller/PublicFavoritePageControllerTest.php b/tests/Unit/Controller/PublicFavoritePageControllerTest.php
index 903d0428f..fa9871352 100644
--- a/tests/Unit/Controller/PublicFavoritePageControllerTest.php
+++ b/tests/Unit/Controller/PublicFavoritePageControllerTest.php
@@ -25,104 +25,98 @@
use OC;
use OC\AppFramework\Http;
-use \OCA\Maps\AppInfo\Application;
+use OCA\Maps\AppInfo\Application;
use OCA\Maps\DB\FavoriteShareMapper;
use OCA\Maps\Service\FavoritesService;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\IAppContainer;
-use \OCP\IServerContainer;
+use OCP\IServerContainer;
use PHPUnit\Framework\TestCase;
+class PublicFavoritePageControllerTest extends TestCase {
+ /* @var PublicFavoritePageController */
+ private $publicPageController;
-class PublicFavoritePageControllerTest extends TestCase
-{
- /* @var PublicFavoritePageController */
- private $publicPageController;
+ private $config;
- private $config;
+ /* @var Application */
+ private $app;
- /* @var Application */
- private $app;
+ /* @var IAppContainer */
+ private $container;
- /* @var IAppContainer */
- private $container;
+ /* @var FavoritesService */
+ private $favoritesService;
- /* @var FavoritesService */
- private $favoritesService;
+ /* @var FavoriteShareMapper */
+ private $favoriteShareMapper;
- /* @var FavoriteShareMapper */
- private $favoriteShareMapper;
+ protected function setUp(): void {
+ // Begin transaction
+ $db = OC::$server->query(\OCP\IDBConnection::class);
+ $db->beginTransaction();
- protected function setUp(): void
- {
- // Begin transaction
- $db = OC::$server->query(\OCP\IDBConnection::class);
- $db->beginTransaction();
+ $this->app = new Application();
- $this->app = new Application();
+ $this->container = $this->app->getContainer();
+ $container = $this->container;
- $this->container = $this->app->getContainer();
- $container = $this->container;
+ $appName = $container->query('AppName');
- $appName = $container->query('AppName');
+ $this->favoritesService = new FavoritesService(
+ $container->query(IServerContainer::class)->getLogger(),
+ $container->query(IServerContainer::class)->getL10N($appName),
+ $container->query(IServerContainer::class)->getSecureRandom(),
+ $container->query(\OCP\IDBConnection::class)
+ );
- $this->favoritesService = new FavoritesService(
- $container->query(IServerContainer::class)->getLogger(),
- $container->query(IServerContainer::class)->getL10N($appName),
- $container->query(IServerContainer::class)->getSecureRandom(),
- $container->query(\OCP\IDBConnection::class)
- );
+ $this->favoriteShareMapper = new FavoriteShareMapper(
+ $container->query(\OCP\IDBConnection::class),
+ $container->query(IServerContainer::class)->getSecureRandom(),
+ $container->query(IServerContainer::class)->getRootFolder()
+ );
- $this->favoriteShareMapper = new FavoriteShareMapper(
- $container->query(\OCP\IDBConnection::class),
- $container->query(IServerContainer::class)->getSecureRandom(),
- $container->query(IServerContainer::class)->getRootFolder()
- );
+ $requestMock = $this->getMockBuilder('OCP\IRequest')->getMock();
+ $sessionMock = $this->getMockBuilder('OCP\ISession')->getMock();
- $requestMock = $this->getMockBuilder('OCP\IRequest')->getMock();
- $sessionMock = $this->getMockBuilder('OCP\ISession')->getMock();
+ $this->config = $container->query(IServerContainer::class)->getConfig();
- $this->config = $container->query(IServerContainer::class)->getConfig();
+ $this->publicPageController = new PublicFavoritePageController(
+ $appName,
+ $requestMock,
+ $sessionMock,
+ $this->config,
+ $container->query(\OCP\ILogger::class),
+ $this->favoriteShareMapper
+ );
+ }
- $this->publicPageController = new PublicFavoritePageController(
- $appName,
- $requestMock,
- $sessionMock,
- $this->config,
- $container->query(\OCP\ILogger::class),
- $this->favoriteShareMapper
- );
- }
+ protected function tearDown(): void {
+ // Rollback transaction
+ $db = OC::$server->query(\OCP\IDBConnection::class);
+ $db->rollBack();
+ }
- protected function tearDown(): void
- {
- // Rollback transaction
- $db = OC::$server->query(\OCP\IDBConnection::class);
- $db->rollBack();
- }
+ public function testSharedFavoritesCategory() {
+ $categoryName = 'test908780';
+ $testUserName = 'test';
- public function testSharedFavoritesCategory()
- {
- $categoryName = 'test908780';
- $testUserName = 'test';
+ $this->favoritesService
+ ->addFavoriteToDB($testUserName, 'Test', 0, 0, $categoryName, '', null);
+ $share = $this->favoriteShareMapper->create($testUserName, $categoryName);
- $this->favoritesService
- ->addFavoriteToDB($testUserName, "Test", 0, 0, $categoryName, "", null);
- $share = $this->favoriteShareMapper->create($testUserName, $categoryName);
+ $result = $this->publicPageController->sharedFavoritesCategory($share->getToken());
- $result = $this->publicPageController->sharedFavoritesCategory($share->getToken());
+ // Assertions
+ $this->assertTrue($result instanceof TemplateResponse);
+ $this->assertEquals('public/favorites_index', $result->getTemplateName());
+ }
- // Assertions
- $this->assertTrue($result instanceof TemplateResponse);
- $this->assertEquals('public/favorites_index', $result->getTemplateName());
- }
+ public function testAccessRestrictionsForSharedFavoritesCategory() {
+ $result = $this->publicPageController->sharedFavoritesCategory('test8348985');
- public function testAccessRestrictionsForSharedFavoritesCategory()
- {
- $result = $this->publicPageController->sharedFavoritesCategory('test8348985');
-
- $this->assertTrue($result instanceof DataResponse);
- $this->assertEquals(Http::STATUS_NOT_FOUND, $result->getStatus());
- }
+ $this->assertTrue($result instanceof DataResponse);
+ $this->assertEquals(Http::STATUS_NOT_FOUND, $result->getStatus());
+ }
}
diff --git a/tests/Unit/Controller/PublicFavoritesApiControllerTest.php b/tests/Unit/Controller/PublicFavoritesApiControllerTest.php
index 345e08b2e..f9290af33 100644
--- a/tests/Unit/Controller/PublicFavoritesApiControllerTest.php
+++ b/tests/Unit/Controller/PublicFavoritesApiControllerTest.php
@@ -25,101 +25,98 @@
use OC;
use OC\AppFramework\Http;
-use \OCP\IServerContainer;
use OCA\Maps\AppInfo\Application;
use OCA\Maps\DB\FavoriteShare;
use OCA\Maps\DB\FavoriteShareMapper;
use OCA\Maps\Service\FavoritesService;
+use OCP\IServerContainer;
use PHPUnit\Framework\TestCase;
+class PublicFavoritesApiControllerTest extends TestCase {
+ /* @var PublicFavoritesApiController */
+ private $publicFavoritesApiController;
-class PublicFavoritesApiControllerTest extends TestCase
-{
- /* @var PublicFavoritesApiController */
- private $publicFavoritesApiController;
+ private $config;
- private $config;
+ /* @var FavoritesService */
+ private $favoritesService;
- /* @var FavoritesService */
- private $favoritesService;
+ /* @var FavoriteShareMapper */
+ private $favoriteShareMapper;
- /* @var FavoriteShareMapper */
- private $favoriteShareMapper;
+ protected function setUp(): void {
+ // Begin transaction
+ $db = OC::$server->query(\OCP\IDBConnection::class);
+ $db->beginTransaction();
- protected function setUp(): void {
- // Begin transaction
- $db = OC::$server->query(\OCP\IDBConnection::class);
- $db->beginTransaction();
+ $container = (new Application())->getContainer();
- $container = (new Application())->getContainer();
+ $appName = $container->query('AppName');
- $appName = $container->query('AppName');
+ $requestMock = $this->getMockBuilder('OCP\IRequest')->getMock();
+ $sessionMock = $this->getMockBuilder('OCP\ISession')->getMock();
- $requestMock = $this->getMockBuilder('OCP\IRequest')->getMock();
- $sessionMock = $this->getMockBuilder('OCP\ISession')->getMock();
+ $this->config = $container->query(IServerContainer::class)->getConfig();
- $this->config = $container->query(IServerContainer::class)->getConfig();
+ $this->favoritesService = new FavoritesService(
+ $container->query(IServerContainer::class)->getLogger(),
+ $container->query(IServerContainer::class)->getL10N($appName),
+ $container->query(IServerContainer::class)->getSecureRandom(),
+ $container->query(\OCP\IDBConnection::class)
+ );
- $this->favoritesService = new FavoritesService(
- $container->query(IServerContainer::class)->getLogger(),
- $container->query(IServerContainer::class)->getL10N($appName),
- $container->query(IServerContainer::class)->getSecureRandom(),
- $container->query(\OCP\IDBConnection::class)
- );
+ $this->favoriteShareMapper = new FavoriteShareMapper(
+ $container->query(\OCP\IDBConnection::class),
+ $container->query(IServerContainer::class)->getSecureRandom(),
+ $container->query(IserverContainer::class)->getRootFolder()
+ );
- $this->favoriteShareMapper = new FavoriteShareMapper(
- $container->query(\OCP\IDBConnection::class),
- $container->query(IServerContainer::class)->getSecureRandom(),
- $container->query(IserverContainer::class)->getRootFolder()
- );
+ $this->publicFavoritesApiController = new PublicFavoritesApiController(
+ $appName,
+ $requestMock,
+ $sessionMock,
+ $this->favoritesService,
+ $this->favoriteShareMapper
+ );
+ }
- $this->publicFavoritesApiController = new PublicFavoritesApiController(
- $appName,
- $requestMock,
- $sessionMock,
- $this->favoritesService,
- $this->favoriteShareMapper
- );
- }
+ protected function tearDown(): void {
+ // Rollback transaction
+ $db = OC::$server->query(\OCP\IDBConnection::class);
+ $db->rollBack();
+ }
- protected function tearDown(): void
- {
- // Rollback transaction
- $db = OC::$server->query(\OCP\IDBConnection::class);
- $db->rollBack();
- }
+ public function testGetFavorites() {
+ $testUser = 'test099897';
+ $categoryName = 'test89774590';
- public function testGetFavorites() {
- $testUser = 'test099897';
- $categoryName = 'test89774590';
+ $this->favoritesService
+ ->addFavoriteToDB($testUser, 'Test1', 0, 0, $categoryName, '', null);
- $this->favoritesService
- ->addFavoriteToDB($testUser, "Test1", 0, 0, $categoryName, "", null);
+ /* @var FavoriteShare */
+ $share = $this->favoriteShareMapper->create($testUser, $categoryName);
- /* @var FavoriteShare */
- $share = $this->favoriteShareMapper->create($testUser, $categoryName);
+ // Mock token sent by request
+ $this->publicFavoritesApiController->setToken($share->getToken());
- // Mock token sent by request
- $this->publicFavoritesApiController->setToken($share->getToken());
+ $response = $this->publicFavoritesApiController->getFavorites();
- $response = $this->publicFavoritesApiController->getFavorites();
+ $this->assertEquals(Http::STATUS_OK, $response->getStatus());
- $this->assertEquals(Http::STATUS_OK, $response->getStatus());
+ $data = $response->getData();
- $data = $response->getData();
+ $this->assertIsArray($data);
+ $this->assertArrayHasKey('share', $data);
+ $this->assertArrayHasKey('favorites', $data);
- $this->assertIsArray($data);
- $this->assertArrayHasKey('share', $data);
- $this->assertArrayHasKey('favorites', $data);
+ $this->assertEquals($testUser, $data['share']->getOwner());
+ $this->assertEquals($categoryName, $data['share']->getCategory());
+ $this->assertEquals($share->getToken(), $data['share']->getToken());
- $this->assertEquals($testUser, $data['share']->getOwner());
- $this->assertEquals($categoryName, $data['share']->getCategory());
- $this->assertEquals($share->getToken(), $data['share']->getToken());
+ $this->assertEquals(1, count($data['favorites']));
- $this->assertEquals(1, count($data['favorites']));
-
- $el = $data['favorites'][0];
- $this->assertEquals('Test1', $el['name']);
- $this->assertEquals($categoryName, $el['category']);
- }
+ $el = $data['favorites'][0];
+ $this->assertEquals('Test1', $el['name']);
+ $this->assertEquals($categoryName, $el['category']);
+ }
}
diff --git a/tests/Unit/Controller/TracksControllerTest.php b/tests/Unit/Controller/TracksControllerTest.php
index a9734a28c..447e73272 100644
--- a/tests/Unit/Controller/TracksControllerTest.php
+++ b/tests/Unit/Controller/TracksControllerTest.php
@@ -11,285 +11,279 @@
namespace OCA\Maps\Controller;
-use \OCA\Maps\AppInfo\Application;
-use OCP\DB\QueryBuilder\IQueryBuilder;
-use \OCP\IServerContainer;
-use OCA\Maps\Service\GeophotoService;
-use OCA\Maps\Service\PhotofilesService;
+use OCA\Maps\AppInfo\Application;
use OCA\Maps\Service\TracksService;
-use OCA\Maps\Service\DevicesService;
-use OCA\Maps\DB\GeophotoMapper;
-use OCP\AppFramework\Http\TemplateResponse;
-
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IServerContainer;
class TracksControllerTest extends \PHPUnit\Framework\TestCase {
- private $appName;
- private $request;
- private $contacts;
-
- private $container;
- private $config;
- private $app;
-
- private $tracksController;
- private $tracksController2;
- private $utilsController;
-
- private $tracksService;
-
- public static function setUpBeforeClass(): void {
- $app = new Application();
- $c = $app->getContainer();
-
- $user = $c->getServer()->getUserManager()->get('test');
- $user2 = $c->getServer()->getUserManager()->get('test2');
- $user3 = $c->getServer()->getUserManager()->get('test3');
- $group = $c->getServer()->getGroupManager()->get('group1test');
- $group2 = $c->getServer()->getGroupManager()->get('group2test');
-
- // CREATE DUMMY USERS
- if ($user === null) {
- $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
- $u1->setEMailAddress('toto@toto.net');
- }
- if ($user2 === null) {
- $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
- }
- if ($user2 === null) {
- $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
- }
- if ($group === null) {
- $c->getServer()->getGroupManager()->createGroup('group1test');
- $u1 = $c->getServer()->getUserManager()->get('test');
- $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
- }
- if ($group2 === null) {
- $c->getServer()->getGroupManager()->createGroup('group2test');
- $u2 = $c->getServer()->getUserManager()->get('test2');
- $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
- }
- }
-
- protected function setUp(): void {
- $this->appName = 'maps';
- $this->request = $this->getMockBuilder('\OCP\IRequest')
- ->disableOriginalConstructor()
- ->getMock();
- $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->app = new Application();
- $this->container = $this->app->getContainer();
- $c = $this->container;
- $this->config = $c->query(IServerContainer::class)->getConfig();
-
- $this->rootFolder = $c->query(IServerContainer::class)->getRootFolder();
-
- $this->tracksService = new TracksService(
- $c->query(IServerContainer::class)->getLogger(),
- $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
- $this->rootFolder,
- $c->query(IServerContainer::class)->getShareManager(),
- $c->query(IServerContainer::class)->query(\OCP\IDBConnection::class)
- );
-
- $this->tracksController = new TracksController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class),
- $c->query(IServerContainer::class)->getConfig(),
- $c->query(IServerContainer::class)->getShareManager(),
- $c->getServer()->getAppManager(),
- $c->getServer()->getUserManager(),
- $c->getServer()->getGroupManager(),
- $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
- $c->query(IServerContainer::class)->getLogger(),
- $c->query(TracksService::class),
- 'test',
- );
-
- $this->tracksController2 = new TracksController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class),
- $c->query(IServerContainer::class)->getConfig(),
- $c->query(IServerContainer::class)->getShareManager(),
- $c->getServer()->getAppManager(),
- $c->getServer()->getUserManager(),
- $c->getServer()->getGroupManager(),
- $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
- $c->query(IServerContainer::class)->getLogger(),
- $c->query(TracksService::class),
- 'test2',
- );
-
- $this->utilsController = new UtilsController(
- $this->appName,
- $this->request,
- $c->query(IServerContainer::class)->getConfig(),
- $c->getServer()->getAppManager(),
+ private $appName;
+ private $request;
+ private $contacts;
+
+ private $container;
+ private $config;
+ private $app;
+
+ private $tracksController;
+ private $tracksController2;
+ private $utilsController;
+
+ private $tracksService;
+
+ public static function setUpBeforeClass(): void {
+ $app = new Application();
+ $c = $app->getContainer();
+
+ $user = $c->getServer()->getUserManager()->get('test');
+ $user2 = $c->getServer()->getUserManager()->get('test2');
+ $user3 = $c->getServer()->getUserManager()->get('test3');
+ $group = $c->getServer()->getGroupManager()->get('group1test');
+ $group2 = $c->getServer()->getGroupManager()->get('group2test');
+
+ // CREATE DUMMY USERS
+ if ($user === null) {
+ $u1 = $c->getServer()->getUserManager()->createUser('test', 'tatotitoTUTU');
+ $u1->setEMailAddress('toto@toto.net');
+ }
+ if ($user2 === null) {
+ $u2 = $c->getServer()->getUserManager()->createUser('test2', 'plopinoulala000');
+ }
+ if ($user2 === null) {
+ $u3 = $c->getServer()->getUserManager()->createUser('test3', 'yeyeahPASSPASS');
+ }
+ if ($group === null) {
+ $c->getServer()->getGroupManager()->createGroup('group1test');
+ $u1 = $c->getServer()->getUserManager()->get('test');
+ $c->getServer()->getGroupManager()->get('group1test')->addUser($u1);
+ }
+ if ($group2 === null) {
+ $c->getServer()->getGroupManager()->createGroup('group2test');
+ $u2 = $c->getServer()->getUserManager()->get('test2');
+ $c->getServer()->getGroupManager()->get('group2test')->addUser($u2);
+ }
+ }
+
+ protected function setUp(): void {
+ $this->appName = 'maps';
+ $this->request = $this->getMockBuilder('\OCP\IRequest')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->contacts = $this->getMockBuilder('OCP\Contacts\IManager')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->app = new Application();
+ $this->container = $this->app->getContainer();
+ $c = $this->container;
+ $this->config = $c->query(IServerContainer::class)->getConfig();
+
+ $this->rootFolder = $c->query(IServerContainer::class)->getRootFolder();
+
+ $this->tracksService = new TracksService(
+ $c->query(IServerContainer::class)->getLogger(),
+ $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
+ $this->rootFolder,
+ $c->query(IServerContainer::class)->getShareManager(),
+ $c->query(IServerContainer::class)->query(\OCP\IDBConnection::class)
+ );
+
+ $this->tracksController = new TracksController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class),
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->query(IServerContainer::class)->getShareManager(),
+ $c->getServer()->getAppManager(),
+ $c->getServer()->getUserManager(),
+ $c->getServer()->getGroupManager(),
+ $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
+ $c->query(IServerContainer::class)->getLogger(),
+ $c->query(TracksService::class),
+ 'test',
+ );
+
+ $this->tracksController2 = new TracksController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class),
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->query(IServerContainer::class)->getShareManager(),
+ $c->getServer()->getAppManager(),
+ $c->getServer()->getUserManager(),
+ $c->getServer()->getGroupManager(),
+ $c->query(IServerContainer::class)->getL10N($c->query('AppName')),
+ $c->query(IServerContainer::class)->getLogger(),
+ $c->query(TracksService::class),
+ 'test2',
+ );
+
+ $this->utilsController = new UtilsController(
+ $this->appName,
+ $this->request,
+ $c->query(IServerContainer::class)->getConfig(),
+ $c->getServer()->getAppManager(),
$this->rootFolder,
- 'test'
- );
-
- $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
-
- // delete first
- if ($userfolder->nodeExists('testFile1.gpx')) {
- //echo "DELETE\n";
- $file = $userfolder->get('testFile1.gpx');
- $file->delete();
- }
- // delete db
- $qb = $c->query(IServerContainer::class)->query(\OCP\IDBConnection::class)->getQueryBuilder();
- $qb->delete('maps_tracks')
- ->where(
- $qb->expr()->eq('user_id', $qb->createNamedParameter('test', IQueryBuilder::PARAM_STR))
- );
- $req = $qb->execute();
- $qb = $qb->resetQueryParts();
- }
-
- public static function tearDownAfterClass(): void {
- //$app = new Application();
- //$c = $app->getContainer();
- //$user = $c->getServer()->getUserManager()->get('test');
- //$user->delete();
- //$user = $c->getServer()->getUserManager()->get('test2');
- //$user->delete();
- //$user = $c->getServer()->getUserManager()->get('test3');
- //$user->delete();
- //$c->getServer()->getGroupManager()->get('group1test')->delete();
- //$c->getServer()->getGroupManager()->get('group2test')->delete();
- }
-
- protected function tearDown(): void {
- // in case there was a failure and something was not deleted
- $c = $this->app->getContainer();
-
- $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
- // delete files
- if ($userfolder->nodeExists('testFile1.gpx')) {
- $file = $userfolder->get('testFile1.gpx');
- $file->delete();
- }
- // delete db
- $qb = $c->query(IServerContainer::class)->query(\OCP\IDBConnection::class)->getQueryBuilder();
- $qb->delete('maps_tracks')
- ->where(
- $qb->expr()->eq('user_id', $qb->createNamedParameter('test', IQueryBuilder::PARAM_STR))
- );
- $req = $qb->execute();
- $qb = $qb->resetQueryParts();
- }
-
- public function testAddGetTracks() {
- $c = $this->app->getContainer();
-
- $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
-
- $filename = 'tests/test_files/testFile1.gpx';
- $content1 = file_get_contents($filename);
- $file = $userfolder->newFile('testFile1.gpxx');
- $file->putContent($content1);
- //$file->touch();
-
- $file = $userfolder->get('testFile1.gpxx');
- $file->move($userfolder->getPath().'/testFile1.gpx');
- //echo 'I MOVE TO '.$userfolder->getPath().'/testFile1.gpx'."\n";
- $file = $userfolder->get('testFile1.gpx');
- $file->touch();
-
- $resp = $this->tracksController->getTracks();
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $foundTestFile = false;
- foreach ($data as $k => $v) {
- if ($v['file_path'] === '/testFile1.gpx') {
- $foundTestFile = true;
- break;
- }
- }
- $this->assertEquals(true, count($data) > 0);
- $this->assertEquals(true, $foundTestFile);
-
- foreach ($this->tracksService->rescan('test') as $path) {
- //echo $path."\n";
- }
-
- $resp = $this->tracksController->getTracks();
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $foundTestFile = false;
- //var_dump($data);
- $trackId = null;
- foreach ($data as $k => $v) {
- if ($v['file_path'] === '/testFile1.gpx') {
- $foundTestFile = true;
- $trackId = $v['id'];
- $this->assertEquals(true, $v['color'] === null);
- break;
- }
- }
- $this->assertEquals(true, count($data) > 0);
- $this->assertEquals(true, $foundTestFile);
-
- // track content
- $resp = $this->tracksController->getTrackFileContent($trackId);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals(true, $content1 === $data['content']);
- $meta = $data['metadata'];
- $this->assertEquals(true, strlen($meta) > 0);
-
- // to get stored metadata
- $resp = $this->tracksController->getTrackFileContent($trackId);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals(true, $content1 === $data['content']);
- $this->assertEquals(true, $meta === $data['metadata']);
-
- // file that does not exist
- $resp = $this->tracksController->getTrackFileContent(0);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('File not found', $data);
-
- // edit track
- $resp = $this->tracksController->editTrack($trackId, '#002244', null, null);
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $this->assertEquals('EDITED', $data);
-
- // check new color
- $resp = $this->tracksController->getTracks();
- $status = $resp->getStatus();
- $this->assertEquals(200, $status);
- $data = $resp->getData();
- $foundTestFile = false;
- foreach ($data as $k => $v) {
- if ($v['file_path'] === '/testFile1.gpx') {
- $foundTestFile = true;
- $this->assertEquals(true, $v['color'] === '#002244');
- break;
- }
- }
- $this->assertEquals(true, count($data) > 0);
- $this->assertEquals(true, $foundTestFile);
-
- // edit track that does not exist
- $resp = $this->tracksController->editTrack(0, '#002244', null, null);
- $status = $resp->getStatus();
- $this->assertEquals(400, $status);
- $data = $resp->getData();
- $this->assertEquals('No such track', $data);
- }
+ 'test'
+ );
+
+ $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
+
+ // delete first
+ if ($userfolder->nodeExists('testFile1.gpx')) {
+ //echo "DELETE\n";
+ $file = $userfolder->get('testFile1.gpx');
+ $file->delete();
+ }
+ // delete db
+ $qb = $c->query(IServerContainer::class)->query(\OCP\IDBConnection::class)->getQueryBuilder();
+ $qb->delete('maps_tracks')
+ ->where(
+ $qb->expr()->eq('user_id', $qb->createNamedParameter('test', IQueryBuilder::PARAM_STR))
+ );
+ $req = $qb->execute();
+ $qb = $qb->resetQueryParts();
+ }
+
+ public static function tearDownAfterClass(): void {
+ //$app = new Application();
+ //$c = $app->getContainer();
+ //$user = $c->getServer()->getUserManager()->get('test');
+ //$user->delete();
+ //$user = $c->getServer()->getUserManager()->get('test2');
+ //$user->delete();
+ //$user = $c->getServer()->getUserManager()->get('test3');
+ //$user->delete();
+ //$c->getServer()->getGroupManager()->get('group1test')->delete();
+ //$c->getServer()->getGroupManager()->get('group2test')->delete();
+ }
+
+ protected function tearDown(): void {
+ // in case there was a failure and something was not deleted
+ $c = $this->app->getContainer();
+
+ $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
+ // delete files
+ if ($userfolder->nodeExists('testFile1.gpx')) {
+ $file = $userfolder->get('testFile1.gpx');
+ $file->delete();
+ }
+ // delete db
+ $qb = $c->query(IServerContainer::class)->query(\OCP\IDBConnection::class)->getQueryBuilder();
+ $qb->delete('maps_tracks')
+ ->where(
+ $qb->expr()->eq('user_id', $qb->createNamedParameter('test', IQueryBuilder::PARAM_STR))
+ );
+ $req = $qb->execute();
+ $qb = $qb->resetQueryParts();
+ }
+
+ public function testAddGetTracks() {
+ $c = $this->app->getContainer();
+
+ $userfolder = $this->container->query(IServerContainer::class)->getUserFolder('test');
+
+ $filename = 'tests/test_files/testFile1.gpx';
+ $content1 = file_get_contents($filename);
+ $file = $userfolder->newFile('testFile1.gpxx');
+ $file->putContent($content1);
+ //$file->touch();
+
+ $file = $userfolder->get('testFile1.gpxx');
+ $file->move($userfolder->getPath().'/testFile1.gpx');
+ //echo 'I MOVE TO '.$userfolder->getPath().'/testFile1.gpx'."\n";
+ $file = $userfolder->get('testFile1.gpx');
+ $file->touch();
+
+ $resp = $this->tracksController->getTracks();
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $foundTestFile = false;
+ foreach ($data as $k => $v) {
+ if ($v['file_path'] === '/testFile1.gpx') {
+ $foundTestFile = true;
+ break;
+ }
+ }
+ $this->assertEquals(true, count($data) > 0);
+ $this->assertEquals(true, $foundTestFile);
+
+ foreach ($this->tracksService->rescan('test') as $path) {
+ //echo $path."\n";
+ }
+
+ $resp = $this->tracksController->getTracks();
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $foundTestFile = false;
+ //var_dump($data);
+ $trackId = null;
+ foreach ($data as $k => $v) {
+ if ($v['file_path'] === '/testFile1.gpx') {
+ $foundTestFile = true;
+ $trackId = $v['id'];
+ $this->assertEquals(true, $v['color'] === null);
+ break;
+ }
+ }
+ $this->assertEquals(true, count($data) > 0);
+ $this->assertEquals(true, $foundTestFile);
+
+ // track content
+ $resp = $this->tracksController->getTrackFileContent($trackId);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals(true, $content1 === $data['content']);
+ $meta = $data['metadata'];
+ $this->assertEquals(true, strlen($meta) > 0);
+
+ // to get stored metadata
+ $resp = $this->tracksController->getTrackFileContent($trackId);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals(true, $content1 === $data['content']);
+ $this->assertEquals(true, $meta === $data['metadata']);
+
+ // file that does not exist
+ $resp = $this->tracksController->getTrackFileContent(0);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('File not found', $data);
+
+ // edit track
+ $resp = $this->tracksController->editTrack($trackId, '#002244', null, null);
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $this->assertEquals('EDITED', $data);
+
+ // check new color
+ $resp = $this->tracksController->getTracks();
+ $status = $resp->getStatus();
+ $this->assertEquals(200, $status);
+ $data = $resp->getData();
+ $foundTestFile = false;
+ foreach ($data as $k => $v) {
+ if ($v['file_path'] === '/testFile1.gpx') {
+ $foundTestFile = true;
+ $this->assertEquals(true, $v['color'] === '#002244');
+ break;
+ }
+ }
+ $this->assertEquals(true, count($data) > 0);
+ $this->assertEquals(true, $foundTestFile);
+
+ // edit track that does not exist
+ $resp = $this->tracksController->editTrack(0, '#002244', null, null);
+ $status = $resp->getStatus();
+ $this->assertEquals(400, $status);
+ $data = $resp->getData();
+ $this->assertEquals('No such track', $data);
+ }
}
diff --git a/tests/Unit/Helper/ExifGeoDataTest.php b/tests/Unit/Helper/ExifGeoDataTest.php
index 3a31c9f18..46d66d498 100644
--- a/tests/Unit/Helper/ExifGeoDataTest.php
+++ b/tests/Unit/Helper/ExifGeoDataTest.php
@@ -3,45 +3,43 @@
namespace OCA\Maps\Helper;
use PHPUnit\Framework\TestCase;
-use OCA\Maps\Helper\ExifGeoData;
-use OCA\Maps\Helper\ExifDataNoLocationException;
class ExifGeoDataTest extends TestCase {
public function imageWithDateAndLocationProvider(): array {
return [
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation1.JPG", 1311984000 + 7200, 47.071717, 10.339557],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation2.JPG", 1312156800 + 7200, 46.862350, 10.916452],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation3.JPG", 1312070400 + 7200, 47.069058, 10.329370],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation4.JPG", 1312070400 + 7200, 47.059160, 10.312354],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation5.JPG", 1568101093 + 7200, 47.357735, 11.177585],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation6.JPG", 1577630208 + 3600, 50.083045, 9.986018],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation7.jpg", 1568999599 + 7200, 49.420833, 11.114444],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation8.JPG", 1501431401 + 7200, 45.306983, 10.700902],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation9.JPG", 1302998400 + 7200, 52.363055, 4.903418],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation10.JPG", 1501238375 + 7200, 46.388742, 11.266598],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation11.JPG", 1501567361 + 7200, 44.827830, 10.956387],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation12.JPG", 1501591333 + 7200, 44.528283, 11.262207],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation13.jpg", 1640083235 + 3600, 54.359561, 10.017325],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation14.jpg", 1559327910 + 7200, 52.976844, 12.988281],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation15.jpg", 1559332394 + 7200, 52.983697, 12.935217],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation16.jpeg", 1593458542 + 7200, 62.733947, 6.779617],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation17.jpeg", 1593458620 + 7200, 62.733769, 6.777794],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation18.jpeg", 1596136867 + 7200, 54.350891, 9.903506],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation19.jpeg", 1596136833 + 7200, 54.350894, 9.903505],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation20.jpeg", 1592913150 + 7200, 61.351753, 6.519107],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation21.jpg", 1653565075 + 7200, 48.704331, 8.418475],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation22.jpeg", 1593890841 + 7200, 62.735419, 7.155311],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation23.jpeg", 1592904886 + 7200, 61.217086, 6.558886],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation24.jpeg", 1592677991 + 7200, 60.427481, 6.548446],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation25.jpeg", 1592650395 + 7200, 59.860523, 6.696346],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation26.jpeg", 1592770386 + 7200, 60.594022, 6.581317],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation27.jpeg", 1592654095 + 7200, 60.033561, 6.563068],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation28.jpg", 1595326357 + 7200, 59.852992, 6.714458],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation29.jpg", 1594918175 + 7200, 57.595925, 9.976864],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation30.jpg", 1595418724 + 7200, 60.669492, 6.807386],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation31.jpg", 1594934141 + 7200, 57.801164, 8.314269],
- ["tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation32.jpeg", 1595629060 + 7200, 59.598981, 9.677297],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation1.JPG', 1311984000 + 7200, 47.071717, 10.339557],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation2.JPG', 1312156800 + 7200, 46.862350, 10.916452],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation3.JPG', 1312070400 + 7200, 47.069058, 10.329370],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation4.JPG', 1312070400 + 7200, 47.059160, 10.312354],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation5.JPG', 1568101093 + 7200, 47.357735, 11.177585],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation6.JPG', 1577630208 + 3600, 50.083045, 9.986018],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation7.jpg', 1568999599 + 7200, 49.420833, 11.114444],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation8.JPG', 1501431401 + 7200, 45.306983, 10.700902],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation9.JPG', 1302998400 + 7200, 52.363055, 4.903418],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation10.JPG', 1501238375 + 7200, 46.388742, 11.266598],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation11.JPG', 1501567361 + 7200, 44.827830, 10.956387],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation12.JPG', 1501591333 + 7200, 44.528283, 11.262207],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation13.jpg', 1640083235 + 3600, 54.359561, 10.017325],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation14.jpg', 1559327910 + 7200, 52.976844, 12.988281],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation15.jpg', 1559332394 + 7200, 52.983697, 12.935217],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation16.jpeg', 1593458542 + 7200, 62.733947, 6.779617],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation17.jpeg', 1593458620 + 7200, 62.733769, 6.777794],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation18.jpeg', 1596136867 + 7200, 54.350891, 9.903506],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation19.jpeg', 1596136833 + 7200, 54.350894, 9.903505],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation20.jpeg', 1592913150 + 7200, 61.351753, 6.519107],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation21.jpg', 1653565075 + 7200, 48.704331, 8.418475],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation22.jpeg', 1593890841 + 7200, 62.735419, 7.155311],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation23.jpeg', 1592904886 + 7200, 61.217086, 6.558886],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation24.jpeg', 1592677991 + 7200, 60.427481, 6.548446],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation25.jpeg', 1592650395 + 7200, 59.860523, 6.696346],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation26.jpeg', 1592770386 + 7200, 60.594022, 6.581317],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation27.jpeg', 1592654095 + 7200, 60.033561, 6.563068],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation28.jpg', 1595326357 + 7200, 59.852992, 6.714458],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation29.jpg', 1594918175 + 7200, 57.595925, 9.976864],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation30.jpg', 1595418724 + 7200, 60.669492, 6.807386],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation31.jpg', 1594934141 + 7200, 57.801164, 8.314269],
+ ['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation32.jpeg', 1595629060 + 7200, 59.598981, 9.677297],
];
}
/**
@@ -52,13 +50,13 @@ public function testImagesWithDateAndLocation(string $path, int $date, float $la
$exif_geo_data->validate(true);
$this->assertEquals($date, $exif_geo_data->dateTaken);
//This is the same upto ~55cm
- $this->assertEqualsWithDelta($lat, $exif_geo_data->lat, 0.000005);
+ $this->assertEqualsWithDelta($lat, $exif_geo_data->lat, 0.000005);
$this->assertEqualsWithDelta($lng, $exif_geo_data->lng, 0.000005);
}
public function imageWithZeroIslandProvider(): array {
return [
- ["tests/test_files/Photos/ZeroIsland/imageZeroIsland1.JPG", 1653829180 + 7200],
+ ['tests/test_files/Photos/ZeroIsland/imageZeroIsland1.JPG', 1653829180 + 7200],
];
}
/**
@@ -66,7 +64,7 @@ public function imageWithZeroIslandProvider(): array {
*/
public function testImagesWithZeroIslandException(string $path, int $date) {
$this->expectException(ExifDataNoLocationException::class);
- $this->expectExceptionMessage("Zero island is not valid");
+ $this->expectExceptionMessage('Zero island is not valid');
$exif_geo_data = ExifGeoData::get($path);
$exif_geo_data->validate(true);
}
@@ -78,11 +76,11 @@ public function testImagesWithZeroIslandGeoDataNull(string $path, int $date) {
$exif_geo_data = ExifGeoData::get($path);
try {
$exif_geo_data->validate(true);
- $this->assertEquals(true,false);
+ $this->assertEquals(true, false);
} catch (ExifDataNoLocationException $e) {
$this->assertEquals($date, $exif_geo_data->dateTaken);
//This is the same upto ~55cm
- $this->assertEqualsWithDelta(null, $exif_geo_data->lat, 0.000005);
+ $this->assertEqualsWithDelta(null, $exif_geo_data->lat, 0.000005);
$this->assertEqualsWithDelta(null, $exif_geo_data->lng, 0.000005);
}
}
@@ -95,7 +93,7 @@ public function testImagesWithZeroIsland(string $path, int $date) {
$exif_geo_data->validate(false);
$this->assertEquals($date, $exif_geo_data->dateTaken);
//This is the same upto ~55cm
- $this->assertEqualsWithDelta(0.0, $exif_geo_data->lat, 0.000005);
+ $this->assertEqualsWithDelta(0.0, $exif_geo_data->lat, 0.000005);
$this->assertEqualsWithDelta(0.0, $exif_geo_data->lng, 0.000005);
}
}
diff --git a/vendor-bin/csfixer/composer.json b/vendor-bin/csfixer/composer.json
new file mode 100644
index 000000000..b67bf1232
--- /dev/null
+++ b/vendor-bin/csfixer/composer.json
@@ -0,0 +1,5 @@
+{
+ "require-dev": {
+ "nextcloud/coding-standard": "^1.2"
+ }
+}
diff --git a/vendor-bin/csfixer/composer.lock b/vendor-bin/csfixer/composer.lock
new file mode 100644
index 000000000..16ba6bc41
--- /dev/null
+++ b/vendor-bin/csfixer/composer.lock
@@ -0,0 +1,112 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
+ "This file is @generated automatically"
+ ],
+ "content-hash": "70f2afb9bd1323f4225d93d6183f384f",
+ "packages": [],
+ "packages-dev": [
+ {
+ "name": "nextcloud/coding-standard",
+ "version": "v1.2.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/nextcloud/coding-standard.git",
+ "reference": "bc9c53a5306114b60c4363057aff9c2ed10a54da"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/bc9c53a5306114b60c4363057aff9c2ed10a54da",
+ "reference": "bc9c53a5306114b60c4363057aff9c2ed10a54da",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.3|^8.0",
+ "php-cs-fixer/shim": "^3.17"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Nextcloud\\CodingStandard\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Christoph Wurst",
+ "email": "christoph@winzerhof-wurst.at"
+ }
+ ],
+ "description": "Nextcloud coding standards for the php cs fixer",
+ "support": {
+ "issues": "https://github.com/nextcloud/coding-standard/issues",
+ "source": "https://github.com/nextcloud/coding-standard/tree/v1.2.3"
+ },
+ "time": "2024-08-23T14:32:32+00:00"
+ },
+ {
+ "name": "php-cs-fixer/shim",
+ "version": "v3.64.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/PHP-CS-Fixer/shim.git",
+ "reference": "81ccfd24baf3a10810dab1152c403981a790b837"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/81ccfd24baf3a10810dab1152c403981a790b837",
+ "reference": "81ccfd24baf3a10810dab1152c403981a790b837",
+ "shasum": ""
+ },
+ "require": {
+ "ext-json": "*",
+ "ext-tokenizer": "*",
+ "php": "^7.4 || ^8.0"
+ },
+ "replace": {
+ "friendsofphp/php-cs-fixer": "self.version"
+ },
+ "suggest": {
+ "ext-dom": "For handling output formats in XML",
+ "ext-mbstring": "For handling non-UTF8 characters."
+ },
+ "bin": [
+ "php-cs-fixer",
+ "php-cs-fixer.phar"
+ ],
+ "type": "application",
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Dariusz RumiĆski",
+ "email": "dariusz.ruminski@gmail.com"
+ }
+ ],
+ "description": "A tool to automatically fix PHP code style",
+ "support": {
+ "issues": "https://github.com/PHP-CS-Fixer/shim/issues",
+ "source": "https://github.com/PHP-CS-Fixer/shim/tree/v3.64.0"
+ },
+ "time": "2024-08-30T23:10:11+00:00"
+ }
+ ],
+ "aliases": [],
+ "minimum-stability": "stable",
+ "stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": [],
+ "platform-dev": [],
+ "plugin-api-version": "2.6.0"
+}