diff options
-rw-r--r-- | .travis.yml | 5 | ||||
-rw-r--r-- | tests/integration/MemLockTest.php | 94 | ||||
-rw-r--r-- | tests/travis/config-redis.json | 10 | ||||
-rw-r--r-- | tests/travis/php.ini | 3 |
4 files changed, 111 insertions, 1 deletions
diff --git a/.travis.yml b/.travis.yml index 1fa36e9..0c31549 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,9 @@ php: - 7 - hhvm +services: + - redis-server + env: global: - BRANCH=master @@ -47,6 +50,8 @@ install: - 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 + - ./occ config:import apps/ojsxc/tests/travis/config-redis.json + before_script: - cd apps/ojsxc diff --git a/tests/integration/MemLockTest.php b/tests/integration/MemLockTest.php new file mode 100644 index 0000000..465c82b --- /dev/null +++ b/tests/integration/MemLockTest.php @@ -0,0 +1,94 @@ +<?php +namespace OCA\OJSXC; + +use OCP\AppFramework\Db\DoesNotExistException; +use Test\TestCase; +use OCA\OJSXC\AppInfo\Application; +use OCA\OJSXC\MemLock; + +//function time() { +// return DbLockTest::$time; +//} + +/** + * @group DB + */ +class MemLockTest extends TestCase { + + /** + * @var \OCA\OJSXC\MemLock + */ + private $memLock; + + /** + * @var \OCA\OJSXC\MemLock + */ + private $memLock2; + + /** + * @var \OCP\AppFramework\IAppContainer + */ + private $container; + + public static $time; + + public function setUp() { + parent::setUp(); + $app = new Application(); + $this->container = $app->getContainer(); + } + + /** + * Tests the setLock and stillLocked function by setting up and lock + * and then setting a new lock. + */ + public function testLock() { + self::$time = 4; + $this->memLock = new MemLock( + 'john', + $this->container->getServer()->getMemCacheFactory() + ); + $this->memLock->setLock(); + + +// $result = $this->fetchLocks(); +// $this->assertCount(1, $result); +// $this->assertEquals($result[0]['userid'], 'john'); +// $this->assertEquals($result[0]['appid'], 'ojsxc'); +// $this->assertEquals($result[0]['configkey'], 'longpolling'); +// $this->assertEquals($result[0]['configvalue'], '4'); + $this->assertTrue($this->memLock->stillLocked()); +// +// +// self::$time = 5; +// $this->dbLock2 = new DbLock( +// 'john', +// $this->container->getServer()->getDb(), +// $this->container->getServer()->getConfig() +// ); // simulate new lock/request +// $this->dbLock2->setLock(); +// +// $this->assertFalse($this->dbLock->stillLocked()); +// $this->assertTrue($this->dbLock2->stillLocked()); +// $result = $this->fetchLocks(); +// $this->assertCount(1, $result); +// $this->assertEquals($result[0]['userid'], 'john'); +// $this->assertEquals($result[0]['appid'], 'ojsxc'); +// $this->assertEquals($result[0]['configkey'], 'longpolling'); +// $this->assertEquals($result[0]['configvalue'], '5'); +// $this->assertTrue($this->dbLock2->stillLocked()); + + } + + private function fetchLocks() { +// $stmt = $this->con->executeQuery("SELECT * FROM `*PREFIX*preferences` WHERE `appid`='ojsxc' AND `configkey`='longpolling'"); +// +// $reuslt = []; +// +// while($row = $stmt->fetch()){ +// $result[] = $row; +// } +// return $result; + } + +}
\ No newline at end of file diff --git a/tests/travis/config-redis.json b/tests/travis/config-redis.json new file mode 100644 index 0000000..603ed2e --- /dev/null +++ b/tests/travis/config-redis.json @@ -0,0 +1,10 @@ +{ + "system": { + "memcache.local": "\\OC\\Memcache\\Redis", + "redis": { + "host": "localhost", + "port": 6379, + "password": "" + } + } +} diff --git a/tests/travis/php.ini b/tests/travis/php.ini index 3b365b0..e4b4650 100644 --- a/tests/travis/php.ini +++ b/tests/travis/php.ini @@ -1,2 +1,3 @@ default_charset = "UTF-8" -always_populate_raw_post_data = -1
\ No newline at end of file +always_populate_raw_post_data = -1 +extension="redis.so"
\ No newline at end of file |