summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-08-21 20:36:16 -0400
committerFrederic Guillot <fred@kanboard.net>2016-08-21 20:36:16 -0400
commit1d16a53c480ea7eb93ba118f6ffd69131eb5f3c5 (patch)
tree822a3a22ce1411a1ad10665c6c7b8f3b6c2ed3b5 /tests
parent8e83e404fbb1d0dc770e5b41fa315a674541459a (diff)
Store comment sorting direction in user metadata
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Core/User/UserSessionTest.php9
-rw-r--r--tests/units/Decorator/MetadataCacheDecoratorTest.php127
2 files changed, 127 insertions, 9 deletions
diff --git a/tests/units/Core/User/UserSessionTest.php b/tests/units/Core/User/UserSessionTest.php
index 64413f98..7e9674c0 100644
--- a/tests/units/Core/User/UserSessionTest.php
+++ b/tests/units/Core/User/UserSessionTest.php
@@ -83,15 +83,6 @@ class UserSessionTest extends Base
$this->assertFalse($us->isAdmin());
}
- public function testCommentSorting()
- {
- $us = new UserSession($this->container);
- $this->assertEquals('ASC', $us->getCommentSorting());
-
- $us->setCommentSorting('DESC');
- $this->assertEquals('DESC', $us->getCommentSorting());
- }
-
public function testBoardCollapseMode()
{
$us = new UserSession($this->container);
diff --git a/tests/units/Decorator/MetadataCacheDecoratorTest.php b/tests/units/Decorator/MetadataCacheDecoratorTest.php
new file mode 100644
index 00000000..3e4dd320
--- /dev/null
+++ b/tests/units/Decorator/MetadataCacheDecoratorTest.php
@@ -0,0 +1,127 @@
+<?php
+
+use Kanboard\Decorator\MetadataCacheDecorator;
+
+require_once __DIR__.'/../Base.php';
+
+class MetadataCacheDecoratorTest extends Base
+{
+ protected $cachePrefix = 'cache_prefix';
+ protected $entityId = 123;
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $cacheMock;
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $metadataModelMock;
+
+ /**
+ * @var MetadataCacheDecorator
+ */
+ protected $metadataCacheDecorator;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->cacheMock = $this
+ ->getMockBuilder('\Kanboard\Core\Cache\MemoryCache')
+ ->setMethods(array(
+ 'set',
+ 'get',
+ ))
+ ->getMock();
+
+ $this->metadataModelMock = $this
+ ->getMockBuilder('\Kanboard\Model\UserMetadataModel')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array(
+ 'getAll',
+ 'save',
+ ))
+ ->getMock()
+ ;
+
+ $this->metadataCacheDecorator = new MetadataCacheDecorator(
+ $this->cacheMock,
+ $this->metadataModelMock,
+ $this->cachePrefix,
+ $this->entityId
+ );
+ }
+
+ public function testSet()
+ {
+ $this->cacheMock
+ ->expects($this->once())
+ ->method('set');
+
+ $this->metadataModelMock
+ ->expects($this->at(0))
+ ->method('save');
+
+ $this->metadataModelMock
+ ->expects($this->at(1))
+ ->method('getAll')
+ ->with($this->entityId)
+ ;
+
+ $this->metadataCacheDecorator->set('key', 'value');
+ }
+
+ public function testGetWithCache()
+ {
+ $this->cacheMock
+ ->expects($this->once())
+ ->method('get')
+ ->with($this->cachePrefix.$this->entityId)
+ ->will($this->returnValue(array('key' => 'foobar')))
+ ;
+
+ $this->assertEquals('foobar', $this->metadataCacheDecorator->get('key', 'default'));
+ }
+
+ public function testGetWithCacheAndDefaultValue()
+ {
+ $this->cacheMock
+ ->expects($this->once())
+ ->method('get')
+ ->with($this->cachePrefix.$this->entityId)
+ ->will($this->returnValue(array('key1' => 'foobar')))
+ ;
+
+ $this->assertEquals('default', $this->metadataCacheDecorator->get('key', 'default'));
+ }
+
+ public function testGetWithoutCache()
+ {
+ $this->cacheMock
+ ->expects($this->at(0))
+ ->method('get')
+ ->with($this->cachePrefix.$this->entityId)
+ ->will($this->returnValue(null))
+ ;
+
+ $this->cacheMock
+ ->expects($this->at(1))
+ ->method('set')
+ ->with(
+ $this->cachePrefix.$this->entityId,
+ array('key' => 'something')
+ )
+ ;
+
+ $this->metadataModelMock
+ ->expects($this->once())
+ ->method('getAll')
+ ->with($this->entityId)
+ ->will($this->returnValue(array('key' => 'something')))
+ ;
+
+ $this->assertEquals('something', $this->metadataCacheDecorator->get('key', 'default'));
+ }
+}