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