-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aaron Carlino
committed
Aug 1, 2021
1 parent
0049f7f
commit 01f8c23
Showing
19 changed files
with
470 additions
and
110 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
29 changes: 0 additions & 29 deletions
29
src/Schema/DataObject/Plugin/DBFieldArgs/DBCurrencyArgs.php
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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
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
55 changes: 55 additions & 0 deletions
55
tests/Schema/DataObject/Plugin/DBFieldArgs/DBDateArgsTest.php
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,55 @@ | ||
<?php | ||
|
||
namespace SilverStripe\GraphQL\Tests\Schema\DataObject\Plugin\DBFieldArgs; | ||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\GraphQL\Schema\DataObject\DataObjectModel; | ||
use SilverStripe\GraphQL\Schema\DataObject\Plugin\DBFieldArgs\DBDateArgs; | ||
use SilverStripe\GraphQL\Schema\Field\ModelField; | ||
use SilverStripe\GraphQL\Schema\SchemaConfig; | ||
use SilverStripe\GraphQL\Tests\Fake\DataObjectFake; | ||
use SilverStripe\ORM\FieldType\DBDate; | ||
use SilverStripe\ORM\FieldType\DBField; | ||
|
||
class DBDateArgsTest extends SapphireTest | ||
{ | ||
public function testApply() | ||
{ | ||
$field = new ModelField('test', [], new DataObjectModel(DataObjectFake::class, new SchemaConfig())); | ||
$factory = new DBDateArgs(); | ||
$factory->applyToField($field); | ||
$args = $field->getArgs(); | ||
|
||
$this->assertArrayHasKey('format', $args); | ||
$arg = $args['format']; | ||
$this->assertEquals($factory->getEnum()->getName(), $arg->getType()); | ||
|
||
$this->assertArrayHasKey('customFormat', $args); | ||
$arg = $args['customFormat']; | ||
$this->assertEquals('String', $arg->getType()); | ||
} | ||
|
||
public function testResolve() | ||
{ | ||
$fake = $this->getMockBuilder(DBDate::class) | ||
->setMethods(['Nice']) | ||
->getMock(); | ||
$fake->expects($this->once()) | ||
->method('Nice'); | ||
|
||
DBDateArgs::resolve($fake, ['format' => 'Nice']); | ||
|
||
$date = DBField::create_field('Date', '123445789'); | ||
$result = DBDateArgs::resolve($date, ['format' => 'FAIL']); | ||
// Referential equality if method not found | ||
$this->assertEquals($result, $date); | ||
|
||
$this->expectExceptionMessage('The "custom" option requires a value for "customFormat"'); | ||
|
||
DBDateArgs::resolve($date, ['format' => 'Custom']); | ||
|
||
$this->expectExceptionMessage('The "customFormat" argument should not be set for formats that are not "custom"'); | ||
|
||
DBDateArgs::resolve($date, ['customFormat' => 'test']); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
tests/Schema/DataObject/Plugin/DBFieldArgs/DBDatetimeArgsTest.php
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,56 @@ | ||
<?php | ||
|
||
namespace SilverStripe\GraphQL\Tests\Schema\DataObject\Plugin\DBFieldArgs; | ||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\GraphQL\Schema\DataObject\DataObjectModel; | ||
use SilverStripe\GraphQL\Schema\DataObject\Plugin\DBFieldArgs\DBDateArgs; | ||
use SilverStripe\GraphQL\Schema\DataObject\Plugin\DBFieldArgs\DBDatetimeArgs; | ||
use SilverStripe\GraphQL\Schema\Field\ModelField; | ||
use SilverStripe\GraphQL\Schema\SchemaConfig; | ||
use SilverStripe\GraphQL\Tests\Fake\DataObjectFake; | ||
use SilverStripe\ORM\FieldType\DBDatetime; | ||
use SilverStripe\ORM\FieldType\DBField; | ||
|
||
class DBDatetimeArgsTest extends SapphireTest | ||
{ | ||
public function testApply() | ||
{ | ||
$field = new ModelField('test', [], new DataObjectModel(DataObjectFake::class, new SchemaConfig())); | ||
$factory = new DBDatetimeArgs(); | ||
$factory->applyToField($field); | ||
$args = $field->getArgs(); | ||
|
||
$this->assertArrayHasKey('format', $args); | ||
$arg = $args['format']; | ||
$this->assertEquals($factory->getEnum()->getName(), $arg->getType()); | ||
|
||
$this->assertArrayHasKey('customFormat', $args); | ||
$arg = $args['customFormat']; | ||
$this->assertEquals('String', $arg->getType()); | ||
} | ||
|
||
public function testResolve() | ||
{ | ||
$fake = $this->getMockBuilder(DBDatetime::class) | ||
->setMethods(['Time']) | ||
->getMock(); | ||
$fake->expects($this->once()) | ||
->method('Time'); | ||
|
||
DBDatetimeArgs::resolve($fake, ['format' => 'Time']); | ||
|
||
$date = DBField::create_field('Datetime', '123445789'); | ||
$result = DBDateArgs::resolve($date, ['format' => 'FAIL']); | ||
// Referential equality if method not found | ||
$this->assertEquals($result, $date); | ||
|
||
$this->expectExceptionMessage('The "custom" option requires a value for "customFormat"'); | ||
|
||
DBDateArgs::resolve($date, ['format' => 'Custom']); | ||
|
||
$this->expectExceptionMessage('The "customFormat" argument should not be set for formats that are not "custom"'); | ||
|
||
DBDateArgs::resolve($date, ['customFormat' => 'test']); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/Schema/DataObject/Plugin/DBFieldArgs/DBDecimalArgsTest.php
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,25 @@ | ||
<?php | ||
|
||
namespace SilverStripe\GraphQL\Tests\Schema\DataObject\Plugin\DBFieldArgs; | ||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\GraphQL\Schema\DataObject\DataObjectModel; | ||
use SilverStripe\GraphQL\Schema\DataObject\Plugin\DBFieldArgs\DBDecimalArgs; | ||
use SilverStripe\GraphQL\Schema\Field\ModelField; | ||
use SilverStripe\GraphQL\Schema\SchemaConfig; | ||
use SilverStripe\GraphQL\Tests\Fake\DataObjectFake; | ||
|
||
class DBDecimalArgsTest extends SapphireTest | ||
{ | ||
public function testApply() | ||
{ | ||
$field = new ModelField('test', [], new DataObjectModel(DataObjectFake::class, new SchemaConfig())); | ||
$factory = new DBDecimalArgs(); | ||
$factory->applyToField($field); | ||
$args = $field->getArgs(); | ||
|
||
$this->assertArrayHasKey('format', $args); | ||
$arg = $args['format']; | ||
$this->assertEquals($factory->getEnum()->getName(), $arg->getType()); | ||
} | ||
} |
Oops, something went wrong.