-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
e0e88a0
commit 1e872d5
Showing
12 changed files
with
187 additions
and
82 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 |
---|---|---|
@@ -1,5 +1,18 @@ | ||
<?php | ||
|
||
dataset('sample', [ | ||
'sample' => file_get_contents(__DIR__ . '/../samples/sample.json'), | ||
'sample' => file_get_contents(__DIR__ . '/sample.json'), | ||
]); | ||
|
||
dataset('sampleBroken', [ | ||
'sample' => file_get_contents(__DIR__ . '/sample-broken.json'), | ||
]); | ||
|
||
dataset('sampleUnknownProvider', [ | ||
'sample' => file_get_contents(__DIR__ . '/sample-unknown-provider.json'), | ||
]); | ||
|
||
dataset('sampleUnmatchingSchema', [ | ||
'sample' => file_get_contents(__DIR__ . '/sample-unmatching-schema.json'), | ||
]); | ||
|
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,12 @@ | ||
We have to make this JSON broken, isn't it? I wonder how... | ||
|
||
{ | ||
"time": 1672852569662, | ||
"blocks": [ | ||
{ | ||
"type": "delimiter", | ||
"data": {} | ||
} | ||
], | ||
"version": "2.26.4" | ||
} |
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,10 @@ | ||
{ | ||
"time": 1672852569662, | ||
"blocks": [ | ||
{ | ||
"type": "foo", | ||
"data": {} | ||
} | ||
], | ||
"version": "2.26.4" | ||
} |
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,4 @@ | ||
{ | ||
"time": 1672852569662, | ||
"version": "2.26.4" | ||
} |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
use BumpCore\EditorPhp\Casts\EditorPhpCast; | ||
use BumpCore\EditorPhp\EditorPhp; | ||
use BumpCore\EditorPhp\Tests\LaravelTestCase; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
use function Orchestra\Testbench\artisan; | ||
|
||
uses(LaravelTestCase::class); | ||
|
||
test('Can be rendered in Laravel environment', function($sample) { | ||
expect(EditorPhp::make($sample)->render())->toBeString(); | ||
})->with('sample'); | ||
|
||
test('Can model casting works with json', function($sample) { | ||
$model = new class() extends Model | ||
{ | ||
protected $fillable = [ | ||
'content', | ||
]; | ||
|
||
protected $casts = [ | ||
'content' => EditorPhpCast::class, | ||
]; | ||
}; | ||
|
||
$model->content = $sample; | ||
|
||
expect($model->content)->toBeInstanceOf(EditorPhp::class); | ||
})->with('sample'); | ||
|
||
test('Can model casting works with editor.php instance', function($sample) { | ||
$model = new class() extends Model | ||
{ | ||
protected $fillable = [ | ||
'content', | ||
]; | ||
|
||
protected $casts = [ | ||
'content' => EditorPhpCast::class, | ||
]; | ||
}; | ||
|
||
$model->content = EditorPhp::make($sample); | ||
|
||
expect($model->content)->toBeInstanceOf(EditorPhp::class); | ||
})->with('sample'); | ||
|
||
test('Can `make:block` command creates block provider', function() { | ||
expect(artisan($this, 'make:block FooBlock'))->toEqual(Command::SUCCESS); | ||
}); | ||
|
||
test('Can render on response', function() { | ||
$response = $this->get('/editor', ['Accept' => 'text/html'])->getContent(); | ||
|
||
expect($response)->not()->toBeJson(); | ||
}); | ||
|
||
test('Can encode to json on response', function() { | ||
$response = $this->get('/editor', ['Accept' => 'application/json'])->getContent(); | ||
|
||
expect($response)->toBeJson(); | ||
}); |
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,47 @@ | ||
<?php | ||
|
||
use BumpCore\EditorPhp\Block\Data; | ||
use BumpCore\EditorPhp\Contracts\Provider; | ||
use BumpCore\EditorPhp\Parser; | ||
|
||
test('Can not register un implemented provider', function() { | ||
$provider = new class() | ||
{ | ||
public function rules(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function render(Data $data): string | ||
{ | ||
return $data('foo'); | ||
} | ||
}; | ||
|
||
Parser::register([ | ||
$provider::class, | ||
]); | ||
})->throws(Exception::class); | ||
|
||
test('Can explicitly define provider type', function() { | ||
$provider = new class() implements Provider | ||
{ | ||
public $type = 'bar'; | ||
|
||
public function rules(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function render(Data $data): string | ||
{ | ||
return $data('foo'); | ||
} | ||
}; | ||
|
||
Parser::register([ | ||
$provider, | ||
]); | ||
|
||
expect(Parser::$providers)->toHaveKeys([$provider->type]); | ||
}); |
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