Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/jsxc.nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLEDfan <tobia@ledfan.be>2016-01-29 14:33:22 +0300
committerLEDfan <tobia@ledfan.be>2016-02-02 10:08:30 +0300
commitd2bf3d7bf45ee15949eb15a775a5c8c74000cb03 (patch)
treefbc609fc6451fd09813a25ba38c61eac9a3bd97d
parent589453df3a6eee1bf0ef457925eb14a79caa225e (diff)
- Remove HHVM tests
- add tests for stable8, stable8.1, stable8.2 and master - fix some unit tests so they don't produce errors - add extra bootstrap files for both integratoin and unit tests - disable incomplete tests which causes errors - Support ownCloud 8.0 - disable MemLock in version 8.0 since the API isn't very usable - use own getServerHost when the method doesn't exists - add namespace declartion in infox.ml - remove unused OCP\ISession in HttpBindController - use IDbConnection in tests - use prepareQuery() when using OCP\IDb
-rw-r--r--.travis.yml63
-rwxr-xr-xappinfo/app.php2
-rw-r--r--appinfo/application.php56
-rwxr-xr-xappinfo/info.xml1
-rw-r--r--appinfo/routes.php10
-rw-r--r--lib/controller/httpbindcontroller.php32
-rw-r--r--lib/db/stanzamapper.php6
-rw-r--r--phpunit.integration.xml2
-rw-r--r--phpunit.xml2
-rw-r--r--tests/bootstrap-integration.php8
-rw-r--r--tests/bootstrap-unit.php3
-rw-r--r--tests/bootstrap.php3
-rw-r--r--tests/integration/DbLockTest.php2
-rw-r--r--tests/integration/MemLockTest.php6
-rw-r--r--tests/travis/config-apcu.json5
-rwxr-xr-xtests/travis/install-master.sh24
-rwxr-xr-xtests/travis/install-stable8.1.sh21
-rwxr-xr-xtests/travis/install-stable8.2.sh21
-rwxr-xr-xtests/travis/install-stable8.sh23
-rw-r--r--tests/travis/php.ini1
-rw-r--r--tests/unit/controller/HttpBindControllerTest.php27
21 files changed, 220 insertions, 98 deletions
diff --git a/.travis.yml b/.travis.yml
index fddefad..155c92e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,10 +1,10 @@
+sudo: required
language: php
php:
- 5.4
- 5.5
- 5.6
- 7
- - hhvm
services:
- redis-server
@@ -16,65 +16,24 @@ env:
- DB=mysql
matrix:
- allow_failures:
- - php: hhvm
include:
- php: 5.4
env: DB=sqlite
- php: 5.4
env: DB=pgsql
+ - php: 5.6
+ env: DB=mysql BRANCH=stable8
+ - php: 5.6
+ env: DB=mysql BRANCH=stable8.1
+ - php: 5.6
+ env: DB=mysql BRANCH=stable8.2
-install:
- # install ocdev
- - sudo apt-get update
- - 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' IDENTIFIED BY '';"
- - 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 jsxc.chat owncloud/apps/ojsxc
- - |
- if [[ $TRAVIS_PHP_VERSION = "hhv"* ]]; then
- echo "PHP7"
- else
- phpenv config-add owncloud/apps/ojsxc/tests/travis/php.ini
- fi
- - cd owncloud
- - ./occ maintenance:install --database-name oc_autotest --database-user oc_autotest --database-pass --admin-user admin --admin-pass admin --database $DB
- - ./occ app:enable ojsxc
- - pear config-set preferred_state beta
- - yes '' | pecl install apcu-4.0.10
-
-
-
-before_script:
- - cd apps/ojsxc
- - composer install
+install: ./tests/travis/install-$BRANCH.sh
+# Note the install script should make sure we are in the apps/ojsxc directory
script:
- - cd ../../
- - ./occ config:import apps/ojsxc/tests/travis/config-redis.json
- - cd apps/ojsxc
+ - composer install
- phpunit -c phpunit.xml
- phpunit -c phpunit.integration.xml
- - cd ../../
- - ./occ config:system:delete 'memcache.local'
- - ./occ config:system:delete 'redis'
- - |
- if [[ $TRAVIS_PHP_VERSION = "hhv"* ]]; then
- echo "PHP7"
- else
- ./occ config:import apps/ojsxc/tests/travis/config-apcu.json
- cd apps/ojsxc
- phpunit -c phpunit.xml
- phpunit -c phpunit.integration.xml
- cat ../../data/owncloud.log
- fi \ No newline at end of file
+ - cat ../../data/owncloud.log
diff --git a/appinfo/app.php b/appinfo/app.php
index 71fd8e2..288cc54 100755
--- a/appinfo/app.php
+++ b/appinfo/app.php
@@ -36,4 +36,4 @@ if(class_exists('\\OCP\\AppFramework\\Http\\EmptyContentSecurityPolicy')) {
require_once __DIR__ ."/../vendor/autoload.php";
-?>
+?> \ No newline at end of file
diff --git a/appinfo/application.php b/appinfo/application.php
index 8e7e1ee..58f4a77 100644
--- a/appinfo/application.php
+++ b/appinfo/application.php
@@ -33,7 +33,6 @@ class Application extends App {
$c->query('AppName'),
$c->query('Request'),
$c->query('UserId'),
- $c->query('OCP\ISession'),
$c->query('StanzaMapper'),
$c->query('IQHandler'),
$c->query('MessageHandler'),
@@ -85,7 +84,12 @@ class Application extends App {
* Config values
*/
$container->registerService('Host', function($c){
- return $c->query('Request')->getServerHost();
+ $request = $c->query('Request');
+ if (method_exists($request, 'getServerHost')) {
+ return $c->query('Request')->getServerHost();
+ } else {
+ return $this->getServerHost();
+ }
});
}
@@ -97,8 +101,10 @@ class Application extends App {
$c = $this->getContainer();
if (self::$config['use_memcache']['locking'] === true) {
$cache = $c->getServer()->getMemCacheFactory();
-
- if ($cache->isAvailable()) {
+ $version = \OC::$server->getSession()->get('OC_Version');
+ if ($version[0] === 8 && $version[1] == 0){
+ $c->getServer()->getLogger()->warning('OJSXC is configured to use memcache as backend for locking, but ownCloud version 8 doesn\'t suppor this.');
+ } else if ($cache->isAvailable()) {
$memcache = $cache->create('ojsxc');
return new MemLock(
$c->query('UserId'),
@@ -117,5 +123,47 @@ class Application extends App {
);
}
+
+ /**
+ * Helper function
+ * https://github.com/owncloud/core/blob/a977465af5834a76b1e98854a2c9bfbe413c218c/lib/private/appframework/http/request.php#L518
+ * @return string
+ */
+ private function getServerHost() {
+ $host = 'localhost';
+ if (isset($this->server['HTTP_X_FORWARDED_HOST'])) {
+ if (strpos($this->server['HTTP_X_FORWARDED_HOST'], ',') !== false) {
+ $parts = explode(',', $this->server['HTTP_X_FORWARDED_HOST']);
+ $host = trim(current($parts));
+ } else {
+ $host = $this->server['HTTP_X_FORWARDED_HOST'];
+ }
+ } else {
+ if (isset($this->server['HTTP_HOST'])) {
+ $host = $this->server['HTTP_HOST'];
+ } else if (isset($this->server['SERVER_NAME'])) {
+ $host = $this->server['SERVER_NAME'];
+ }
+ }
+ if ($host !== null) {
+ return $host;
+ }
+ // get the host from the headers
+ $host = $this->getInsecureServerHost();
+ // Verify that the host is a trusted domain if the trusted domains
+ // are defined
+ // If no trusted domain is provided the first trusted domain is returned
+ $trustedDomainHelper = new TrustedDomainHelper($this->config);
+ if ($trustedDomainHelper->isTrustedDomain($host)) {
+ return $host;
+ } else {
+ $trustedList = $this->config->getSystemValue('trusted_domains', []);
+ if(!empty($trustedList)) {
+ return $trustedList[0];
+ } else {
+ return '';
+ }
+ }
+ }
} \ No newline at end of file
diff --git a/appinfo/info.xml b/appinfo/info.xml
index ae9d1b4..f76e614 100755
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -11,4 +11,5 @@
<bugs>http://github.com/jsxc/jsxc/issues</bugs>
<repository type="git">http://github.com/jsxc/jsxc.owncloud.git</repository>
<ocsid>162257</ocsid>
+ <namespace>OJSXC</namespace>
</info>
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 49ccf51..45a5c94 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -12,23 +12,23 @@ use \OCA\OJSXC\AppInfo\Application;
$this->create('ojsxc_ajax_getsettings', 'ajax/getsettings.php')
->actionInclude('ojsxc/ajax/getsettings.php');
-
+
$this->create('ojsxc_ajax_getturncredentials', 'ajax/getturncredentials.php')
->actionInclude('ojsxc/ajax/getturncredentials.php');
-
+
$this->create('ojsxc_ajax_setsettings', 'ajax/setsettings.php')
->actionInclude('ojsxc/ajax/setsettings.php');
-
+
$this->create('ojsxc_ajax_setUserSettings', 'ajax/setUserSettings.php')
->actionInclude('ojsxc/ajax/setUserSettings.php');
$this->create('ojsxc_ajax_getUsers', 'ajax/getUsers.php')
->actionInclude('ojsxc/ajax/getUsers.php');
-
+
$application = new Application();
$application->registerRoutes($this, array(
'routes' => array(
- array('name' => 'http_bind#index', 'url' => '/http-bind', 'verb' => array('GET', 'POST')),
+ array('name' => 'http_bind#index', 'url' => '/http-bind', 'verb' => 'POST'),
)
));
?>
diff --git a/lib/controller/httpbindcontroller.php b/lib/controller/httpbindcontroller.php
index 19f55cc..4bcf71d 100644
--- a/lib/controller/httpbindcontroller.php
+++ b/lib/controller/httpbindcontroller.php
@@ -113,7 +113,6 @@ class HttpBindController extends Controller {
public function __construct($appName,
IRequest $request,
$userId,
- ISession $session,
StanzaMapper $stanzaMapper,
IQ $iqHandler,
Message $messageHandler,
@@ -126,7 +125,6 @@ class HttpBindController extends Controller {
parent::__construct($appName, $request);
$this->userId = $userId;
$this->pollingId = time();
- $this->session = $session;
$this->stanzaMapper = $stanzaMapper;
$this->host = $host;
$this->iqHandler = $iqHandler;
@@ -147,7 +145,7 @@ class HttpBindController extends Controller {
$this->lock->setLock();
$input = $this->body;
$longpoll = true; // set to false when the response should directly be returned and no polling should be done
- if (!empty($input)){
+ if (!empty($input)) {
// replace invalid XML by valid XML one
$input = str_replace("<vCard xmlns='vcard-temp'/>", "<vCard xmlns='jabber:vcard-temp'/>", $input);
$reader = new Reader();
@@ -155,22 +153,24 @@ class HttpBindController extends Controller {
$reader->elementMap = [
'{jabber:client}message' => 'Sabre\Xml\Element\KeyValue',
];
-
+ $stanzas = null;
try {
$stanzas = $reader->parse();
- } catch (LibXMLException $e){
+ } catch (LibXMLException $e) {
}
- $stanzas = $stanzas['value'];
- if (is_array($stanzas)) {
- foreach ($stanzas as $stanza) {
- $stanzaType = $this->getStanzaType($stanza);
- if ($stanzaType === self::MESSAGE) {
- $this->messageHandler->handle($stanza);
- } else if ($stanzaType === self::IQ) {
- $result = $this->iqHandler->handle($stanza);
- if (!is_null($result)) {
- $longpoll = false;
- $this->response->write($result);
+ if (!is_null($stanzas)) {
+ $stanzas = $stanzas['value'];
+ if (is_array($stanzas)) {
+ foreach ($stanzas as $stanza) {
+ $stanzaType = $this->getStanzaType($stanza);
+ if ($stanzaType === self::MESSAGE) {
+ $this->messageHandler->handle($stanza);
+ } else if ($stanzaType === self::IQ) {
+ $result = $this->iqHandler->handle($stanza);
+ if (!is_null($result)) {
+ $longpoll = false;
+ $this->response->write($result);
+ }
}
}
}
diff --git a/lib/db/stanzamapper.php b/lib/db/stanzamapper.php
index c112458..e9f3f8d 100644
--- a/lib/db/stanzamapper.php
+++ b/lib/db/stanzamapper.php
@@ -6,6 +6,7 @@ use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\Mapper;
use OCP\IDb;
+use OCP\IDBConnection;
use Sabre\Xml\Writer;
/**
@@ -38,7 +39,7 @@ class StanzaMapper extends Mapper {
$writer->write($entity);
$xml = $writer->outputMemory();
$sql = "INSERT INTO `*PREFIX*ojsxc_stanzas` (`to`, `from`, `stanza`) VALUES(?,?,?)";
- $q = $this->db->prepare($sql);
+ $q = $this->db->prepareQuery($sql);
$q->execute([$entity->getTo(), $entity->getFrom(), $xml]);
}
@@ -52,7 +53,7 @@ class StanzaMapper extends Mapper {
$stmt = $this->execute("SELECT stanza, id FROM *PREFIX*ojsxc_stanzas WHERE `to`=?", [$to]);
$results = [];
while($row = $stmt->fetch()){
- $row['stanza'] =preg_replace('/to="([a-zA-z]*)"/', "to=\"$1@" .$this->host ."\"", $row['stanza']);
+ $row['stanza'] = preg_replace('/to="([a-zA-z]*)"/', "to=\"$1@" .$this->host ."\"", $row['stanza']);
$row['stanza'] = preg_replace('/from="([a-zA-z]*)"/', "from=\"$1@" .$this->host ."\"", $row['stanza']);
$results[] = $this->mapRowToEntity($row);
}
@@ -65,6 +66,7 @@ class StanzaMapper extends Mapper {
foreach($results as $result){
$this->delete($result);
}
+
return $results;
}
diff --git a/phpunit.integration.xml b/phpunit.integration.xml
index 489898a..6d99d05 100644
--- a/phpunit.integration.xml
+++ b/phpunit.integration.xml
@@ -1,4 +1,4 @@
-<phpunit bootstrap="tests/bootstrap.php"
+<phpunit bootstrap="tests/bootstrap-integration.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
diff --git a/phpunit.xml b/phpunit.xml
index 41a4754..3881fa2 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,4 +1,4 @@
-<phpunit bootstrap="../../lib/base.php"
+<phpunit bootstrap="tests/bootstrap-unit.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
diff --git a/tests/bootstrap-integration.php b/tests/bootstrap-integration.php
new file mode 100644
index 0000000..22a433d
--- /dev/null
+++ b/tests/bootstrap-integration.php
@@ -0,0 +1,8 @@
+<?php
+try {
+ require_once __DIR__ . '/../../../tests/bootstrap.php';
+} catch (Exception $ex) {
+ require_once __DIR__ . '/../../../lib/base.php';
+
+}
+require_once __DIR__ . '/../vendor/autoload.php'; \ No newline at end of file
diff --git a/tests/bootstrap-unit.php b/tests/bootstrap-unit.php
new file mode 100644
index 0000000..3ccb8db
--- /dev/null
+++ b/tests/bootstrap-unit.php
@@ -0,0 +1,3 @@
+<?php
+require_once __DIR__ . '/../../../lib/base.php';
+require_once __DIR__ . '/../vendor/autoload.php'; \ No newline at end of file
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
deleted file mode 100644
index 41d18f3..0000000
--- a/tests/bootstrap.php
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-require_once __DIR__ . '/../../../tests/bootstrap.php';
-require_once __DIR__ . '/../vendor/autoload.php'; \ No newline at end of file
diff --git a/tests/integration/DbLockTest.php b/tests/integration/DbLockTest.php
index e294f43..f378537 100644
--- a/tests/integration/DbLockTest.php
+++ b/tests/integration/DbLockTest.php
@@ -37,7 +37,7 @@ class DbLockTest extends TestCase {
parent::setUp();
$app = new Application();
$this->container = $app->getContainer();
- $this->con = $this->container->getServer()->getDb();
+ $this->con = $this->container->getServer()->getDatabaseConnection();
$this->con->executeQuery("DELETE FROM `*PREFIX*preferences` WHERE `appid`='ojsxc' AND `configkey`='longpolling'");
}
diff --git a/tests/integration/MemLockTest.php b/tests/integration/MemLockTest.php
index e1d04f1..3ab1c16 100644
--- a/tests/integration/MemLockTest.php
+++ b/tests/integration/MemLockTest.php
@@ -41,6 +41,12 @@ class MemLockTest extends TestCase {
parent::setUp();
$app = new Application();
$this->container = $app->getContainer();
+
+ $version = \OC::$server->getSession()->get('OC_Version');
+ if ($version[0] === 8 && $version[1] == 0) {
+ $this->markTestSkipped();
+ }
+
}
/**
diff --git a/tests/travis/config-apcu.json b/tests/travis/config-apcu.json
deleted file mode 100644
index c01f280..0000000
--- a/tests/travis/config-apcu.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "system": {
- "memcache.local" : "\\OC\\Memcache\\APCu"
- }
-}
diff --git a/tests/travis/install-master.sh b/tests/travis/install-master.sh
new file mode 100755
index 0000000..9d67555
--- /dev/null
+++ b/tests/travis/install-master.sh
@@ -0,0 +1,24 @@
+#!/bin/bash -x
+# install ocdev
+sudo apt-get update
+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' IDENTIFIED BY '';"
+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 jsxc.chat owncloud/apps/ojsxc
+phpenv config-add owncloud/apps/ojsxc/tests/travis/php.ini
+cd owncloud
+./occ maintenance:install --database-name oc_autotest --database-user oc_autotest --database-pass --admin-user admin --admin-pass admin --database $DB
+./occ app:enable ojsxc
+
+# before_script:
+./occ config:import apps/ojsxc/tests/travis/config-redis.json
+cd apps/ojsxc
diff --git a/tests/travis/install-stable8.1.sh b/tests/travis/install-stable8.1.sh
new file mode 100755
index 0000000..ad016a3
--- /dev/null
+++ b/tests/travis/install-stable8.1.sh
@@ -0,0 +1,21 @@
+#!/bin/bash -x
+# install ocdev
+sudo apt-get update
+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' IDENTIFIED BY '';"
+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 jsxc.chat owncloud/apps/ojsxc
+phpenv config-add owncloud/apps/ojsxc/tests/travis/php.ini
+cd owncloud
+./occ maintenance:install --database-name oc_autotest --database-user oc_autotest --database-pass --admin-user admin --admin-pass admin --database $DB
+./occ app:enable ojsxc
+cd apps/ojsxc \ No newline at end of file
diff --git a/tests/travis/install-stable8.2.sh b/tests/travis/install-stable8.2.sh
new file mode 100755
index 0000000..1816548
--- /dev/null
+++ b/tests/travis/install-stable8.2.sh
@@ -0,0 +1,21 @@
+#!/bin/bash -x
+# install ocdev
+sudo apt-get update
+sudo apt-get -y install python3-jinja2 python3-setuptools
+sudo easy_install3 requests
+sudo easy_install3 ocdev
+# set up postgresql
+reateuser -U travis -s oc_autotest
+# set up mysql
+mysql -e 'create database oc_autotest;'
+mysql -u root -e "CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY '';"
+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 jsxc.chat owncloud/apps/ojsxc
+phpenv config-add owncloud/apps/ojsxc}/tests/travis/php.ini
+cd owncloud
+./occ maintenance:install --database-name oc_autotest --database-user oc_autotest --database-pass --admin-user admin --admin-pass admin --database $DB
+./occ app:enable ojsxc
+cd apps/ojsxc
diff --git a/tests/travis/install-stable8.sh b/tests/travis/install-stable8.sh
new file mode 100755
index 0000000..a0ce189
--- /dev/null
+++ b/tests/travis/install-stable8.sh
@@ -0,0 +1,23 @@
+#!/bin/bash -x
+# install ocdev
+sudo apt-get update
+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
+cd owncloud
+ocdev ci $DB
+#enable ojsxc
+mv ../jsxc.chat apps/ojsxc
+php -f console.php app:enable ojsxc
+
+cd apps/ojsxc
+
diff --git a/tests/travis/php.ini b/tests/travis/php.ini
index 4e6415b..cdba47f 100644
--- a/tests/travis/php.ini
+++ b/tests/travis/php.ini
@@ -1,4 +1,3 @@
default_charset = "UTF-8"
always_populate_raw_post_data = -1
extension="redis.so"
-extension="apc.so" \ No newline at end of file
diff --git a/tests/unit/controller/HttpBindControllerTest.php b/tests/unit/controller/HttpBindControllerTest.php
index 40c4507..7ae6931 100644
--- a/tests/unit/controller/HttpBindControllerTest.php
+++ b/tests/unit/controller/HttpBindControllerTest.php
@@ -62,7 +62,6 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase {
*/
private function setUpController($requestBody) {
$request = $this->getMockBuilder('OCP\IRequest')->disableOriginalConstructor()->getMock();
- $session = $this->getMockBuilder('OCP\ISession')->disableOriginalConstructor()->getMock();
$this->stanzaMapper = $this->getMockBuilder('OCA\OJSXC\Db\StanzaMapper')->disableOriginalConstructor()->getMock();
$this->iqHandler = $this->getMockBuilder('OCA\OJSXC\StanzaHandlers\IQ')->disableOriginalConstructor()->getMock();
@@ -73,7 +72,6 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase {
'ojsxc',
$request,
$this->userId,
- $session,
$this->stanzaMapper,
$this->iqHandler,
$this->messageHandler,
@@ -87,6 +85,9 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase {
/**
* When invalid XML, just start long polling.
+ * Note: this test will cause some errors in the owncloud.log:
+ * {"reqId":"HmbEV6qTWF68ii1G\/kz1","remoteAddr":"","app":"PHP","message":"XMLReader::read(): An Error Occured while reading at \/var\/www\/owncloud\/apps\/ojsxc\/vendor\/sabre\/xml\/lib\/Reader.php#66","level":0,"time":"2016-01-30T14:52:44+00:00","method":"--","url":"--"}
+ * {"reqId":"HmbEV6qTWF68ii1G\/kz1","remoteAddr":"","app":"PHP","message":"XMLReader::read(): An Error Occured while reading at \/var\/www\/owncloud\/apps\/ojsxc\/vendor\/sabre\/xml\/lib\/Reader.php#145","level":0,"time":"2016-01-30T14:52:44+00:00","method":"--","url":"--"}
*/
public function testInvalidXML() {
$ex = new DoesNotExistException('');
@@ -136,7 +137,7 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase {
* @dataProvider IQProvider
*/
public function testIQHandlerWhenNoDbResults($body, $result, $expected, $pollCount, $handlerCount) {
- $ex = new DoesNotExistException();
+ $ex = new DoesNotExistException('');
$this->setUpController($body);
$this->mockLock();
$expResponse = new XMPPResponse();
@@ -189,7 +190,7 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase {
public function testMessageNoDbHandler() {
$body = '<body rid=\'897878959\' xmlns=\'http://jabber.org/protocol/httpbind\' sid=\'7862\'><message to=\'derp@own.dev\' type=\'chat\' id=\'1452960296859-msg\' xmlns=\'jabber:client\'><body>abc</body><request xmlns=\'urn:xmpp:receipts\'/></message></body>';
- $ex = new DoesNotExistException();
+ $ex = new DoesNotExistException('');
$this->setUpController($body);
$this->mockLock();
@@ -217,7 +218,7 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase {
<message to='derp@own.dev' type='chat' id='1452960296861-msg' xmlns='jabber:client'><body>abc3</body></message>
</body>
XML;
- $ex = new DoesNotExistException();
+ $ex = new DoesNotExistException('');
$this->setUpController($body);
$this->mockLock();
@@ -294,7 +295,12 @@ XML;
$this->assertEquals($expResponse->render(), $response->render());
}
+ /**
+ * @TODO implement tests
+ */
public function testPresenceHandler() {
+ $this->markTestSkipped();
+ $this->markTestIncomplete();
$body = '<body rid=\'897878985\' xmlns=\'http://jabber.org/protocol/httpbind\' sid=\'7862\'><presence xmlns=\'jabber:client\'><c xmlns=\'http://jabber.org/protocol/caps\' hash=\'sha-1\' node=\'http://jsxc.org/\' ver=\'u2kAg/CbVmVZhsu+lZrkuLLdO+0=\'/><show>chat</show></presence></body>';
$this->setUpController($body);
$this->mockLock();
@@ -303,11 +309,20 @@ XML;
}
public function testBodyHandler() {
+ $ex = new DoesNotExistException('');
$body = '<body rid=\'897878985\' xmlns=\'http://jabber.org/protocol/httpbind\' sid=\'7862\'/>';
$this->setUpController($body);
$this->mockLock();
+ $expResponse = new XMPPResponse();
- $this->controller->index();
+ $this->stanzaMapper->expects($this->exactly(10))
+ ->method('findByTo')
+ ->with('john')
+ ->will($this->throwException($ex));
+
+ $response = $this->controller->index();
+ $this->assertEquals($expResponse, $response);
+ $this->assertEquals($expResponse->render(), $response->render());
}
}