1 | <?php |
||
2 | |||
3 | namespace DNADesign\Elemental\Tests\GraphQL; |
||
4 | |||
5 | use DNADesign\Elemental\GraphQL\Resolvers\Resolver; |
||
6 | use DNADesign\Elemental\Models\ElementalArea; |
||
7 | use DNADesign\Elemental\Tests\Src\TestElement; |
||
8 | use InvalidArgumentException; |
||
9 | use SilverStripe\Dev\SapphireTest; |
||
10 | use SilverStripe\GraphQL\Schema\Schema; |
||
0 ignored issues
–
show
|
|||
11 | use SilverStripe\Security\Security; |
||
12 | |||
13 | class AddElementToAreaMutationTest extends SapphireTest |
||
14 | { |
||
15 | protected static $fixture_file = 'AddElementToAreaMutationTest.yml'; |
||
16 | |||
17 | protected static $extra_dataobjects = [ |
||
18 | TestElement::class, |
||
19 | ]; |
||
20 | |||
21 | protected function setUp(): void |
||
22 | { |
||
23 | parent::setUp(); |
||
24 | if (!class_exists(Schema::class)) { |
||
25 | $this->markTestSkipped('Skipped GraphQL 4 test ' . __CLASS__); |
||
26 | } |
||
27 | } |
||
28 | |||
29 | public function testAddingBlocksInOrder() |
||
30 | { |
||
31 | $className = TestElement::class; |
||
32 | $areaID = $this->objFromFixture(ElementalArea::class, 'one')->ID; |
||
33 | |||
34 | $one = $this->runMutation($className, $areaID)->ID; |
||
35 | $this->assertIdsInOrder([$one], 'The first element is added'); |
||
36 | |||
37 | $two = $this->runMutation($className, $areaID, $one)->ID; |
||
38 | $this->assertIdsInOrder([$one, $two], 'The second element is added after the first'); |
||
39 | |||
40 | $three = $this->runMutation($className, $areaID, $one)->ID; |
||
41 | $this->assertIdsInOrder([$one, $three, $two], 'The third element is added after the first'); |
||
42 | |||
43 | $four = $this->runMutation($className, $areaID)->ID; |
||
44 | $this->assertIdsInOrder( |
||
45 | [$one, $three, $two, $four], |
||
46 | 'The fourth element is added last, when no after ID parameter is given' |
||
47 | ); |
||
48 | |||
49 | $five = $this->runMutation($className, $areaID, 0)->ID; |
||
50 | $this->assertIdsInOrder([$five, $one, $three, $two, $four], 'The fifth element is added first, after ID 0'); |
||
51 | } |
||
52 | |||
53 | public function testBadElementalArea() |
||
54 | { |
||
55 | $this->expectException(InvalidArgumentException::class); |
||
56 | $areaID = $this->objFromFixture(ElementalArea::class, 'one')->ID; |
||
57 | $this->runMutation(TestElement::class, $areaID + 1); |
||
58 | } |
||
59 | |||
60 | public function testOrderingByWrongElementalArea() |
||
61 | { |
||
62 | $this->expectException(InvalidArgumentException::class); |
||
63 | $firstArea = ElementalArea::get()->first(); |
||
64 | $elementInFirstArea = TestElement::create(); |
||
65 | $firstArea->Elements()->add($elementInFirstArea); |
||
66 | |||
67 | ElementalArea::create()->write(); |
||
68 | $this->runMutation(TestElement::class, 2, $elementInFirstArea->ID); |
||
69 | } |
||
70 | |||
71 | protected function assertIdsInOrder($ids, $message = null) |
||
72 | { |
||
73 | $actualIDs = TestElement::get()->sort('Sort')->map()->keys(); |
||
74 | // Ideally this should be assertSame, but sometimes the database |
||
75 | // returns IDs as strings instead of integers (e.g. "1" instead of 1). |
||
76 | $this->assertEquals($ids, $actualIDs, $message); |
||
77 | } |
||
78 | |||
79 | protected function runMutation($className, $elementalAreaID, $afterElementId = null) |
||
80 | { |
||
81 | $context = ['currentUser' => Security::getCurrentUser()]; |
||
82 | $resolveInfo = new FakeResolveInfo(); |
||
83 | |||
84 | $args = [ |
||
85 | 'className' => $className, |
||
86 | 'elementalAreaID' => $elementalAreaID, |
||
87 | ]; |
||
88 | |||
89 | if (!is_null($afterElementId)) { |
||
90 | $args['afterElementID'] = $afterElementId; |
||
91 | } |
||
92 | |||
93 | return Resolver::resolveAddElementToArea(null, $args, $context, $resolveInfo); |
||
94 | } |
||
95 | } |
||
96 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths