Add stack sorting functionality

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2017-05-23 18:09:42 +02:00
parent fbc12ae8f7
commit b6d94ec9ff
9 changed files with 141 additions and 9 deletions

View File

@@ -158,7 +158,34 @@ class StackServiceTest extends \PHPUnit_Framework_TestCase {
$stack->setOrder(1);
$result = $this->stackService->update(123, 'Foo', 2, 1);
$this->assertEquals($stack, $result);
}
public function testReorder() {
$this->permissionService->expects($this->once())->method('checkPermission');
$a = $this->createStack(1, 0);
$b = $this->createStack(2, 1);
$c = $this->createStack(3, 2);
$stacks = [$a, $b, $c];
$this->stackMapper->expects($this->once())
->method('find')
->with(1)
->willReturn($a);
$this->stackMapper->expects($this->once())
->method('findAll')
->willReturn($stacks);
$actual = $this->stackService->reorder(1, 2);
$a = $this->createStack(1, 2);
$b = $this->createStack(2, 0);
$c = $this->createStack(3, 1);
$expected = [$b, $c, $a];
$this->assertEquals($expected, $actual);
}
private function createStack($id, $order) {
$stack = new Stack();
$stack->setId($id);
$stack->setOrder($order);
return $stack;
}
}