-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Julien Veyssier
committed
Mar 31, 2019
1 parent
268b1fd
commit 4bc4ec3
Showing
5 changed files
with
200 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
<phpunit bootstrap="tests/bootstrap.php" colors="true"> | ||
<testsuites> | ||
<testsuite name="unit"> | ||
<directory>./tests/Unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">lib</directory> | ||
<exclude> | ||
<directory suffix=".php">appinfo</directory> | ||
<directory suffix=".php">templates</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
<testsuites> | ||
<testsuite name="unit"> | ||
<directory>./tests/Unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
|
||
namespace OCA\Maps\Controller; | ||
|
||
use \OCA\Cospend\AppInfo\Application; | ||
use \OCA\Maps\Service\FavoritesService; | ||
use OCP\AppFramework\Http\TemplateResponse; | ||
|
||
|
||
class FavoriteControllerTest extends \PHPUnit\Framework\TestCase { | ||
private $appName; | ||
private $request; | ||
private $contacts; | ||
|
||
private $container; | ||
private $config; | ||
private $app; | ||
|
||
private $pageController; | ||
private $pageController2; | ||
private $utilsController; | ||
|
||
public static function setUpBeforeClass() { | ||
$app = new Application(); | ||
$c = $app->getContainer(); | ||
|
||
// clear test users | ||
$user = $c->getServer()->getUserManager()->get('test'); | ||
if ($user !== null) { | ||
$user->delete(); | ||
} | ||
$user = $c->getServer()->getUserManager()->get('test2'); | ||
if ($user !== null) { | ||
$user->delete(); | ||
} | ||
$user = $c->getServer()->getUserManager()->get('test3'); | ||
if ($user !== null) { | ||
$user->delete(); | ||
} | ||
|
||
// CREATE DUMMY USERS | ||
$u1 = $c->getServer()->getUserManager()->createUser('test', 'T0T0T0'); | ||
$u1->setEMailAddress('[email protected]'); | ||
$u2 = $c->getServer()->getUserManager()->createUser('test2', 'T0T0T0'); | ||
$u3 = $c->getServer()->getUserManager()->createUser('test3', 'T0T0T0'); | ||
$c->getServer()->getGroupManager()->createGroup('group1test'); | ||
$c->getServer()->getGroupManager()->get('group1test')->addUser($u1); | ||
$c->getServer()->getGroupManager()->createGroup('group2test'); | ||
$c->getServer()->getGroupManager()->get('group2test')->addUser($u2); | ||
} | ||
|
||
public function setUp() { | ||
$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('ServerContainer')->getConfig(); | ||
|
||
$this->favoritesController = new FavoritesController( | ||
$this->appName, | ||
$this->request, | ||
'test', | ||
$c->query('ServerContainer')->getUserFolder('test'), | ||
$c->query('ServerContainer')->getConfig(), | ||
$c->getServer()->getShareManager(), | ||
$c->getServer()->getAppManager(), | ||
$c->getServer()->getUserManager(), | ||
$c->getServer()->getGroupManager(), | ||
$c->query('ServerContainer')->getL10N($c->query('AppName')), | ||
$c->query('ServerContainer')->getLogger(), | ||
new FavoritesService( | ||
$c->query('ServerContainer')->getLogger(), | ||
$c->query('ServerContainer')->getL10N($c->query('AppName')) | ||
) | ||
); | ||
|
||
$this->favoritesController2 = new FavoritesController( | ||
$this->appName, | ||
$this->request, | ||
'test2', | ||
$c->query('ServerContainer')->getUserFolder('test2'), | ||
$c->query('ServerContainer')->getConfig(), | ||
$c->getServer()->getShareManager(), | ||
$c->getServer()->getAppManager(), | ||
$c->getServer()->getUserManager(), | ||
$c->getServer()->getGroupManager(), | ||
$c->query('ServerContainer')->getL10N($c->query('AppName')), | ||
$c->query('ServerContainer')->getLogger(), | ||
new FavoritesService( | ||
$c->query('ServerContainer')->getLogger(), | ||
$c->query('ServerContainer')->getL10N($c->query('AppName')) | ||
) | ||
); | ||
|
||
$this->utilsController = new UtilsController( | ||
$this->appName, | ||
$this->request, | ||
'test', | ||
$c->query('ServerContainer')->getUserFolder('test'), | ||
$c->query('ServerContainer')->getConfig(), | ||
$c->getServer()->getAppManager() | ||
); | ||
} | ||
|
||
public static function tearDownAfterClass() { | ||
$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(); | ||
} | ||
|
||
public function tearDown() { | ||
// in case there was a failure and something was not deleted | ||
} | ||
|
||
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']); | ||
|
||
// invalid values | ||
$resp = $this->favoritesController->addFavorite('', 3.1, 4.2, '', null, null); | ||
$status = $resp->getStatus(); | ||
$this->assertEquals(400, $status); | ||
|
||
$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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
<?php | ||
|
||
namespace OCA\Maps\Tests\Unit\Controller; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
namespace OCA\Maps\Controller; | ||
|
||
use OCP\AppFramework\Http\TemplateResponse; | ||
|
||
|
||
class PageControllerTest extends PHPUnit_Framework_TestCase { | ||
private $controller; | ||
private $userId = 'john'; | ||
class PageControllerTest extends \PHPUnit\Framework\TestCase { | ||
private $controller; | ||
private $userId = 'john'; | ||
|
||
public function setUp() { | ||
$request = $this->getMockBuilder('OCP\IRequest')->getMock(); | ||
public function setUp() { | ||
$request = $this->getMockBuilder('OCP\IRequest')->getMock(); | ||
|
||
$this->controller = new PageController( | ||
'maps', $request, $this->userId | ||
); | ||
} | ||
$this->controller = new PageController( | ||
'maps', $request, $this->userId | ||
); | ||
} | ||
|
||
public function testIndex() { | ||
$result = $this->controller->index(); | ||
public function testIndex() { | ||
$result = $this->controller->index(); | ||
|
||
$this->assertEquals('index', $result->getTemplateName()); | ||
$this->assertTrue($result instanceof TemplateResponse); | ||
} | ||
$this->assertEquals('index', $result->getTemplateName()); | ||
$this->assertTrue($result instanceof TemplateResponse); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
<?php | ||
/** | ||
* Nextcloud - maps | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
*/ | ||
define('PHPUNIT_RUN', 1); | ||
|
||
if (!defined('PHPUNIT_RUN')) { | ||
define('PHPUNIT_RUN', 1); | ||
} | ||
// ugly hack to fix issues with template code using static code | ||
$_SERVER['REQUEST_URI'] = '/index.php/apps/maps/'; | ||
$_SERVER['SCRIPT_NAME'] = '/index.php'; | ||
|
||
require_once __DIR__.'/../../../lib/base.php'; | ||
|
||
// Fix for "Autoload path not allowed: .../tests/lib/testcase.php" | ||
\OC::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); | ||
|
||
// Fix for "Autoload path not allowed: .../maps/tests/testcase.php" | ||
\OC_App::loadApp('maps'); | ||
|
||
if(!class_exists('PHPUnit_Framework_TestCase')) { | ||
require_once('PHPUnit/Autoload.php'); | ||
if (version_compare(implode('.', \OCP\Util::getVersion()), '8.2', '>=')) { | ||
\OC::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); | ||
\OC_App::loadApp('maps'); | ||
} | ||
|
||
//if(!class_exists('PHPUnit_Framework_TestCase')) { | ||
// require_once('PHPUnit/Autoload.php'); | ||
//} | ||
|
||
OC_Hook::clear(); |