first commit
This commit is contained in:
Родитель
9c7374333b
Коммит
5c87cf3d41
|
@ -0,0 +1,3 @@
|
|||
.idea
|
||||
*.iml
|
||||
/vendor/
|
80
.travis.yml
80
.travis.yml
|
@ -1,43 +1,57 @@
|
|||
sudo: required
|
||||
dist: trusty
|
||||
language: php
|
||||
php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- hhvm
|
||||
|
||||
- 7.1
|
||||
env:
|
||||
- DB=sqlite BRANCH=master
|
||||
- DB=postgresql BRANCH=master
|
||||
- DB=mysql BRANCH=master
|
||||
global:
|
||||
- CORE_BRANCH=stable12
|
||||
matrix:
|
||||
- DB=pgsql
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: hhvm
|
||||
allow_failures:
|
||||
- env: DB=pgsql CORE_BRANCH=master
|
||||
include:
|
||||
- php: 7.1
|
||||
env: DB=sqlite
|
||||
- php: 7.1
|
||||
env: DB=mysql
|
||||
- php: 7.1
|
||||
env: DB=pgsql CORE_BRANCH=master
|
||||
fast_finish: true
|
||||
|
||||
install:
|
||||
# install ocdev
|
||||
- sudo apt-get -y install python3-jinja2 python3-setuptools
|
||||
- sudo easy_install3 requests
|
||||
- sudo easy_install3 ocdev
|
||||
# set up postgresql
|
||||
- createuser -U travis -s oc_autotest
|
||||
# set up mysql
|
||||
- mysql -e 'create database oc_autotest;'
|
||||
- mysql -u root -e "CREATE USER 'oc_autotest'@'localhost';"
|
||||
- mysql -u root -e "grant all on oc_autotest.* to 'oc_autotest'@'localhost';"
|
||||
# install owncloud
|
||||
- cd ..
|
||||
- ocdev setup core --dir owncloud --branch $BRANCH --no-history
|
||||
- mv app-tutorial owncloud/apps/ownnotes
|
||||
- phpenv config-add owncloud/apps/ownnotes/tests/travis/php.ini
|
||||
- cd owncloud
|
||||
- ocdev ci $DB
|
||||
# enable ownnotes
|
||||
- php -f console.php app:enable ownnotes
|
||||
before_install:
|
||||
# enable a display for running JavaScript tests
|
||||
- export DISPLAY=:99.0
|
||||
- sh -e /etc/init.d/xvfb start
|
||||
- if [[ "$DB" == 'mysql' ]]; then sudo apt-get -y install mariadb-server; fi
|
||||
- nvm install 8
|
||||
- npm install -g npm@latest
|
||||
- make
|
||||
- make appstore
|
||||
# install core
|
||||
- cd ../
|
||||
- git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b $CORE_BRANCH nextcloud
|
||||
- mv notestutorial nextcloud/apps/
|
||||
|
||||
before_script:
|
||||
- cd apps/ownnotes
|
||||
- if [[ "$DB" == 'pgsql' ]]; then createuser -U travis -s oc_autotest; fi
|
||||
- if [[ "$DB" == 'mysql' ]]; then mysql -u root -e 'create database oc_autotest;'; fi
|
||||
- if [[ "$DB" == 'mysql' ]]; then mysql -u root -e "CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY '';"; fi
|
||||
- if [[ "$DB" == 'mysql' ]]; then mysql -u root -e "grant all on oc_autotest.* to 'oc_autotest'@'localhost';"; fi
|
||||
- cd nextcloud
|
||||
- mkdir data
|
||||
- ./occ maintenance:install --database-name oc_autotest --database-user oc_autotest --admin-user admin --admin-pass admin --database $DB --database-pass=''
|
||||
- ./occ app:enable notestutorial
|
||||
- php -S localhost:8080 &
|
||||
- cd apps/notestutorial
|
||||
|
||||
script:
|
||||
- phpunit -c phpunit.xml
|
||||
- phpunit -c phpunit.integration.xml
|
||||
- make test
|
||||
|
||||
after_failure:
|
||||
- cat ../../data/nextcloud.log
|
||||
|
||||
addons:
|
||||
firefox: "latest"
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
owncloud-ownnotes (0.0.2)
|
||||
owncloud-notestutorial (0.0.2)
|
||||
* First release
|
101
Makefile
101
Makefile
|
@ -1,40 +1,75 @@
|
|||
# Makefile for building the project
|
||||
# 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 2016
|
||||
|
||||
app_name=ownnotes
|
||||
project_dir=$(CURDIR)/../$(app_name)
|
||||
build_dir=$(CURDIR)/build/artifacts
|
||||
appstore_dir=$(build_dir)/appstore
|
||||
source_dir=$(build_dir)/source
|
||||
package_name=$(app_name)
|
||||
app_name=$(notdir $(CURDIR))
|
||||
build_tools_directory=$(CURDIR)/build/tools
|
||||
source_build_directory=$(CURDIR)/build/artifacts/source
|
||||
source_package_name=$(source_build_directory)/$(app_name)
|
||||
appstore_build_directory=$(CURDIR)/build/artifacts/appstore
|
||||
appstore_package_name=$(appstore_build_directory)/$(app_name)
|
||||
composer=$(shell which composer 2> /dev/null)
|
||||
|
||||
all: dist
|
||||
all: build
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
make composer
|
||||
|
||||
# Installs and updates the composer dependencies. If composer is not installed
|
||||
# a copy is fetched from the web
|
||||
.PHONY: composer
|
||||
composer:
|
||||
ifeq (, $(composer))
|
||||
@echo "No composer command available, downloading a copy from the web"
|
||||
mkdir -p $(build_tools_directory)
|
||||
curl -sS https://getcomposer.org/installer | php
|
||||
mv composer.phar $(build_tools_directory)
|
||||
php $(build_tools_directory)/composer.phar install --prefer-dist
|
||||
php $(build_tools_directory)/composer.phar update --prefer-dist
|
||||
else
|
||||
composer install --prefer-dist
|
||||
composer update --prefer-dist
|
||||
endif
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf $(build_dir)
|
||||
rm -rf ./build
|
||||
|
||||
dist: clean
|
||||
mkdir -p $(source_dir)
|
||||
tar cvzf $(source_dir)/$(package_name).tar.gz $(project_dir) \
|
||||
--exclude-vcs \
|
||||
--exclude=$(project_dir)/build/artifacts \
|
||||
--exclude=$(project_dir)/js/node_modules \
|
||||
--exclude=$(project_dir)/js/coverage
|
||||
.PHONY: distclean
|
||||
distclean: clean
|
||||
rm -rf vendor
|
||||
|
||||
appstore_package: clean
|
||||
mkdir -p $(appstore_dir)
|
||||
tar cvzf $(appstore_dir)/$(package_name).tar.gz $(project_dir) \
|
||||
# Builds the source and appstore package
|
||||
.PHONY: dist
|
||||
dist:
|
||||
make source
|
||||
make appstore
|
||||
|
||||
.PHONY: source
|
||||
source:
|
||||
rm -rf $(source_build_directory)
|
||||
mkdir -p $(source_build_directory)
|
||||
tar cvzf $(source_package_name).tar.gz ../$(app_name) \
|
||||
--exclude-vcs \
|
||||
--exclude=$(project_dir)/build \
|
||||
--exclude=$(project_dir)/js/node_modules \
|
||||
--exclude=$(project_dir)/js/.bowerrc \
|
||||
--exclude=$(project_dir)/js/.jshintrc \
|
||||
--exclude=$(project_dir)/js/Gruntfile.js \
|
||||
--exclude=$(project_dir)/js/*.json \
|
||||
--exclude=$(project_dir)/js/*.conf.js \
|
||||
--exclude=$(project_dir)/js/*.log \
|
||||
--exclude=$(project_dir)/js/README.md \
|
||||
--exclude=$(project_dir)/js/.bowerrc \
|
||||
--exclude=$(project_dir)/.travis.yml \
|
||||
--exclude=$(project_dir)/phpunit*xml \
|
||||
--exclude=$(project_dir)/Makefile \
|
||||
--exclude=$(project_dir)/tests
|
||||
--exclude="../$(app_name)/build" \
|
||||
--exclude="../$(app_name)/*.log"
|
||||
|
||||
.PHONY: appstore
|
||||
appstore:
|
||||
rm -rf $(appstore_build_directory)
|
||||
mkdir -p $(appstore_build_directory)
|
||||
tar cvzf $(appstore_package_name).tar.gz ../$(app_name) \
|
||||
--exclude-vcs \
|
||||
--exclude="../$(app_name)/build" \
|
||||
--exclude="../$(app_name)/tests" \
|
||||
--exclude="../$(app_name)/Makefile" \
|
||||
--exclude="../$(app_name)/*.log" \
|
||||
--exclude="../$(app_name)/phpunit*xml" \
|
||||
--exclude="../$(app_name)/composer.*"
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
./vendor/phpunit/phpunit/phpunit -c phpunit.xml
|
||||
./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml
|
|
@ -8,7 +8,7 @@ This is the tutorial app. To install it change into your ownCloud's apps directo
|
|||
|
||||
Then run:
|
||||
|
||||
git clone https://github.com/owncloud/app-tutorial.git ownnotes
|
||||
git clone https://github.com/owncloud/app-tutorial.git notestutorial
|
||||
|
||||
where the branch parameter is the ownCloud version that you are targeting:
|
||||
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
namespace OCA\OwnNotes\AppInfo;
|
||||
|
||||
use OCP\AppFramework\App;
|
||||
|
||||
$app = new App('ownnotes');
|
||||
$container = $app->getContainer();
|
||||
|
||||
$container->query('OCP\INavigationManager')->add(function () use ($container) {
|
||||
$urlGenerator = $container->query('OCP\IURLGenerator');
|
||||
$l10n = $container->query('OCP\IL10N');
|
||||
return [
|
||||
// the string under which your app will be referenced in owncloud
|
||||
'id' => 'ownnotes',
|
||||
|
||||
// sorting weight for the navigation. The higher the number, the higher
|
||||
// will it be listed in the navigation
|
||||
'order' => 10,
|
||||
|
||||
// the route that will be shown on startup
|
||||
'href' => $urlGenerator->linkToRoute('ownnotes.page.index'),
|
||||
|
||||
// the icon that will be shown in the navigation
|
||||
// this file needs to exist in img/
|
||||
'icon' => $urlGenerator->imagePath('ownnotes', 'app.svg'),
|
||||
|
||||
// the title of your application. This will be used in the
|
||||
// navigation or on the settings page of your app
|
||||
'name' => $l10n->t('Own Notes'),
|
||||
];
|
||||
});
|
|
@ -1,39 +1,37 @@
|
|||
<database>
|
||||
<database xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/database.xsd">
|
||||
<name>*dbname*</name>
|
||||
<create>true</create>
|
||||
<overwrite>false</overwrite>
|
||||
<charset>utf8</charset>
|
||||
<table>
|
||||
<name>*dbprefix*ownnotes_notes</name>
|
||||
<name>*dbprefix*notestutorial</name>
|
||||
<declaration>
|
||||
<field>
|
||||
<name>id</name>
|
||||
<type>integer</type>
|
||||
<length>8</length>
|
||||
<unsigned>true</unsigned>
|
||||
<notnull>true</notnull>
|
||||
<autoincrement>true</autoincrement>
|
||||
<unsigned>true</unsigned>
|
||||
<primary>true</primary>
|
||||
<length>8</length>
|
||||
</field>
|
||||
<field>
|
||||
<name>title</name>
|
||||
<type>text</type>
|
||||
<length>200</length>
|
||||
<default></default>
|
||||
<notnull>true</notnull>
|
||||
<default></default>
|
||||
</field>
|
||||
<field>
|
||||
<name>user_id</name>
|
||||
<type>text</type>
|
||||
<length>200</length>
|
||||
<default></default>
|
||||
<notnull>true</notnull>
|
||||
<default></default>
|
||||
</field>
|
||||
<field>
|
||||
<name>content</name>
|
||||
<type>clob</type>
|
||||
<default></default>
|
||||
<notnull>true</notnull>
|
||||
<default></default>
|
||||
</field>
|
||||
</declaration>
|
||||
</table>
|
||||
|
|
|
@ -1,14 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<info>
|
||||
<id>ownnotes</id>
|
||||
<name>Own Notes</name>
|
||||
<description>My first ownCloud app</description>
|
||||
<licence>AGPL</licence>
|
||||
<author>Bernhard Posselt</author>
|
||||
<version>0.0.2</version>
|
||||
<namespace>OwnNotes</namespace>
|
||||
<category>other</category>
|
||||
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
|
||||
<id>notestutorial</id>
|
||||
<name>Notes Tutorial</name>
|
||||
<summary>App for taking notes</summary>
|
||||
<description><![CDATA[This is a tutorial app for taking notes to demonstrate the Nextcloud API]]></description>
|
||||
<version>0.0.1</version>
|
||||
<licence>agpl</licence>
|
||||
<author mail="dev@bernhard-posselt.com" >Bernhard Posselt</author>
|
||||
<namespace>NotesTutorial</namespace>
|
||||
<category>office</category>
|
||||
<bugs>https://github.com/nextcloud/app-tutorial</bugs>
|
||||
<dependencies>
|
||||
<owncloud min-version="8" />
|
||||
<nextcloud min-version="12" max-version="12"/>
|
||||
</dependencies>
|
||||
</info>
|
||||
<navigations>
|
||||
<navigation>
|
||||
<name>Notes Tutorial</name>
|
||||
<route>notestutorial.page.index</route>
|
||||
</navigation>
|
||||
</navigations>
|
||||
</info>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "nextcloud/app-tutorial",
|
||||
"description": "Nextcloud App Tutorial",
|
||||
"type": "project",
|
||||
"license": "AGPL",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Bernhard Posselt",
|
||||
"email": "dev@bernhard-posselt.com"
|
||||
}
|
||||
],
|
||||
"require": {},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.4"
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
namespace OCA\OwnNotes\Db;
|
||||
|
||||
use OCP\IDb;
|
||||
use OCP\AppFramework\Db\Mapper;
|
||||
|
||||
class NoteMapper extends Mapper {
|
||||
|
||||
public function __construct(IDb $db) {
|
||||
parent::__construct($db, 'ownnotes_notes', '\OCA\OwnNotes\Db\Note');
|
||||
}
|
||||
|
||||
public function find($id, $userId) {
|
||||
$sql = 'SELECT * FROM *PREFIX*ownnotes_notes WHERE id = ? AND user_id = ?';
|
||||
return $this->findEntity($sql, [$id, $userId]);
|
||||
}
|
||||
|
||||
public function findAll($userId) {
|
||||
$sql = 'SELECT * FROM *PREFIX*ownnotes_notes WHERE user_id = ?';
|
||||
return $this->findEntities($sql, [$userId]);
|
||||
}
|
||||
|
||||
}
|
|
@ -189,7 +189,7 @@ View.prototype = {
|
|||
}
|
||||
};
|
||||
|
||||
var notes = new Notes(OC.generateUrl('/apps/ownnotes/notes'));
|
||||
var notes = new Notes(OC.generateUrl('/apps/notestutorial/notes'));
|
||||
var view = new View(notes);
|
||||
notes.loadAll().done(function () {
|
||||
view.render();
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OwnNotes\Controller;
|
||||
namespace OCA\NotesTutorial\Controller;
|
||||
|
||||
use Closure;
|
||||
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
|
||||
use OCA\OwnNotes\Service\NotFoundException;
|
||||
use OCA\NotesTutorial\Service\NoteNotFound;
|
||||
|
||||
|
||||
trait Errors {
|
||||
|
||||
protected function handleNotFound (Closure $callback) {
|
||||
protected function handleNotFound (Closure $callback): DataResponse {
|
||||
try {
|
||||
return new DataResponse($callback());
|
||||
} catch(NotFoundException $e) {
|
||||
} catch(NoteNotFound $e) {
|
||||
$message = ['message' => $e->getMessage()];
|
||||
return new DataResponse($message, Http::STATUS_NOT_FOUND);
|
||||
}
|
|
@ -1,24 +1,29 @@
|
|||
<?php
|
||||
namespace OCA\OwnNotes\Controller;
|
||||
|
||||
namespace OCA\NotesTutorial\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\ApiController;
|
||||
|
||||
use OCA\OwnNotes\Service\NoteService;
|
||||
use OCA\NotesTutorial\Service\NoteService;
|
||||
|
||||
class NoteApiController extends ApiController {
|
||||
|
||||
/** @var NoteService */
|
||||
private $service;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
use Errors;
|
||||
|
||||
public function __construct($AppName, IRequest $request,
|
||||
NoteService $service, $UserId){
|
||||
parent::__construct($AppName, $request);
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
NoteService $service,
|
||||
$userId) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->service = $service;
|
||||
$this->userId = $UserId;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,7 +31,7 @@ class NoteApiController extends ApiController {
|
|||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function index() {
|
||||
public function index(): DataResponse {
|
||||
return new DataResponse($this->service->findAll($this->userId));
|
||||
}
|
||||
|
||||
|
@ -34,10 +39,8 @@ class NoteApiController extends ApiController {
|
|||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function show($id) {
|
||||
public function show(int $id): DataResponse {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->find($id, $this->userId);
|
||||
});
|
||||
|
@ -47,11 +50,8 @@ class NoteApiController extends ApiController {
|
|||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $content
|
||||
*/
|
||||
public function create($title, $content) {
|
||||
public function create(string $title, string $content): DataResponse {
|
||||
return $this->service->create($title, $content, $this->userId);
|
||||
}
|
||||
|
||||
|
@ -59,12 +59,9 @@ class NoteApiController extends ApiController {
|
|||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $title
|
||||
* @param string $content
|
||||
*/
|
||||
public function update($id, $title, $content) {
|
||||
public function update(int $id, string $title,
|
||||
string $content): DataResponse {
|
||||
return $this->handleNotFound(function () use ($id, $title, $content) {
|
||||
return $this->service->update($id, $title, $content, $this->userId);
|
||||
});
|
||||
|
@ -74,10 +71,8 @@ class NoteApiController extends ApiController {
|
|||
* @CORS
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function destroy($id) {
|
||||
public function destroy(int $id): DataResponse {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->delete($id, $this->userId);
|
||||
});
|
|
@ -1,39 +1,42 @@
|
|||
<?php
|
||||
namespace OCA\OwnNotes\Controller;
|
||||
namespace OCA\NotesTutorial\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Controller;
|
||||
|
||||
use OCA\OwnNotes\Service\NoteService;
|
||||
use OCA\NotesTutorial\Service\NoteService;
|
||||
|
||||
class NoteController extends Controller {
|
||||
|
||||
/** @var NoteService */
|
||||
private $service;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
|
||||
use Errors;
|
||||
|
||||
public function __construct($AppName, IRequest $request,
|
||||
NoteService $service, $UserId){
|
||||
parent::__construct($AppName, $request);
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
NoteService $service,
|
||||
$userId){
|
||||
parent::__construct($appName, $request);
|
||||
$this->service = $service;
|
||||
$this->userId = $UserId;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function index() {
|
||||
public function index(): DataResponse {
|
||||
return new DataResponse($this->service->findAll($this->userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function show($id) {
|
||||
public function show(int $id): DataResponse {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->find($id, $this->userId);
|
||||
});
|
||||
|
@ -41,22 +44,16 @@ class NoteController extends Controller {
|
|||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $content
|
||||
*/
|
||||
public function create($title, $content) {
|
||||
public function create(string $title, string $content): DataResponse {
|
||||
return $this->service->create($title, $content, $this->userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $title
|
||||
* @param string $content
|
||||
*/
|
||||
public function update($id, $title, $content) {
|
||||
public function update(int $id, string $title,
|
||||
string $content): DataResponse {
|
||||
return $this->handleNotFound(function () use ($id, $title, $content) {
|
||||
return $this->service->update($id, $title, $content, $this->userId);
|
||||
});
|
||||
|
@ -64,10 +61,8 @@ class NoteController extends Controller {
|
|||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function destroy($id) {
|
||||
public function destroy(int $id): DataResponse {
|
||||
return $this->handleNotFound(function () use ($id) {
|
||||
return $this->service->delete($id, $this->userId);
|
||||
});
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace OCA\OwnNotes\Controller;
|
||||
namespace OCA\NotesTutorial\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
|
@ -16,7 +16,7 @@
|
|||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index() {
|
||||
return new TemplateResponse('ownnotes', 'main');
|
||||
return new TemplateResponse('notestutorial', 'main');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace OCA\OwnNotes\Db;
|
||||
namespace OCA\NotesTutorial\Db;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
|
@ -11,7 +11,7 @@ class Note extends Entity implements JsonSerializable {
|
|||
protected $content;
|
||||
protected $userId;
|
||||
|
||||
public function jsonSerialize() {
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
namespace OCA\NotesTutorial\Db;
|
||||
|
||||
use OCP\IDb;
|
||||
use OCP\AppFramework\Db\Mapper;
|
||||
|
||||
class NoteMapper extends Mapper {
|
||||
|
||||
public function __construct(IDb $db) {
|
||||
parent::__construct($db, 'notestutorial', '\OCA\NotesTutorial\Db\Note');
|
||||
}
|
||||
|
||||
public function find(int $id, string $userId): Note {
|
||||
$sql = 'SELECT * FROM *PREFIX*notestutorial WHERE id = ? AND user_id = ?';
|
||||
return $this->findEntity($sql, [$id, $userId]);
|
||||
}
|
||||
|
||||
public function findAll(string $userId): array {
|
||||
$sql = 'SELECT * FROM *PREFIX*notestutorial WHERE user_id = ?';
|
||||
return $this->findEntities($sql, [$userId]);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\NotesTutorial\Service;
|
||||
|
||||
|
||||
class NoteNotFound extends \Exception {}
|
|
@ -1,31 +1,32 @@
|
|||
<?php
|
||||
namespace OCA\OwnNotes\Service;
|
||||
namespace OCA\NotesTutorial\Service;
|
||||
|
||||
use Exception;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
|
||||
use OCA\OwnNotes\Db\Note;
|
||||
use OCA\OwnNotes\Db\NoteMapper;
|
||||
use OCA\NotesTutorial\Db\Note;
|
||||
use OCA\NotesTutorial\Db\NoteMapper;
|
||||
|
||||
|
||||
class NoteService {
|
||||
|
||||
/** @var NoteMapper */
|
||||
private $mapper;
|
||||
|
||||
public function __construct(NoteMapper $mapper){
|
||||
$this->mapper = $mapper;
|
||||
}
|
||||
|
||||
public function findAll($userId) {
|
||||
public function findAll(string $userId): array {
|
||||
return $this->mapper->findAll($userId);
|
||||
}
|
||||
|
||||
private function handleException ($e) {
|
||||
private function handleException (Exception $e): void {
|
||||
if ($e instanceof DoesNotExistException ||
|
||||
$e instanceof MultipleObjectsReturnedException) {
|
||||
throw new NotFoundException($e->getMessage());
|
||||
throw new NoteNotFound($e->getMessage());
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
<phpunit bootstrap="../../lib/base.php">
|
||||
<phpunit bootstrap="tests/bootstrap.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="unit">
|
||||
<directory>./tests/integration</directory>
|
||||
<testsuite name="integration">
|
||||
<directory>./tests/Integration</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
</phpunit>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<phpunit bootstrap="tests/unit/autoloader.php">
|
||||
<phpunit bootstrap="tests/bootstrap.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="unit">
|
||||
<directory>./tests/unit</directory>
|
||||
<directory>./tests/Unit</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
</phpunit>
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OwnNotes\Service;
|
||||
|
||||
|
||||
class NotFoundException extends ServiceException {}
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OwnNotes\Service;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ServiceException extends Exception {}
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
script('ownnotes', 'handlebars');
|
||||
script('ownnotes', 'script');
|
||||
style('ownnotes', 'style');
|
||||
script('notestutorial', 'handlebars');
|
||||
script('notestutorial', 'script');
|
||||
style('notestutorial', 'style');
|
||||
?>
|
||||
|
||||
<div id="app">
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
namespace OCA\OwnNotes\Controller;
|
||||
namespace OCA\NotesTutorial\Controller;
|
||||
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\App;
|
||||
use Test\TestCase;
|
||||
|
||||
use OCA\OwnNotes\Db\Note;
|
||||
use OCA\NotesTutorial\Db\Note;
|
||||
|
||||
class NoteIntregrationTest extends TestCase {
|
||||
|
||||
|
@ -15,7 +15,7 @@ class NoteIntregrationTest extends TestCase {
|
|||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$app = new App('ownnotes');
|
||||
$app = new App('notestutorial');
|
||||
$container = $app->getContainer();
|
||||
|
||||
// only replace the user id
|
||||
|
@ -24,11 +24,11 @@ class NoteIntregrationTest extends TestCase {
|
|||
});
|
||||
|
||||
$this->controller = $container->query(
|
||||
'OCA\OwnNotes\Controller\NoteController'
|
||||
'OCA\NotesTutorial\Controller\NoteController'
|
||||
);
|
||||
|
||||
$this->mapper = $container->query(
|
||||
'OCA\OwnNotes\Db\NoteMapper'
|
||||
'OCA\NotesTutorial\Db\NoteMapper'
|
||||
);
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace OCA\OwnNotes\Controller;
|
||||
namespace OCA\NotesTutorial\Controller;
|
||||
|
||||
require_once __DIR__ . '/NoteControllerTest.php';
|
||||
|
||||
|
@ -8,7 +8,7 @@ class NoteApiControllerTest extends NoteControllerTest {
|
|||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->controller = new NoteApiController(
|
||||
'ownnotes', $this->request, $this->service, $this->userId
|
||||
'notestutorial', $this->request, $this->service, $this->userId
|
||||
);
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
namespace OCA\OwnNotes\Controller;
|
||||
namespace OCA\NotesTutorial\Controller;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
|
||||
use OCA\OwnNotes\Service\NotFoundException;
|
||||
use OCA\NotesTutorial\Service\NoteNotFound;
|
||||
|
||||
|
||||
class NoteControllerTest extends PHPUnit_Framework_TestCase {
|
||||
|
@ -18,11 +18,11 @@ class NoteControllerTest extends PHPUnit_Framework_TestCase {
|
|||
|
||||
public function setUp() {
|
||||
$this->request = $this->getMockBuilder('OCP\IRequest')->getMock();
|
||||
$this->service = $this->getMockBuilder('OCA\OwnNotes\Service\NoteService')
|
||||
$this->service = $this->getMockBuilder('OCA\NotesTutorial\Service\NoteService')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->controller = new NoteController(
|
||||
'ownnotes', $this->request, $this->service, $this->userId
|
||||
'notestutorial', $this->request, $this->service, $this->userId
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class NoteControllerTest extends PHPUnit_Framework_TestCase {
|
|||
// test the correct status code if no note is found
|
||||
$this->service->expects($this->once())
|
||||
->method('update')
|
||||
->will($this->throwException(new NotFoundException()));
|
||||
->will($this->throwException(new NoteNotFound()));
|
||||
|
||||
$result = $this->controller->update(3, 'title', 'content');
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace OCA\OwnNotes\Controller;
|
||||
namespace OCA\NotesTutorial\Controller;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
|
@ -11,7 +11,7 @@ class PageControllerTest extends PHPUnit_Framework_TestCase {
|
|||
|
||||
public function setUp() {
|
||||
$request = $this->getMockBuilder('OCP\IRequest')->getMock();
|
||||
$this->controller = new PageController('ownnotes', $request);
|
||||
$this->controller = new PageController('notestutorial', $request);
|
||||
}
|
||||
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
namespace OCA\OwnNotes\Service;
|
||||
namespace OCA\NotesTutorial\Service;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
|
||||
use OCA\OwnNotes\Db\Note;
|
||||
use OCA\NotesTutorial\Db\Note;
|
||||
|
||||
class NoteServiceTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
|
@ -14,7 +14,7 @@ class NoteServiceTest extends PHPUnit_Framework_TestCase {
|
|||
private $userId = 'john';
|
||||
|
||||
public function setUp() {
|
||||
$this->mapper = $this->getMockBuilder('OCA\OwnNotes\Db\NoteMapper')
|
||||
$this->mapper = $this->getMockBuilder('OCA\NotesTutorial\Db\NoteMapper')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->service = new NoteService($this->mapper);
|
||||
|
@ -48,7 +48,7 @@ class NoteServiceTest extends PHPUnit_Framework_TestCase {
|
|||
|
||||
|
||||
/**
|
||||
* @expectedException OCA\OwnNotes\Service\NotFoundException
|
||||
* @expectedException OCA\NotesTutorial\Service\NoteNotFound
|
||||
*/
|
||||
public function testUpdateNotFound() {
|
||||
// test the correct status code if no note is found
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
if (!defined('PHPUNIT_RUN')) {
|
||||
define('PHPUNIT_RUN', 1);
|
||||
}
|
||||
|
||||
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: .../notestutorial/tests/testcase.php"
|
||||
\OC_App::loadApp('notestutorial');
|
||||
|
||||
if(!class_exists('PHPUnit_Framework_TestCase')) {
|
||||
require_once('PHPUnit/Autoload.php');
|
||||
}
|
||||
|
||||
OC_Hook::clear();
|
|
@ -1,2 +0,0 @@
|
|||
default_charset = "UTF-8"
|
||||
always_populate_raw_post_data = -1
|
|
@ -1,52 +0,0 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/../../../../3rdparty/autoload.php';
|
||||
|
||||
|
||||
class OC {
|
||||
public static $server;
|
||||
public static $session;
|
||||
}
|
||||
|
||||
// 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, 'OC_') === 0) {
|
||||
$path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
|
||||
$relPath = __DIR__ . '/../../../../lib/private/' . $path;
|
||||
|
||||
if(file_exists($relPath)){
|
||||
require_once $relPath;
|
||||
}
|
||||
} else if(strpos($className, 'Test\\') === 0) {
|
||||
$path = strtolower(str_replace('\\', '/', substr($className, 4)) . '.php');
|
||||
$relPath = __DIR__ . '/../../../../tests/lib/' . $path;
|
||||
|
||||
if(file_exists($relPath)){
|
||||
require_once $relPath;
|
||||
}
|
||||
} else if(strpos($className, 'OC\\') === 0) {
|
||||
$path = strtolower(str_replace('\\', '/', substr($className, 2)) . '.php');
|
||||
$relPath = __DIR__ . '/../../../../lib/private' . $path;
|
||||
|
||||
if(file_exists($relPath)){
|
||||
require_once $relPath;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// create a new server instance
|
||||
OC::$server = new \OC\Server('');
|
Загрузка…
Ссылка в новой задаче