-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
10 changed files
with
382 additions
and
384 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,25 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<logging> | ||
<junit outputFile="build/report.junit.xml"/> | ||
</logging> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">./app</directory> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
</phpunit> |
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,173 @@ | ||
<?php | ||
|
||
use Riclep\StoryblokCli\Endpoints\ComponentGroups; | ||
use Riclep\StoryblokCli\Endpoints\Components; | ||
|
||
test('can get components for space', function () { | ||
$components = Components::make('dummy-token'); | ||
$components->mockable([ | ||
mockResponse('components'), | ||
]); | ||
|
||
$componentsData = $components->all(); | ||
|
||
expect($componentsData->getComponents())->not()->toBeNull(); | ||
expect($componentsData->getComponents())->toHaveCount(5); | ||
expect($componentsData->getComponents()[0]['name'])->toEqual('page'); | ||
}); | ||
|
||
test('can get component by ID', function () { | ||
$components = Components::make('dummy-token'); | ||
$components->mockable([ | ||
mockResponse('components/2559045'), | ||
]); | ||
|
||
$componentData = $components->byId(2559045); | ||
|
||
expect($componentData->getComponent()['name'])->toEqual('hero'); | ||
}); | ||
|
||
test('can create a component', function () { | ||
$components = Components::make('dummy-token'); | ||
$components->mockable([ | ||
mockResponse('components/2559045'), | ||
]); | ||
|
||
$componentData = $components->create([ | ||
'component' => [ | ||
'name' => 'hero', | ||
'display_name' => 'Hero', | ||
'schema' => [ | ||
'title' => [ | ||
'type' => 'text', | ||
'pos' => 0, | ||
], | ||
'image' => [ | ||
'type' => 'image', | ||
'pos' => 1, | ||
], | ||
], | ||
'is_root' => false, | ||
'is_nestable' => true, | ||
], | ||
]); | ||
|
||
expect($componentData->getComponent()['name'])->toEqual('hero'); | ||
}); | ||
|
||
test('can update a component', function () { | ||
$components = Components::make('dummy-token'); | ||
$components->mockable([ | ||
mockResponse('components/2559045'), | ||
]); | ||
|
||
$componentData = $components->update(2559045, [ | ||
'component' => [ | ||
'name' => 'hero', | ||
'display_name' => 'Hero', | ||
'schema' => [ | ||
'title' => [ | ||
'type' => 'text', | ||
'pos' => 0, | ||
], | ||
'image' => [ | ||
'type' => 'image', | ||
'pos' => 1, | ||
], | ||
], | ||
'is_root' => false, | ||
'is_nestable' => true, | ||
], | ||
]); | ||
|
||
expect($componentData->getComponent()['name'])->toEqual('hero'); | ||
}); | ||
|
||
test('can delete a component', function () { | ||
$components = Components::make('dummy-token'); | ||
$components->mockable([ | ||
mockResponse('components/2559045'), | ||
]); | ||
|
||
$componentData = $components->delete(2559045); | ||
|
||
expect($componentData->getComponent()['name'])->toEqual('hero'); | ||
}); | ||
|
||
test('can get component groups', function () { | ||
$components = Components::make('dummy-token'); | ||
$components->mockable([ | ||
mockResponse('components'), | ||
]); | ||
|
||
$componentsData = $components->all(); | ||
|
||
expect($componentsData->getComponentGroups())->not()->toBeNull(); | ||
expect($componentsData->getComponentGroups())->toHaveCount(2); | ||
expect($componentsData->getComponentGroups()[0]['name'])->toEqual('Body blocks'); | ||
}); | ||
|
||
test('can get all component groups for space', function () { | ||
$componentGroups = ComponentGroups::make('dummy-token'); | ||
$componentGroups->mockable([ | ||
mockResponse('component_groups'), | ||
]); | ||
|
||
$componentGroupsData = $componentGroups->all(); | ||
|
||
expect($componentGroupsData->getComponentGroups())->not()->toBeNull(); | ||
expect($componentGroupsData->getComponentGroups())->toHaveCount(2); | ||
expect($componentGroupsData->getComponentGroups()[0]['name'])->toEqual('Body blocks'); | ||
}); | ||
|
||
test('can get component group by ID', function () { | ||
$componentGroups = ComponentGroups::make('dummy-token'); | ||
$componentGroups->mockable([ | ||
mockResponse('component_groups/58878'), | ||
]); | ||
|
||
$componentGroupsData = $componentGroups->byId(58878); | ||
|
||
expect($componentGroupsData->getComponentGroup()['name'])->toEqual('Body blocks'); | ||
}); | ||
|
||
test('can create a component group', function () { | ||
$componentGroups = ComponentGroups::make('dummy-token'); | ||
$componentGroups->mockable([ | ||
mockResponse('component_groups/58878'), | ||
]); | ||
|
||
$componentGroupData = $componentGroups->create([ | ||
'component_group' => [ | ||
'name' => 'Body blocks', | ||
], | ||
]); | ||
|
||
expect($componentGroupData->getComponentGroup()['name'])->toEqual('Body blocks'); | ||
}); | ||
|
||
test('can update a component group', function () { | ||
$componentGroups = ComponentGroups::make('dummy-token'); | ||
$componentGroups->mockable([ | ||
mockResponse('component_groups/58878'), | ||
]); | ||
|
||
$componentGroupData = $componentGroups->update(58878, [ | ||
'component_group' => [ | ||
'name' => 'Body blocks', | ||
], | ||
]); | ||
|
||
expect($componentGroupData->getComponentGroup()['name'])->toEqual('Body blocks'); | ||
}); | ||
|
||
test('can delete a component group', function () { | ||
$componentGroups = ComponentGroups::make('dummy-token'); | ||
$componentGroups->mockable([ | ||
mockResponse('component_groups/58878'), | ||
]); | ||
|
||
$componentGroupData = $componentGroups->delete(58878); | ||
|
||
expect($componentGroupData->getComponentGroup()['name'])->toEqual('Body blocks'); | ||
}); |
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,5 @@ | ||
<?php | ||
|
||
test('example', function () { | ||
expect(true)->toBeTrue(); | ||
}); |
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 | ||
|
||
use Riclep\StoryblokCli\Endpoints\Spaces; | ||
use Riclep\StoryblokCli\Endpoints\Stories; | ||
|
||
test('returns empty collection when data does not exist', function () { | ||
$spaces = Spaces::make('dummy-token'); | ||
$spaces->mockable([ | ||
mockResponse('spaces/196985'), | ||
]); | ||
|
||
$spaceData = $spaces->byId(196985)->getCollectionFromResponse('not-here'); | ||
|
||
expect($spaceData)->not()->toBeNull(); | ||
expect($spaceData)->toHaveCount(0); | ||
expect($spaceData)->toBeCollection(); | ||
}); | ||
|
||
test('can get spaces', function () { | ||
$spaces = Spaces::make('dummy-token'); | ||
$spaces->mockable([ | ||
mockResponse('spaces'), | ||
]); | ||
|
||
$spacesData = $spaces->all(); | ||
expect($spacesData->getSpaces())->not()->toBeNull(); | ||
expect($spacesData->getSpaces())->toHaveCount(2); | ||
|
||
$spaceValues = $spacesData->getSpaces(); | ||
expect($spaceValues[0]['name'])->toEqual('Example Space 1'); | ||
expect($spaceValues[1]['name'])->toEqual('Example Space 2'); | ||
}); | ||
|
||
test('can get a space by id', function () { | ||
$spaces = Spaces::make('dummy-token'); | ||
$spaces->mockable([ | ||
mockResponse('spaces/196985'), | ||
]); | ||
|
||
$spaceData = $spaces->byId(196985); | ||
|
||
$spaceValue = $spaceData->getSpace(); | ||
expect($spaceValue['name'])->toEqual('CLI space'); | ||
}); | ||
|
||
test('can set space id', function () { | ||
$story = Stories::make('dummy-token'); | ||
$story->mockable([ | ||
mockResponse('stories/259645264'), | ||
]); | ||
|
||
$storyData = $story->spaceId(12345)->byId(259645264); | ||
|
||
expect($storyData->getStory()['name'])->toEqual('Home'); | ||
}); |
Oops, something went wrong.