remove old phpunit tests

This commit is contained in:
korelstar 2020-02-19 21:36:33 +01:00
parent 70e77ed35d
commit d17d2ffc6c
9 changed files with 0 additions and 1211 deletions

View File

@ -1,8 +0,0 @@
<phpunit bootstrap="../../lib/base.php"
colors="true">
<testsuites>
<testsuite name="integration">
<directory>./tests/integration</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@ -1,12 +0,0 @@
<phpunit bootstrap="../../tests/bootstrap.php"
verbose="true"
timeoutForSmallTests="900"
timeoutForMediumTests="900"
timeoutForLargeTests="900"
colors="true">
<testsuites>
<testsuite name="unit">
<directory>./tests/unit</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@ -1,78 +0,0 @@
<?php
/**
* Nextcloud - Notes
*
* 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 2015
*/
namespace OCA\Notes\Controller;
use PHPUnit_Framework_TestCase;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\App;
use OCP\Files\File;
class NotesApiControllerTest extends PHPUnit_Framework_TestCase {
private $controller;
private $mapper;
private $userId = 'test';
private $notesFolder = '/test/files/Notes';
private $fs;
public function setUp() {
$app = new App('notes');
$container = $app->getContainer();
$container->registerService('UserId', function($c) {
return $this->userId;
});
$this->controller = $container->query(
'OCA\Notes\Controller\NotesApiController'
);
$this->fs = $container->query(
'OCP\Files\IRootFolder'
);
$this->fs->newFolder($this->notesFolder);
}
public function testUpdate() {
$note = $this->controller->create('test')->getData();
$this->assertEquals('test', $note->getContent());
$t = 100000;
$note2 = $this->controller->update($note->getId(), 'test2')->getData();
$this->assertEquals('test2', $note2->getContent());
$this->assertEquals($note->getId(), $note2->getId());
$this->assertNotEquals($t, $note2->getModified());
$note3 = $this->controller->update($note->getId(), 'test3', null, $t)->getData();
$this->assertEquals('test3', $note3->getContent());
$this->assertEquals($note->getId(), $note3->getId());
$this->assertEquals($t, $note3->getModified());
$notes = $this->controller->index()->getData();
$this->assertCount(1, $notes);
$this->assertEquals('test3', $notes[0]->getContent());
$file = $this->fs->get($this->notesFolder . '/test3.txt');
$this->assertTrue($file instanceof File);
}
public function tearDown() {
$this->fs->get($this->notesFolder)->delete();
}
}

View File

@ -1,68 +0,0 @@
<?php
/**
* Nextcloud - Notes
*
* 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 2015
*/
namespace OCA\Notes\Controller;
use PHPUnit_Framework_TestCase;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\App;
use OCP\Files\File;
class NotesControllerTest extends PHPUnit_Framework_TestCase {
private $controller;
private $userId = 'test';
private $notesFolder = '/test/files/Notes';
private $fs;
public function setUp() {
$app = new App('notes');
$container = $app->getContainer();
$container->registerService('UserId', function($c) {
return $this->userId;
});
$this->controller = $container->query(
'OCA\Notes\Controller\NotesController'
);
$this->fs = $container->query(
'OCP\Files\IRootFolder'
);
$this->fs->newFolder($this->notesFolder);
}
public function testUpdate() {
$note = $this->controller->create('test')->getData();
$this->assertEquals('test', $note->getContent());
$note2 = $this->controller->update($note->getId(), 'test2')->getData();
$this->assertEquals('test2', $note2->getContent());
$this->assertEquals($note->getId(), $note2->getId());
$notes = $this->controller->index()->getData();
$this->assertCount(1, $notes);
$this->assertEquals('test2', $notes[0]->getContent());
$file = $this->fs->get($this->notesFolder . '/test2.txt');
$this->assertTrue($file instanceof File);
}
public function tearDown() {
$this->fs->get($this->notesFolder)->delete();
}
}

View File

