fix import for integration tests
This commit is contained in:
parent
a2232bbd25
commit
a8ddf748a7
|
@ -1,3 +1,6 @@
|
|||
owncloud-news (6.0.5)
|
||||
* **Enhancement**: Add user information API route
|
||||
|
||||
owncloud-news (6.0.4)
|
||||
* **Bugfix**: Allow YouTube videos to go fullscreen, #857
|
||||
* **Enhancement**: Group plugins in menu, #718
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -59,6 +59,8 @@ return ['routes' => [
|
|||
['name' => 'export#articles', 'url' => '/export/articles', 'verb' => 'GET'],
|
||||
|
||||
// API 1.2
|
||||
['name' => 'user_api#index', 'url' => '/api/v1-2/user', 'verb' => 'GET'],
|
||||
['name' => 'user_api#avatar', 'url' => '/api/v1-2/user/avatar', 'verb' => 'GET'],
|
||||
['name' => 'utility_api#version', 'url' => '/api/v1-2/version', 'verb' => 'GET'],
|
||||
['name' => 'utility_api#status', 'url' => '/api/v1-2/status', 'verb' => 'GET'],
|
||||
['name' => 'utility_api#before_update', 'url' => '/api/v1-2/cleanup/before-update', 'verb' => 'GET'],
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - News
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Alessandro Cosentino <cosenal@gmail.com>
|
||||
* @author Bernhard Posselt <dev@bernhard-posselt.com>
|
||||
* @copyright Alessandro Cosentino 2012
|
||||
* @copyright Bernhard Posselt 2012, 2014
|
||||
*/
|
||||
|
||||
namespace OCA\News\Controller;
|
||||
|
||||
use \OCP\IRequest;
|
||||
use \OCP\IUserSession;
|
||||
use \OCP\IURLGenerator;
|
||||
use \OCP\Files\IRootFolder;
|
||||
use \OCP\AppFramework\ApiController;
|
||||
use \OCP\AppFramework\Http;
|
||||
|
||||
class UserApiController extends ApiController {
|
||||
|
||||
private $userSession;
|
||||
private $rootFolder;
|
||||
|
||||
public function __construct($AppName,
|
||||
IRequest $request,
|
||||
IUserSession $userSession,
|
||||
IRootFolder $rootFolder){
|
||||
parent::__construct($AppName, $request);
|
||||
$this->userSession = $userSession;
|
||||
$this->rootFolder = $rootFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
* @CORS
|
||||
*/
|
||||
public function index() {
|
||||
$user = $this->userSession->getUser();
|
||||
|
||||
// find the avatar
|
||||
$jpgAvatar = '/' . $user->getUID() . '/avatar.jpg';
|
||||
$pngAvatar = '/' . $user->getUID() . '/avatar.png';
|
||||
$avatar = null;
|
||||
|
||||
if ($this->rootFolder->nodeExists($jpgAvatar)) {
|
||||
$file = $this->rootFolder->get($jpgAvatar);
|
||||
$avatar = [
|
||||
'data' => base64_encode($file->getContent()),
|
||||
'mime' => 'image/jpeg'
|
||||
];
|
||||
} elseif ($this->rootFolder->nodeExists($pngAvatar)) {
|
||||
$file = $this->rootFolder->get($pngAvatar);
|
||||
$avatar = [
|
||||
'data' => base64_encode($file->getContent()),
|
||||
'mime' => 'image/png'
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'userId' => $user->getUID(),
|
||||
'displayName' => $user->getDisplayName(),
|
||||
'lastLoginTimestamp' => $user->getLastLogin(),
|
||||
'avatar' => $avatar
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
<phpunit bootstrap="tests/classloader.php">
|
||||
<phpunit bootstrap="tests/bootstrap.php">
|
||||
<testsuites>
|
||||
<testsuite name="unit">
|
||||
<directory>./tests/unit</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
</phpunit>
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - News
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Bernhard Posselt <dev@bernhard-posselt.com>
|
||||
* @copyright Bernhard Posselt 2012, 2014
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../../tests/bootstrap.php';
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - News
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Alessandro Cosentino <cosenal@gmail.com>
|
||||
* @author Bernhard Posselt <dev@bernhard-posselt.com>
|
||||
* @copyright Alessandro Cosentino 2012
|
||||
* @copyright Bernhard Posselt 2012, 2014
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// to execute without owncloud, we need to create our own classloader
|
||||
spl_autoload_register(function ($className){
|
||||
if (strpos($className, 'OCA\\') === 0) {
|
||||
|
||||
$path = strtolower(
|
||||
str_replace('\\', '/', substr($className, 3)) . '.php'
|
||||
);
|
||||
$relPath = __DIR__ . '/../..' . $path;
|
||||
|
||||
if(file_exists($relPath)){
|
||||
require_once $relPath;
|
||||
}
|
||||
} else if(strpos($className, 'OCP\\') === 0) {
|
||||
$path = strtolower(
|
||||
str_replace('\\', '/', substr($className, 3)) . '.php'
|
||||
);
|
||||
$relPath = __DIR__ . '/../../../lib/public' . $path;
|
||||
|
||||
if(file_exists($relPath)){
|
||||
require_once $relPath;
|
||||
}
|
||||
} else if(strpos($className, 'Test\\') === 0) {
|
||||
$path = strtolower(
|
||||
str_replace('\\', '/', substr($className, 4)) . '.php'
|
||||
);
|
||||
echo $path;
|
||||
$relPath = __DIR__ . '/../../../tests/lib' . $path;
|
||||
|
||||
if(file_exists($relPath)){
|
||||
require_once $relPath;
|
||||
}
|
||||
}
|
||||
});
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace OCA\News\Tests\Integration;
|
||||
|
||||
require_once __DIR__ . '/../../../../tests/bootstrap.php';
|
||||
require_once __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use OCP\IDb;
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - News
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Alessandro Cosentino <cosenal@gmail.com>
|
||||
* @author Bernhard Posselt <dev@bernhard-posselt.com>
|
||||
* @copyright Alessandro Cosentino 2012
|
||||
* @copyright Bernhard Posselt 2012, 2014
|
||||
*/
|
||||
|
||||
namespace OCA\News\Controller;
|
||||
|
||||
|
||||
class UserApiControllerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $request;
|
||||
private $appName;
|
||||
private $rootFolder;
|
||||
private $userSession;
|
||||
private $controller;
|
||||
private $user;
|
||||
private $file;
|
||||
|
||||
protected function setUp() {
|
||||
$this->appName = 'news';
|
||||
$this->request = $this->getMockBuilder(
|
||||
'\OCP\IRequest')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->rootFolder = $this->getMockBuilder(
|
||||
'\OCP\Files\IRootFolder')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->file = $this->getMockBuilder(
|
||||
'\OCP\Files\File')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userSession = $this->getMockBuilder(
|
||||
'\OCP\IUserSession')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->user = $this->getMockBuilder(
|
||||
'\OCP\IUser')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->controller = new UserApiController(
|
||||
$this->appName, $this->request, $this->userSession,
|
||||
$this->rootFolder
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function expectUser($uid, $displayName, $lastLogin) {
|
||||
$this->userSession->expects($this->any())
|
||||
->method('getUser')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->user->expects($this->any())
|
||||
->method('getUID')
|
||||
->will($this->returnValue($uid));
|
||||
$this->user->expects($this->any())
|
||||
->method('getLastLogin')
|
||||
->will($this->returnValue($lastLogin));
|
||||
$this->user->expects($this->any())
|
||||
->method('getDisplayName')
|
||||
->will($this->returnValue($displayName));
|
||||
}
|
||||
|
||||
private function expectImg($isJpg, $isPng, $user, $exists, $data) {
|
||||
$jpg = '/' . $user . '/' . 'avatar.jpg';
|
||||
$png = '/' . $user . '/' . 'avatar.png';
|
||||
|
||||
$this->rootFolder->expects($this->any())
|
||||
->method('nodeExists')
|
||||
->will($this->returnValueMap([
|
||||
[$jpg, $isJpg],
|
||||
[$png, $isPng]
|
||||
]));
|
||||
$this->rootFolder->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($this->file));
|
||||
$this->file->expects($this->any())
|
||||
->method('getContent')
|
||||
->will($this->returnValue($data));
|
||||
}
|
||||
|
||||
public function testGetJpeg() {
|
||||
$this->expectUser('john', 'John', 123);
|
||||
$this->expectImg(true, false, 'john', true, 'hi');
|
||||
|
||||
$result = $this->controller->index();
|
||||
$expected = [
|
||||
'userId' => 'john',
|
||||
'displayName' => 'John',
|
||||
'lastLoginTimestamp' => 123,
|
||||
'avatar' => [
|
||||
'data' => base64_encode('hi'),
|
||||
'mime' => 'image/jpeg'
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testGetPng() {
|
||||
$this->expectUser('john', 'John', 123);
|
||||
$this->expectImg(false, true, 'john', false, 'hi');
|
||||
|
||||
$result = $this->controller->index();
|
||||
$expected = [
|
||||
'userId' => 'john',
|
||||
'displayName' => 'John',
|
||||
'lastLoginTimestamp' => 123,
|
||||
'avatar' => [
|
||||
'data' => base64_encode('hi'),
|
||||
'mime' => 'image/png'
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testNoAvatar() {
|
||||
$this->expectUser('john', 'John', 123);
|
||||
$this->expectImg(false, false, 'john', false, 'hi');
|
||||
|
||||
$result = $this->controller->index();
|
||||
$expected = [
|
||||
'userId' => 'john',
|
||||
'displayName' => 'John',
|
||||
'lastLoginTimestamp' => 123,
|
||||
'avatar' => null
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue