Skip to content
This repository has been archived by the owner on Mar 7, 2020. It is now read-only.

[WIP][demo] Managing articles feature #202

Open
wants to merge 1 commit into
base: demo
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions config/packages/grids/backend/article.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
sylius_grid:
grids:
app_backend_article:
driver:
name: doctrine/orm
options:
class: "%app.model.article.class%"
sorting:
title: asc
fields:
title:
type: string
label: sylius.ui.title
sortable: ~
filters:
search:
type: string
label: sylius.ui.search
options:
fields: [title]
actions:
main:
create:
type: create
item:
update:
type: update
delete:
type: delete
bulk:
delete:
type: delete
4 changes: 4 additions & 0 deletions config/packages/sylius_fixtures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ sylius_fixtures:
client:
random_id: 5rbhrb0iiukokcwk8gow0w4ocgww0oco8g8gsgokwc0wcssg4w
secret: 2rlxzhijcx448ow4c0gksw4wo8oo4k8kkwwg0osskk8g0k8kw8

article:
options:
random: 20
1 change: 1 addition & 0 deletions config/packages/sylius_grid.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
imports:
- { resource: 'grids/backend/admin_user.yml' }
- { resource: 'grids/backend/article.yaml' }
- { resource: 'grids/backend/customer.yml' }

sylius_grid:
Expand Down
4 changes: 4 additions & 0 deletions config/packages/sylius_resource.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
sylius_resource:
resources:
app.article:
classes:
model: App\Entity\Article
form: App\Form\Type\ArticleType
app.oauth_client:
classes:
model: App\Entity\OAuth\Client
3 changes: 3 additions & 0 deletions config/routes/backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ app_backend_partial:
sylius_backend_admin_user:
resource: "backend/admin_user.yaml"

app_backend_article:
resource: "backend/article.yaml"

sylius_backend_customer:
resource: "backend/customer.yaml"

Expand Down
14 changes: 14 additions & 0 deletions config/routes/backend/article.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
app_backend_article:
resource: |
alias: app.article
section: backend
except: ['show']
redirect: update
grid: app_backend_article
vars:
all:
subheader: app.ui.manage_articles
index:
icon: newspaper
templates: backend/crud
type: sylius.resource
4 changes: 4 additions & 0 deletions config/services/fixtures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ services:
arguments:
$exampleFactory: '@App\Fixture\Factory\AppUserExampleFactory'

App\Fixture\ArticleFixture:
arguments:
$exampleFactory: '@App\Fixture\Factory\ArticleExampleFactory'

App\Fixture\OAuthClientFixture:
arguments:
$exampleFactory: '@App\Fixture\Factory\OAuthClientExampleFactory'
16 changes: 16 additions & 0 deletions features/article/managing_articles/adding_article.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@managing_articles
Feature: Adding a new article
In order to extend articles database
As an Administrator
I want to add a new article

Background:
Given I am logged in as an administrator

@ui
Scenario: Adding a new article
Given I want to create a new article
When I specify its title as "Star Wars"
And I add it
Then I should be notified that it has been successfully created
And the article "Star Wars" should appear in the website
16 changes: 16 additions & 0 deletions features/article/managing_articles/article_validation.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@managing_articles
Feature: Articles validation
In order to avoid making mistakes when managing articles
As an Administrator
I want to be prevented from adding it without specifying required fields

Background:
Given I am logged in as an administrator

@ui
Scenario: Trying to add a new article without title
Given I want to create a new article
When I do not specify its title
And I try to add it
Then I should be notified that the title is required
And this article should not be added
19 changes: 19 additions & 0 deletions features/article/managing_articles/browsing_articles.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@managing_articles
Feature: Browsing articles
In order to manage articles in the website
As an Administrator
I want to browse articles

Background:
Given there is an article titled "Star Wars"
And there is also an article titled "Game Of Thrones"
And there is also an article titled "Back To The Future"
And I am logged in as an administrator

@ui
Scenario: Browsing articles in the website
When I want to browse articles
Then there should be 3 articles in the list
And I should see the article "Star Wars" in the list
And I should see the article "Game Of Thrones" in the list
And I should see the article "Back To The Future" in the list
16 changes: 16 additions & 0 deletions features/article/managing_articles/delete_articles.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@managing_articles
Feature: Deleting an article
In order to get rid of deprecated articles
As an Administrator
I want to be able to delete articles