@ -1,271 +0,0 @@
<?php
/**
* Nextcloud - Notes
*
* 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
*/
namespace OCA\Notes\Controller;
use PHPUnit_Framework_TestCase;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http;
use OCA\Notes\Service\NoteDoesNotExistException;
use OCA\Notes\Db\Note;
class NotesApiControllerTest extends PHPUnit_Framework_TestCase {
private $request;
private $service;
private $userId;
private $appName;
private $controller;
public function setUp (){
$this->request = $this->getMockBuilder('OCP\IRequest')
->disableOriginalConstructor()
->getMock();
$this->service = $this->getMockBuilder('OCA\Notes\Service\NotesService')
->disableOriginalConstructor()
->getMock();
$this->userId = 'john';
$this->appName = 'notes';
$this->controller = new NotesApiController(
$this->appName, $this->request, $this->service, $this->userId
);
}
/**
* GET /notes/
*/
public function testGetAll(){
$expected = [new Note, new Note];
$this->service->expects($this->once())
->method('getAll')
->with($this->equalTo($this->userId))
->will($this->returnValue($expected));
$response = $this->controller->index();
$this->assertEquals($expected, $response->getData());
$this->assertTrue($response instanceof DataResponse);
}
public function testGetAllHide(){
$note1 = Note::fromRow([
'id' => 3,
'modified' => 123,
'title' => 'test',
'content' => 'yo'
]);
$note2 = Note::fromRow([
'id' => 4,
'modified' => 111,
'title' => 'abc',
'content' => 'deee'
]);
$notes = [
$note1, $note2
];
$this->service->expects($this->once())
->method('getAll')
->with($this->equalTo($this->userId))
->will($this->returnValue($notes));
$response = $this->controller->index('title,content');
$this->assertEquals(json_encode([
[
'etag' => null,
'modified' => 123,
'category' => null,
'favorite' => false,
'id' => 3,
],
[
'etag' => null,
'modified' => 111,
'category' => null,
'favorite' => false,
'id' => 4,
]
]), json_encode($response->getData()));
$this->assertTrue($response instanceof DataResponse);
}
/**
* GET /notes/1
*/
public function testGet(){
$id = 1;
$expected = new Note;
$this->service->expects($this->once())
->method('get')
->with($this->equalTo($id),
$this->equalTo($this->userId))
->will($this->returnValue($expected));
$response = $this->controller->get($id);
$this->assertEquals($expected, $response->getData());
$this->assertTrue($response instanceof DataResponse);
}
public function testGetHide(){
$note = Note::fromRow([
'id' => 3,
'modified' => 123,
'title' => 'test',
'content' => 'yo'
]);
$this->service->expects($this->once())
->method('get')
->with($this->equalTo(3),
$this->equalTo($this->userId))
->will($this->returnValue($note));
$response = $this->controller->get(3, 'title,content');
$this->assertEquals(json_encode([
'etag' => null,
'modified' => 123,
'category' => null,
'favorite' => false,
'id' => 3,
]), json_encode($response->getData()));
$this->assertTrue($response instanceof DataResponse);
}
public function testGetDoesNotExist(){
$id = 1;
$expected = ['hi'];
$this->service->expects($this->once())
->method('get')
->with($this->equalTo($id),
$this->equalTo($this->userId))
->will($this->throwException(new NoteDoesNotExistException()));
$response = $this->controller->get($id);
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
$this->assertTrue($response instanceof DataResponse);
}
/**
* POST /notes
*/
public function testCreate(){
$content = 'yii';
$note = new Note();
$note->setId(4);
$this->service->expects($this->once())
->method('create')
->with($this->equalTo($this->userId))
->will($this->returnValue($note));
$this->service->expects($this->once())
->method('update')
->with($this->equalTo($note->getId()),
$this->equalTo($content),
$this->equalTo($this->userId))
->will($this->returnValue($note));
$response = $this->controller->create($content);
$this->assertEquals($note, $response->getData());
$this->assertTrue($response instanceof DataResponse);
}
/**
* PUT /notes/
*/
public function testUpdate(){
$id = 1;
$content = 'yo';
$expected = ['hi'];
$this->service->expects($this->once())
->method('update')
->with($this->equalTo($id),
$this->equalTo($content),
$this->equalTo($this->userId))
->will($this->returnValue($expected));
$response = $this->controller->update($id, $content);
$this->assertEquals($expected, $response->getData());
$this->assertTrue($response instanceof DataResponse);
}
public function testUpdateDoesNotExist(){
$id = 1;
$content = 'yo';
$this->service->expects($this->once())
->method('update')
->with($this->equalTo($id),
$this->equalTo($content),
$this->equalTo($this->userId))
->will($this->throwException(new NoteDoesNotExistException()));
$response = $this->controller->update($id, $content);
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
$this->assertTrue($response instanceof DataResponse);
}
/**
* DELETE /notes/
*/
public function testDelete(){
$id = 1;
$this->service->expects($this->once())
->method('delete')
->with($this->equalTo(1),
$this->equalTo($this->userId));
$response = $this->controller->destroy($id);
$this->assertTrue($response instanceof DataResponse);
}
public function testDeleteDoesNotExist(){
$id = 1;
$this->service->expects($this->once())
->method('delete')
->with($this->equalTo(1),
$this->equalTo($this->userId))
->will($this->throwException(new NoteDoesNotExistException()));
$response = $this->controller->destroy($id);
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
$this->assertTrue($response instanceof DataResponse);
}
}

