Skip to content

Content API Endpoint and Behat tests #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ APP_SECRET=67d829bf61dc5f87a73fd814e2c9f629
DATABASE_URL=sqlite:///%kernel.project_dir%/var/data/bolt.sqlite

# MySQL (with docker)
#DATABASE_HOST=database
#DATABASE_USER=bolt_db_user
#DATABASE_PASSWORD=bolt_db_password
#DATABASE_NAME=bolt
#DATABASE_URL=mysql://bolt_db_user:bolt_db_password@mysql:3306/bolt
#DATABASE_URL=mysql://bolt_db_user:bolt_db_password@database:3306/bolt

###< doctrine/doctrine-bundle ###

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ appveyor.yml
!/var/log/.gitkeep
!/var/log/e2e-reports/performance/.gitkeep
!/var/log/e2e-reports/report/.gitkeep
!/var/log/behat-reports/.gitkeep
/var/data/*
!/var/data/.gitkeep
/var/sessions/*
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@ script:
- ./bin/console doctrine:schema:validate --skip-sync -vvv --no-interaction
# run jest unit tests
- npm test
# run API tests
- ./vendor/bin/behat
# run e2e tests with Kakunin
- cd tests/e2e && npm run kakunin && cd ../..
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,20 @@ test:
vendor/bin/phpunit
vendor/bin/phpspec run

behat:
make server
vendor/bin/behat -v

behat-rerun:
make server
vendor/bin/behat -v --rerun

e2e:
make server
cd tests/e2e && npm run kakunin && cd ../..

db-create:
bin/console doctrine:database:create --if-not-exists
bin/console doctrine:database:create
bin/console doctrine:schema:create
bin/console doctrine:fixtures:load -n

Expand Down Expand Up @@ -102,3 +110,9 @@ docker-db-reset:

docker-npm-fix-env:
docker-compose run node sh -c "npm rebuild node-sass"

docker-behat:
docker-compose exec -T php vendor/bin/behat -v

docker-behat-rerun:
docker-compose exec -T php vendor/bin/behat -v --rerun
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ Testing
---

Bolt uses several testing frameworks for [different test layers](https://martinfowler.com/articles/practical-test-pyramid.html):
- unit: PHPUnit, PHPSpec, Jest
- functional: PHPUnit with WebTestCase (not yet configured)
- integration (API endpoints): Behat (not yet configured)
- unit: PHPSpec, PHPUnit, Jest
- integration (of Symfony services): PHPUnit with KernelTestCase
- functional (API Contracts): Behat
- acceptance (UI, end-to-end): Kakunin

To run PHP unit tests:
Expand Down
5 changes: 5 additions & 0 deletions assets/scss/modules/api/api.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//** Api

#swagger-ui .col{
width: auto;
}
1 change: 1 addition & 0 deletions assets/scss/modules/modules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
@import './listing/listing';
@import './editor/editor';
@import './user/user';
@import './api/api';
38 changes: 38 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
default:

gherkin:
filters:
tags: ~@wip

autoload:
- "%paths.base%/tests/api/bootstrap"

formatters:
pretty:
output_styles:
comment: [ white, black ]
calls:
error_reporting: 16383 # E_ALL & ~E_USER_DREPRECATED

extensions:
Lakion\Behat\MinkDebugExtension:
directory: var/log/behat-reports
screenshot: false

Behat\MinkExtension:
base_url: 'http://127.0.0.1:8088/'
goutte: ~
sessions:
default:
goutte: ~

Behatch\Extension: ~

suites:
default:
filters:
tags: "~@wip"
contexts:
- Behatch\Context\JsonContext
- Context\FeatureContext
paths: [ "%paths.base%/tests/api" ]
12 changes: 12 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@
},
"require-dev": {
"ext-pdo_sqlite": "*",
"behat/behat": "^3.5",
"behat/mink": "dev-master@dev",
"behat/mink-extension": "^2.3",
"behat/mink-goutte-driver": "^1.2",
"behatch/contexts": "^3.2",
"coduo/php-matcher": "dev-feature/array-universal-key@dev",
"dama/doctrine-test-bundle": "^5.0",
"doctrine/doctrine-fixtures-bundle": "^3.0",
"lakion/mink-debug-extension": "^1.2",
"phpspec/phpspec": "^5.1",
"phpstan/phpstan": "^0.10.3",
"phpunit/phpunit": "^7.0",
"roave/security-advisories": "dev-master@dev",
"symfony/browser-kit": "^4.2",
"symfony/css-selector": "^4.2",
"symfony/debug-bundle": "^4.2",
Expand All @@ -69,6 +77,9 @@
"symfony/web-server-bundle": "^4.2",
"symplify/easy-coding-standard": "^5.2"
},
"repositories": [
{ "type": "vcs", "url": "https://github.com/jarjak/php-matcher", "no-api": true }
],
"minimum-stability": "stable",
"prefer-stable": true,
"config": {
Expand All @@ -88,6 +99,7 @@
"autoload-dev": {
"psr-4": {
"Bolt\\Tests\\": "tests/php/",
"Context\\": "tests/api/bootstrap/",
"spec\\Bolt\\": "tests/spec/Bolt/"
}
},
Expand Down
2 changes: 2 additions & 0 deletions config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
api_platform:
enable_swagger_ui: false # route redirected manually to /bolt/api
graphql:
graphiql:
enabled: true
mapping:
paths: ['%kernel.project_dir%/src/Entity']
formats:
jsonld: ['application/ld+json']
json: ['application/json']
jsonapi: ['application/vnd.api+json']
html: ['text/html']
Expand Down
4 changes: 3 additions & 1 deletion config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ frontend:
# ------------------------------------------------------------------------------
# Place your own routes here, that have a LOWER priority than the default routes.


api_entrypoint:
path: /bolt/api # moved to admin area firewall
controller: api_platform.swagger.action.ui

# ------------------------------------------------------------------------------
# These are the routes defining the Bolt Control Panel ("backend"). It's common
Expand Down
3 changes: 2 additions & 1 deletion easy-coding-standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@ parameters:
- 'PhpCsFixer\Fixer\Phpdoc\PhpdocSummaryFixer'
- 'PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer'
- 'SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff'
- 'Symplify\CodingStandard\Sniffs\Debug\CommentedOutCodeSniff' #to be removed after beta release
- 'Symplify\CodingStandard\Sniffs\Debug\CommentedOutCodeSniff' #to be removed before beta release
- 'Symplify\CodingStandard\Sniffs\Debug\DebugFunctionCallSniff' #to be removed before beta release
2 changes: 1 addition & 1 deletion public/theme/skeleton/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% if record is defined %}

<h1>{{ record.title }}</h1>
<h1><a href="{{ record.link }}">{{ record.title }}</a></h1>

{# Remove this block if you don't need it anymore. #}
{{ include('partials/_fresh_install.twig') }}
Expand Down
2 changes: 1 addition & 1 deletion public/theme/skeleton/partials/_sub_fields.twig
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
{% endfor %}

{# We do the same for the templatefields, if set and not empty. #}
{% set templatefields = record.values.templatefields.values|default() %}
{% set templatefields = record.getValue('templateFields') %}
{% if templatefields is not empty %}

{# Note: This needs to be expanded upon!! For better detection the 'virtual'
Expand Down
32 changes: 16 additions & 16 deletions src/Content/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ public function createSidebarMenu()
'icon' => 'fa-sliders-h',
]]);

$menu['Configuration']->addChild('Users &amp; Permissions', [
$menu->getChild('Configuration')->addChild('Users &amp; Permissions', [
'uri' => $this->urlGenerator->generate('bolt_users'),
'extras' => [
'name' => $t->trans('caption.users_permissions'),
'icon' => 'fa-users',
],
]);

$menu['Configuration']->addChild('Main configuration', [
$menu->getChild('Configuration')->addChild('Main configuration', [
'uri' => $this->urlGenerator->generate('bolt_file_edit', [
'area' => 'config',
'file' => '/bolt/config.yaml',
Expand All @@ -119,7 +119,7 @@ public function createSidebarMenu()
],
]);

$menu['Configuration']->addChild('ContentTypes', [
$menu->getChild('Configuration')->addChild('ContentTypes', [
'uri' => $this->urlGenerator->generate('bolt_file_edit', [
'area' => 'config',
'file' => '/bolt/contenttypes.yaml',
Expand All @@ -130,7 +130,7 @@ public function createSidebarMenu()
],
]);

$menu['Configuration']->addChild('Taxonomies', [
$menu->getChild('Configuration')->addChild('Taxonomies', [
'uri' => $this->urlGenerator->generate('bolt_file_edit', [
'area' => 'config',
'file' => '/bolt/taxonomy.yaml',
Expand All @@ -141,7 +141,7 @@ public function createSidebarMenu()
],
]);

$menu['Configuration']->addChild('Menu set up', [
$menu->getChild('Configuration')->addChild('Menu set up', [
'uri' => $this->urlGenerator->generate('bolt_file_edit', [
'area' => 'config',
'file' => '/bolt/menu.yaml',
Expand All @@ -153,7 +153,7 @@ public function createSidebarMenu()
],
]);

$menu['Configuration']->addChild('Routing set up', [
$menu->getChild('Configuration')->addChild('Routing set up', [
'uri' => $this->urlGenerator->generate('bolt_file_edit', [
'area' => 'config',
'file' => '/routes.yaml',
Expand All @@ -164,7 +164,7 @@ public function createSidebarMenu()
],
]);

$menu['Configuration']->addChild('All configuration files', [
$menu->getChild('Configuration')->addChild('All configuration files', [
'uri' => $this->urlGenerator->generate('bolt_filemanager', ['area' => 'config']),
'extras' => [
'name' => $t->trans('caption.all_configuration_files'),
Expand All @@ -179,55 +179,55 @@ public function createSidebarMenu()
'icon' => 'fa-tools',
]]);

$menu['Maintenance']->addChild('Bolt API', [
$menu->getChild('Maintenance')->addChild('Bolt API', [
'uri' => $this->urlGenerator->generate('api_entrypoint'),
'extras' => [
'name' => $t->trans('caption.api'),
'icon' => 'fa-code',
],
]);

$menu['Maintenance']->addChild('Check database', [
$menu->getChild('Maintenance')->addChild('Check database', [
'uri' => '',
'extras' => [
'name' => $t->trans('caption.check_database'),
'icon' => 'fa-database',
],
]);

$menu['Maintenance']->addChild('Fixtures', [
$menu->getChild('Maintenance')->addChild('Fixtures', [
'uri' => '',
'extras' => [
'name' => $t->trans('caption.fixtures_dummy_content'),
'icon' => 'fa-hat-wizard',
],
]);

$menu['Maintenance']->addChild('Clear the cache', [
$menu->getChild('Maintenance')->addChild('Clear the cache', [
'uri' => $this->urlGenerator->generate('bolt_clear_cache'),
'extras' => [
'name' => $t->trans('caption.clear_cache'),
'icon' => 'fa-eraser',
],
]);

$menu['Maintenance']->addChild('Installation checks', [
$menu->getChild('Maintenance')->addChild('Installation checks', [
'uri' => '',
'extras' => [
'name' => $t->trans('caption.installation_checks'),
'icon' => 'fa-clipboard-check',
],
]);

$menu['Maintenance']->addChild('Translations: Messages', [
$menu->getChild('Maintenance')->addChild('Translations: Messages', [
'uri' => $this->urlGenerator->generate('translation_index'),
'extras' => [
'name' => $t->trans('caption.translations'),
'icon' => 'fa-language',
],
]);

$menu['Maintenance']->addChild('Extensions', [
$menu->getChild('Maintenance')->addChild('Extensions', [
'uri' => '',
'extras' => [
'name' => $t->trans('caption.extensions'),
Expand All @@ -242,15 +242,15 @@ public function createSidebarMenu()
'icon' => 'fa-folder-open',
]]);

$menu['File Management']->addChild('Uploaded files', [
$menu->getChild('File Management')->addChild('Uploaded files', [
'uri' => $this->urlGenerator->generate('bolt_filemanager', ['area' => 'files']),
'extras' => [
'name' => $t->trans('caption.uploaded_files'),
'icon' => 'fa-archive',
],
]);

$menu['File Management']->addChild('View/edit Templates', [
$menu->getChild('File Management')->addChild('View/edit Templates', [
'uri' => $this->urlGenerator->generate('bolt_filemanager', ['area' => 'themes']),
'extras' => [
'name' => $t->trans('caption.view_edit_templates'),
Expand Down
7 changes: 7 additions & 0 deletions src/Controller/Frontend/DetailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Bolt\Repository\FieldRepository;
use Bolt\TemplateChooser;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;

Expand Down Expand Up @@ -42,6 +43,9 @@ public function record(ContentRepository $contentRepository, FieldRepository $fi
} else {
/* @todo this should search only by slug or any other unique field */
$field = $fieldRepository->findOneBySlug($slugOrId);
if ($field === null) {
throw new NotFoundHttpException('Content does not exist.');
}
$record = $field->getContent();
}

Expand All @@ -52,6 +56,9 @@ public function record(ContentRepository $contentRepository, FieldRepository $fi
$recordSlug => $record,
];

dump($record);
dump($record->getFieldValues());

$templates = $this->templateChooser->record($record);

return $this->renderTemplate($templates, $context);
Expand Down
Loading