SortBlockMutationCreatorTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 22
c 2
b 0
f 0
dl 0
loc 45
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testSortBlock() 0 13 1
A runMutation() 0 12 1
A assertIdsInOrder() 0 5 1
1
<?php
2
3
namespace DNADesign\Elemental\Tests\GraphQL;
4
5
use DNADesign\Elemental\GraphQL\SortBlockMutationCreator;
6
use DNADesign\Elemental\Tests\Src\TestElement;
7
use GraphQL\Type\Definition\ResolveInfo;
8
use SilverStripe\Dev\SapphireTest;
9
use SilverStripe\Security\Security;
10
11
class SortBlockMutationCreatorTest extends SapphireTest
12
{
13
    protected static $fixture_file = 'SortBlockMutationCreatorTest.yml';
14
15
    protected static $extra_dataobjects = [
16
        TestElement::class,
17
    ];
18
19
    /**
20
     * Reorders blocks by compounding each result into the next test (rather than isolated sorting tests)
21
     */
22
    public function testSortBlock()
23
    {
24
        $this->runMutation(1, 3);
25
        $this->assertIdsInOrder([2, 3, 1, 4]);
26
27
        $this->runMutation(4, 2);
28
        $this->assertIdsInOrder([2, 4, 3, 1]);
29
30
        $this->runMutation(1, 0);
31
        $this->assertIdsInOrder([1, 2, 4, 3]);
32
33
        $this->runMutation(3, 2);
34
        $this->assertIdsInOrder([1, 2, 3, 4]);
35
    }
36
37
    protected function assertIdsInOrder($ids)
38
    {
39
        $actualIDs = TestElement::get()->sort('Sort')->map()->keys();
40
41
        $this->assertSame($ids, $actualIDs);
42
    }
43
44
    protected function runMutation($id, $afterBlockId)
45
    {
46
        $member = Security::getCurrentUser();
47
48
        $mutation = new SortBlockMutationCreator();
49
        $context = ['currentUser' => $member];
50
        $resolveInfo = new ResolveInfo([]);
51
52
        $mutation->resolve(null, [
53
            'ID' => $id,
54
            'AfterBlockID' => $afterBlockId,
55
        ], $context, $resolveInfo);
56
    }
57
}
58