Background:
Given there is an article titled "Star Wars"
And I am logged in as an administrator

@ui
Scenario: Deleting an article
Given I want to browse articles
When I delete article with title "Star Wars"
Then I should be notified that it has been successfully deleted
And there should not be "Star Wars" article anymore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@managing_articles
Feature: Deleting multiple articles
In order to get rid of spam articles in an efficient way
As an Administrator
I want to be able to delete multiple articles at once

Background:
Given there is an article titled "Star Wars"
And there is also an article titled "Game Of Thrones"
And there is also an article titled "Back To The Future"
And I am logged in as an administrator

@ui @javascript
Scenario: Deleting multiple articles at once
Given I browse articles
And I check the "Star Wars" article
And I also check the "Game Of Thrones" article
And I delete them
Then I should be notified that they have been successfully deleted
And I should see a single article in the list
And I should see the article "Back To The Future" in the list
18 changes: 18 additions & 0 deletions features/article/managing_articles/editing_article.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@managing_articles
Feature: Editing article
In order to change article details
As an Administrator
I want to be able to edit an article

Background:
Given there is an article titled "Star Wars"
And I am logged in as an administrator

@ui
Scenario: Renaming the article
Given I want to modify the "Star Wars" article
When I rename it to "Game Of Thrones"
And I save my changes
Then I should be notified that it has been successfully edited
And I should see the article "Game Of Thrones" in the list
But there should not be "Star Wars" article anymore
41 changes: 41 additions & 0 deletions spec/App/Entity/ArticleSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of monofony.
*
* (c) Mobizel
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace spec\App\Entity;

use PhpSpec\ObjectBehavior;
use Sylius\Component\Resource\Model\ResourceInterface;

class ArticleSpec extends ObjectBehavior
{
function it_implements_resource_interface()
{
$this->shouldImplement(ResourceInterface::class);
}

function it_has_no_id_by_default()
{
$this->getId()->shouldReturn(null);
}

function it_has_no_title_by_default()
{
$this->getTitle()->shouldReturn(null);
}

function its_title_is_mutable()
{
$this->setTitle('Awesome title');
$this->getTitle()->shouldReturn('Awesome title');
}
}
61 changes: 61 additions & 0 deletions src/Behat/Context/Setup/ArticleContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of monofony.
*
* (c) Mobizel
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Behat\Context\Setup;

use App\Behat\Service\SharedStorageInterface;
use App\Entity\Article;
use App\Fixture\Factory\ArticleExampleFactory;
use Behat\Behat\Context\Context;
use Sylius\Component\Resource\Repository\RepositoryInterface;

final class ArticleContext implements Context
{
/** @var SharedStorageInterface */
private $sharedStorage;

/** @var ArticleExampleFactory */
private $articleFactory;

/** @var RepositoryInterface */
private $articleRepository;

public function __construct(
SharedStorageInterface $sharedStorage,
ArticleExampleFactory $articleFactory,
RepositoryInterface $articleRepository
) {
$this->sharedStorage = $sharedStorage;
$this->articleFactory = $articleFactory;
$this->articleRepository = $articleRepository;
}

/**
* @Given there is (also )an article titled :title
*/
public function thereIsAnAdministratorIdentifiedBy(string $title): void
{
$this->createArticle(['title' => $title]);
}

/**
* @param array $options
*/
private function createArticle(array $options): void
{
/** @var Article $article */
$article = $this->articleFactory->create($options);
$this->articleRepository->add($article);
$this->sharedStorage->set('article', $article);
}
}
47 changes: 47 additions & 0 deletions src/Behat/Context/Transform/ArticleContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of monofony.
*
* (c) Mobizel
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Behat\Context\Transform;

use App\Entity\Article;
use Behat\Behat\Context\Context;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Webmozart\Assert\Assert;

final class ArticleContext implements Context
{
/** @var RepositoryInterface */
private $articleRepository;

public function __construct(RepositoryInterface $articleRepository)
{
$this->articleRepository = $articleRepository;
}

/**
* @Transform /^article "([^"]+)"$/
* @Transform :article
*/
public function getArticleByTitle(string $title)
{
/** @var Article $article */
$article = $this->articleRepository->findOneBy(['title' => $title]);

Assert::notNull(
$article,
sprintf('Article with title "%s" does not exist', $title)
);

return $article;
}
}
Loading