-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW Adding tests for new GraphQL mutation creator
- Loading branch information
Showing
3 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
namespace DNADesign\Elemental\Tests\GraphQL; | ||
|
||
use DNADesign\Elemental\GraphQL\SortBlockMutationCreator; | ||
use DNADesign\Elemental\Tests\Src\TestElement; | ||
use GraphQL\Type\Definition\ResolveInfo; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\Security\Security; | ||
|
||
class SortBlockMutationCreatorTest extends SapphireTest | ||
{ | ||
protected static $fixture_file = 'SortBlockMutationCreatorTest.yml'; | ||
|
||
protected static $extra_dataobjects = [ | ||
TestElement::class | ||
]; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->logInWithPermission('ADMIN'); | ||
} | ||
|
||
public function testSortBlock() | ||
{ | ||
$this->runMutation(1, 3); | ||
$this->assertIdsInOrder([2,3,1,4]); | ||
|
||
$this->runMutation(4, 2); | ||
$this->assertIdsInOrder([2,4,3,1]); | ||
|
||
$this->runMutation(1, 0); | ||
$this->assertIdsInOrder([1,2,4,3]); | ||
|
||
$this->runMutation(3, 2); | ||
$this->assertIdsInOrder([1,2,3,4]); | ||
} | ||
|
||
protected function assertIdsInOrder($ids) | ||
{ | ||
$actualIDs = TestElement::get()->sort('Sort')->map()->keys(); | ||
|
||
$this->assertSame($ids, $actualIDs); | ||
} | ||
|
||
protected function runMutation($id, $afterBlockId) | ||
{ | ||
$member = Security::getCurrentUser(); | ||
|
||
$mutation = new SortBlockMutationCreator(); | ||
$context = ['currentUser' => $member]; | ||
$resolveInfo = new ResolveInfo([]); | ||
|
||
$mutation->resolve(null, [ | ||
'ID' => $id, | ||
'AfterBlockID' => $afterBlockId, | ||
], $context, $resolveInfo); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
DNADesign\Elemental\Tests\Src\TestElement: | ||
element1: | ||
ID: 1 | ||
Sort: 1 | ||
element2: | ||
ID: 2 | ||
Sort: 2 | ||
element3: | ||
ID: 3 | ||
Sort: 3 | ||
element4: | ||
ID: 4 | ||
Sort: 4 |