View File

@ -1,219 +0,0 @@
<?php
/**
* Nextcloud - Notes
*
* 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
*/
namespace OCA\Notes\Controller;
use PHPUnit_Framework_TestCase;
use OCP\IRequest;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http;
use OCA\Notes\Service\NoteDoesNotExistException;
use OCA\Notes\Db\Note;
class NotesControllerTest extends PHPUnit_Framework_TestCase {
private $request;
private $service;
private $userId;
private $appName;
private $controller;
private $config;
public function setUp (){
$this->request = $this->getMockBuilder('OCP\IRequest')
->disableOriginalConstructor()
->getMock();
$this->config = $this->getMockBuilder('OCP\IConfig')
->disableOriginalConstructor()
->getMock();
$this->service = $this->getMockBuilder('OCA\Notes\Service\NotesService')
->disableOriginalConstructor()
->getMock();
$this->userId = 'john';
$this->appName = 'notes';
$this->controller = new NotesController(
$this->appName, $this->request, $this->service, $this->config,
$this->userId
);
}
/**
* GET /notes/
*/
public function testGetAll(){
$expected = ['hi'];
$this->service->expects($this->once())
->method('getAll')
->will($this->returnValue($expected));
$response = $this->controller->index();
$this->assertEquals($expected, $response->getData());
$this->assertTrue($response instanceof DataResponse);
}
/**
* GET /notes/1
*/
public function testGet(){
$id = 1;
$expected = ['hi'];
$this->config->expects($this->once())
->method('setUserValue')
->with($this->equalTo($this->userId),
$this->equalTo($this->appName),
$this->equalTo('notesLastViewedNote'),
$this->equalTo($id));
$this->service->expects($this->once())
->method('get')
->with($this->equalTo($id),
$this->equalTo($this->userId))
->will($this->returnValue($expected));
$response = $this->controller->get($id);
$this->assertEquals($expected, $response->getData());
$this->assertTrue($response instanceof DataResponse);
}
public function testGetDoesNotExist(){
$id = 1;
$expected = ['hi'];
$this->config->expects($this->once())
->method('setUserValue')
->with($this->equalTo($this->userId),
$this->equalTo($this->appName),
$this->equalTo('notesLastViewedNote'),
$this->equalTo($id));
$this->service->expects($this->once())
->method('get')
->with($this->equalTo($id),
$this->equalTo($this->userId))
->will($this->throwException(new NoteDoesNotExistException()));
$response = $this->controller->get($id);
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
$this->assertTrue($response instanceof DataResponse);
}
/**
* POST /notes
*/
public function testCreate(){
$created = new Note();
$created->setId(3);
$expected = new Note();
$this->service->expects($this->once())
->method('create')
->with($this->equalTo($this->userId))
->will($this->returnValue($created));
$this->service->expects($this->once())
->method('update')
->with(3, 'hi', $this->userId)
->will($this->returnValue($expected));
$response = $this->controller->create('hi');
$this->assertEquals($expected, $response->getData());
$this->assertTrue($response instanceof DataResponse);
}
/**
* PUT /notes/
*/
public function testUpdate(){
$id = 1;
$content = 'yo';
$expected = ['hi'];
$this->service->expects($this->once())
->method('update')
->with($this->equalTo($id),
$this->equalTo($content),
$this->equalTo($this->userId))
->will($this->returnValue($expected));
$response = $this->controller->update($id, $content);
$this->assertEquals($expected, $response->getData());
$this->assertTrue($response instanceof DataResponse);
}
public function testUpdateDoesNotExist(){
$id = 1;
$content = 'yo';
$this->service->expects($this->once())
->method('update')
->with($this->equalTo($id),
$this->equalTo($content),
$this->equalTo($this->userId))
->will($this->throwException(new NoteDoesNotExistException()));
$response = $this->controller->update($id, $content);
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
$this->assertTrue($response instanceof DataResponse);
}
/**
* DELETE /notes/
*/
public function testDelete(){
$id = 1;
$this->service->expects($this->once())
->method('delete')
->with($this->equalTo($id),
$this->equalTo($this->userId));
$response = $this->controller->destroy($id);
$this->assertTrue($response instanceof DataResponse);
}
public function testDeleteDoesNotExist(){
$id = 1;
$this->service->expects($this->once())
->method('delete')
->with($this->equalTo($id),
$this->equalTo($this->userId))
->will($this->throwException(new NoteDoesNotExistException()));
$response = $this->controller->destroy($id);
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
$this->assertTrue($response instanceof DataResponse);
}
}

