diff options
author | LEDfan <tobia@ledfan.be> | 2016-01-20 12:08:47 +0300 |
---|---|---|
committer | LEDfan <tobia@ledfan.be> | 2016-01-20 12:08:47 +0300 |
commit | 5fc9eb463f29351ab448a51978b6e06c5e7528e5 (patch) | |
tree | 5c44dcd334d6be4f95102b7dddc444fdee3691be /tests/integration | |
parent | 53ea997ee3180e1e3c9f03a889334c7fee6e665c (diff) |
Refactor httpbindcontrollertest + add tests for dblock
Diffstat (limited to 'tests/integration')
-rw-r--r-- | tests/integration/DbLockTest.php | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/integration/DbLockTest.php b/tests/integration/DbLockTest.php new file mode 100644 index 0000000..61ce3ca --- /dev/null +++ b/tests/integration/DbLockTest.php @@ -0,0 +1,97 @@ +<?php +namespace OCA\OJSXC; + +use OCP\AppFramework\Db\DoesNotExistException; +use Test\TestCase; +use OCA\OJSXC\AppInfo\Application; +use OCA\OJSXC\DbLock; + +function time() { + return DbLockTest::$time; +} + +/** + * @group DB + */ +class DbLockTest extends TestCase { + + /** + * @var \OCA\OJSXC\DbLock + */ + private $dbLock; + + /** + * @var \OCA\OJSXC\DbLock + */ + private $dbLock2; + + /** + * @var \OCP\IDb + */ + private $con; + + public static $time; + + public function setUp() { + parent::setUp(); + $app = new Application(); + $this->container = $app->getContainer(); + $this->con = $this->container->getServer()->getDb(); + $this->con->executeQuery("DELETE FROM `*PREFIX*preferences` WHERE `appid`='ojsxc' AND `configkey`='longpolling'"); + } + + /** + * Tests the setLock and stillLocked function by setting up and lock + * and then setting a new lock. + */ + public function testLock() { + self::$time = 4; + $this->dbLock = new DbLock( + 'john', + $this->container->getServer()->getDb(), + $this->container->getServer()->getConfig() + ); + $this->dbLock->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->dbLock->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 |