View File

@ -1,102 +0,0 @@
<?php
/**
* Nextcloud - Notes
*
* 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
*/
namespace OCA\Notes\Controller;
use PHPUnit_Framework_TestCase;
use OCP\IRequest;
use OCP\AppFramework\Http\TemplateResponse;
use OCA\Notes\Service\NoteDoesNotExistException;
class PageControllerTest extends PHPUnit_Framework_TestCase {
private $request;
private $service;
private $userId;
private $appName;
private $controller;
private $config;
public function setUp (){
$this->request = $this->getMockBuilder('OCP\IRequest')
->disableOriginalConstructor()
->getMock();
$this->service = $this->getMockBuilder('OCA\Notes\Service\NotesService')
->disableOriginalConstructor()
->getMock();
$this->config = $this->getMockBuilder('OCP\IConfig')
->disableOriginalConstructor()
->getMock();
$this->userId = 'john';
$this->appName = 'notes';
$this->controller = new PageController(
$this->appName, $this->request, $this->userId,
$this->service, $this->config
);
}
public function testIndexReturnsTemplate(){
$result = $this->controller->index();
$this->assertTrue($result instanceof TemplateResponse);
}
public function testIndexShouldSendTheCorrectTemplate(){
$this->config->expects($this->once())
->method('getUserValue')
->with($this->equalTo($this->userId),
$this->equalTo($this->appName),
$this->equalTo('notesLastViewedNote'))
->will($this->returnValue('3'));
$result = $this->controller->index();
$this->assertEquals('main', $result->getTemplateName());
$this->assertEquals(['lastViewedNote' => 3], $result->getParams());
}
public function testIndexShouldSendZeroWhenNoLastViewedNote(){
$this->config->expects($this->once())
->method('getUserValue')
->with($this->equalTo($this->userId),
$this->equalTo($this->appName),
$this->equalTo('notesLastViewedNote'))
->will($this->returnValue(''));
$result = $this->controller->index();
$this->assertEquals(['lastViewedNote' => 0], $result->getParams());
}
public function testIndexShouldSetZeroWhenLastViewedNotDoesNotExist(){
$this->config->expects($this->once())
->method('getUserValue')
->with($this->equalTo($this->userId),
$this->equalTo($this->appName),
$this->equalTo('notesLastViewedNote'))
->will($this->returnValue('3'));
$this->service->expects($this->once())
->method('get')
->with($this->equalTo(3),
$this->equalTo($this->userId))
->will($this->throwException(new NoteDoesNotExistException()));
$result = $this->controller->index();
$this->assertEquals(['lastViewedNote' => 0], $result->getParams());
}
}

View File

@ -1,88 +0,0 @@
<?php
/**
* Nextcloud - Notes
*
* 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
*/
namespace OCA\Notes\Db;
use PHPUnit_Framework_TestCase;
class NoteTest extends PHPUnit_Framework_TestCase {
public function testFromFile(){
$file = $this->getMockBuilder('OCP\Files\File')->getMock();
$file->expects($this->any())
->method('getId')
->will($this->returnValue(3));
$file->expects($this->any())
->method('getContent')
->will($this->returnValue('content'));
$file->expects($this->any())
->method('getMTime')
->will($this->returnValue(323));
$file->expects($this->any())
->method('getName')
->will($this->returnValue('file.txt'));
$file->expects($this->any())
->method('getPath')
->will($this->returnValue('/john/files/Notes/file.txt'));
$notesFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
$notesFolder->expects($this->any())
->method('getPath')
->will($this->returnValue('/john/files/Notes'));
$note = Note::fromFile($file, $notesFolder);
$this->assertEquals(3, $note->getId());
$this->assertEquals(323, $note->getModified());
$this->assertEquals(null, $note->getCategory());
$this->assertEquals('file', $note->getTitle());
$this->assertEquals('content', $note->getContent());
}
public function testFromFileInSubdir(){
$file = $this->getMockBuilder('OCP\Files\File')->getMock();
$file->expects($this->any())
->method('getId')
->will($this->returnValue(3));
$file->expects($this->any())
->method('getContent')
->will($this->returnValue('content'));
$file->expects($this->any())
->method('getMTime')
->will($this->returnValue(323));
$file->expects($this->any())
->method('getName')
->will($this->returnValue('file.txt'));
$file->expects($this->any())
->method('getPath')
->will($this->returnValue('/john/files/Notes/mycategory/file.txt'));
$notesFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock();
$notesFolder->expects($this->any())
->method('getPath')
->will($this->returnValue('/john/files/Notes'));
$note = Note::fromFile($file, $notesFolder);
$this->assertEquals(3, $note->getId());
$this->assertEquals(323, $note->getModified());
$this->assertEquals('mycategory', $note->getCategory());
$this->assertEquals('file', $note->getTitle());
$this->assertEquals('content', $note->getContent());
}
}

View File

@ -1,365 +0,0 @@
<?php
/**
* Nextcloud - Notes
*
* 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
*/
namespace OCA\Notes\Service;
use PHPUnit_Framework_TestCase;
use OCA\Notes\Db\Note;
class NotesServiceTest extends PHPUnit_Framework_TestCase {
private $root;
private $service;
private $userId;
private $l10n;
private $userFolder;
public function setUp(){
$this->root = $this->getMockBuilder('OCP\Files\IRootFolder')
->getMock();
$this->userFolder = $this->getMockBuilder('OCP\Files\Folder')
->getMock();
$this->l10n = $this->getMockBuilder('OCP\IL10N')
->getMock();
$this->userId = 'john';
$this->service = new NotesService($this->root, $this->l10n);
}
private function createNode($name, $type, $mime, $mtime=0, $content='', $id=0, $subdir='') {
if ($type === 'folder') {
$iface = 'OCP\Files\Folder';
} else {
$iface = 'OCP\Files\File';
}
$node = $this->getMockBuilder($iface)
->getMock();
$node->expects($this->any())
->method('getType')
->will($this->returnValue($type));
$node->expects($this->any())
->method('getMimeType')
->will($this->returnValue($mime));
$node->expects($this->any())
->method('getName')
->will($this->returnValue($name));
$node->expects($this->any())
->method('getMTime')
->will($this->returnValue($mtime));
$node->expects($this->any())
->method('getId')
->will($this->returnValue($id));
$node->expects($this->any())
->method('getPath')
->will($this->returnValue('/' . $this->userId . '/files/Notes/'.$subdir.($subdir ? '/' : '').$name));
$node->expects($this->any())
->method('getParent')
->will($this->returnValue($this->userFolder));
if ($type === 'file') {
$node->expects($this->any())
->method('getContent')
->will($this->returnValue($content));
}
return $node;
}
private function expectUserFolder($at=0) {
$path = '/' . $this->userId . '/files/Notes';
$this->root->expects($this->at($at))
->method('nodeExists')
->with($this->equalTo($path))
->will($this->returnValue(true));
$this->root->expects($this->any($at + 1))
->method('get')
->with($this->equalTo($path))
->will($this->returnValue($this->userFolder));
}
public function testGetAll(){
$nodes = [];
$nodes[] = $this->createNode('file1.txt', 'file', 'text/plain');
$nodes[] = $this->createNode('file1.jpg', 'file', 'image/jpeg');
$nodes[] = $this->createNode('file3.txt', 'folder', 'text/plain');
$this->expectUserFolder();
$this->userFolder->expects($this->once())
->method('getDirectoryListing')
->will($this->returnValue($nodes));
$result = $this->service->getAll($this->userId);
$this->assertEquals('file1', $result[0]->getTitle());
$this->assertCount(1, $result);
}
public function testGet(){
$nodes = [];
$nodes[] = $this->createNode('file1.txt', 'file', 'text/plain');
$this->expectUserFolder();
$this->userFolder->expects($this->once())
->method('getById')
->with($this->equalTo(2))
->will($this->returnValue($nodes));
$result = $this->service->get(2, $this->userId);
$this->assertEquals('file1', $result->getTitle());
}
/**
* @expectedException OCA\Notes\Service\NoteDoesNotExistException
*/
public function testGetDoesNotExist(){
$nodes = [];
$this->expectUserFolder();
$this->userFolder->expects($this->once())
->method('getById')
->with($this->equalTo(2))
->will($this->returnValue($nodes));
$this->service->get(2, $this->userId);
}
/**
* @expectedException OCA\Notes\Service\NoteDoesNotExistException
*/
public function testGetDoesNotExistWrongExtension(){
$nodes = [];
$nodes[] = $this->createNode('file1.jpg', 'file', 'image/jpeg');
$this->expectUserFolder();
$this->userFolder->expects($this->once())
->method('getById')
->with($this->equalTo(2))
->will($this->returnValue($nodes));
$this->service->get(2, $this->userId);
}
public function testDelete(){
$nodes = [];
$nodes[] = $this->createNode('file1.txt', 'file', 'text/plain');
$this->expectUserFolder();
$this->userFolder->expects($this->once())
->method('getById')
->with($this->equalTo(2))
->will($this->returnValue($nodes));
$nodes[0]->expects($this->once())
->method('delete');
$this->service->delete(2, $this->userId);
}
/**
* @expectedException OCA\Notes\Service\NoteDoesNotExistException
*/
public function testDeleteDoesNotExist(){
$nodes = [];
$this->expectUserFolder();
$this->userFolder->expects($this->once())
->method('getById')
->with($this->equalTo(2))
->will($this->returnValue($nodes));
$this->service->delete(2, $this->userId);
}
/**
* @expectedException OCA\Notes\Service\NoteDoesNotExistException
*/
public function testDeleteDoesNotExistWrongExtension(){
$nodes = [];
$nodes[] = $this->createNode('file1.jpg', 'file', 'image/jpeg');
$this->expectUserFolder();
$this->userFolder->expects($this->once())
->method('getById')
->with($this->equalTo(2))
->will($this->returnValue($nodes));
$this->service->delete(2, $this->userId);
}
private function expectGenerateFileName($at=0, $title, $id=0, $branch=0) {
if ($branch === 0) {
$this->userFolder->expects($this->at($at))
->method('nodeExists')
->with($this->equalTo($title . '.txt'))
->will($this->returnValue(false));
} else if ($branch === 1) {
$this->userFolder->expects($this->at($at))
->method('nodeExists')
->with($this->equalTo($title . '.txt'))
->will($this->returnValue(true));
$file = $this->createNode('file1.txt', 'file', 'text/plain', 0, '', 0);
$this->userFolder->expects($this->at($at+1))
->method('get')
->with($this->equalTo($title . '.txt'))
->will($this->returnValue($file));
} else if ($branch === 2) {
$this->userFolder->expects($this->at($at))
->method('nodeExists')
->with($this->equalTo($title . '.txt'))
->will($this->returnValue(true));
$file = $this->createNode('file1.txt', 'file', 'text/plain', 0, '', 0);
$this->userFolder->expects($this->at($at+1))
->method('get')
->with($this->equalTo($title . '.txt'))
->will($this->returnValue($file));
$this->userFolder->expects($this->at($at+2))
->method('nodeExists')
->with($this->equalTo($title . ' (2).txt'))
->will($this->returnValue(true));
$this->userFolder->expects($this->at($at+3))
->method('get')
->with($this->equalTo($title . ' (2).txt'))
->will($this->returnValue($file));
$this->userFolder->expects($this->at($at+4))
->method('nodeExists')
->with($this->equalTo($title . ' (3).txt'))
->will($this->returnValue(false));
}
}
public function testCreate() {
$this->l10n->expects($this->once())
->method('t')
->with($this->equalTo('New note'))
->will($this->returnValue('New note'));
$this->expectUserFolder();
$this->expectGenerateFileName(0, 'New note');
$file = $this->createNode('file1.txt', 'file', 'text/plain');
$this->userFolder->expects($this->once())
->method('newFile')
->with($this->equalTo('New note.txt'))
->will($this->returnValue($file));
$note = $this->service->create($this->userId);
$this->assertEquals('file1', $note->getTitle());
}
public function testCreateModified() {
$t = 2000000;
$this->l10n->expects($this->once())
->method('t')
->with($this->equalTo('New note'))
->will($this->returnValue('New note'));
$this->expectUserFolder();
$this->expectGenerateFileName(0, 'New note');
$file = $this->createNode('file1.txt', 'file', 'text/plain', $t);
$this->userFolder->expects($this->once())
->method('newFile')
->with($this->equalTo('New note.txt'))
->will($this->returnValue($file));
$note = $this->service->create($this->userId, $t);
$this->assertEquals('file1', $note->getTitle());
$this->assertEquals($t, $note->getModified());
}
public function testCreateExists() {
$this->l10n->expects($this->once())
->method('t')
->with($this->equalTo('New note'))
->will($this->returnValue('New note'));
$this->expectUserFolder();
$this->expectGenerateFileName(0, 'New note', 0, 2);
$file = $this->createNode('file1.txt', 'file', 'text/plain');
$this->userFolder->expects($this->once())
->method('newFile')
->with($this->equalTo('New note (3).txt'))
->will($this->returnValue($file));
$note = $this->service->create($this->userId);
$this->assertEquals('file1', $note->getTitle());
}
public function testUpdate() {
$nodes = [];
$nodes[] = $this->createNode('file1.txt', 'file', 'text/plain');
$this->expectUserFolder();
$this->userFolder->expects($this->at(0))
->method('getById')
->with($this->equalTo(3))
->will($this->returnValue($nodes));
$this->l10n->expects($this->once())
->method('t')
->with($this->equalTo('New note'))
->will($this->returnValue('New note'));
$this->expectUserFolder();
$this->expectGenerateFileName(1, 'New note', 0, 2);
$path = '/' . $this->userId . '/files/Notes/New note (3).txt';
$nodes[0]->expects($this->once())
->method('move')
->with($this->equalTo($path));
$note = $this->service->update(3, '', $this->userId);
$this->assertEquals('file1', $note->getTitle());
}
public function testUpdateWithContent() {
$nodes = [];
$nodes[] = $this->createNode('file1.txt', 'file', 'text/plain');
$this->expectUserFolder();
$this->userFolder->expects($this->at(0))
->method('getById')
->with($this->equalTo(3))
->will($this->returnValue($nodes));
$this->l10n->expects($this->never())
->method('t');
$this->expectUserFolder();
$this->expectGenerateFileName(1, 'some', 0, 2);
$path = '/' . $this->userId . '/files/Notes/some (3).txt';
$nodes[0]->expects($this->once())
->method('move')
->with($this->equalTo($path));
$note = $this->service->update(3, "some\nnice", $this->userId);
$this->assertEquals('file1', $note->getTitle());
}
}