Skip to content

Commit

Permalink
adjust to sf6
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed May 4, 2024
1 parent b50b8d0 commit b71e83b
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: 'PHP ${{ matrix.php-version }}, Symfony ${{ matrix.symfony-version }} ${{ matrix.dependencies}}'
runs-on: ubuntu-20.04
env:
SYMFONY_PHPUNIT_VERSION: 8
SYMFONY_PHPUNIT_VERSION: 9
SYMFONY_DEPRECATIONS_HELPER: "/.*each.*/"
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}

Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"ext-dom": "*",
"jackalope/jackalope-doctrine-dbal": "^1.3 || ^2.0",
"mockery/mockery": "^1.4.1",
"symfony-cmf/routing-bundle": "dev-sf7 as 3.1.0",
"symfony-cmf/testing": "^4.0.0",
"symfony-cmf/routing-bundle": "3.1.0",
"symfony-cmf/testing": "5.0.2",
"doctrine/dbal": "^3.8.1 || ^4.0",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/phpcr-bundle": "^3.0",
Expand All @@ -44,8 +44,7 @@
"suggest": {
"symfony/twig-bundle": "To get access to the CMF twig extension",
"symfony/security-bundle": "To be able to use the publish workflow system",
"symfony-cmf/routing": "To be able to use the CMF twig extension functions cmf_prev_linkable/cmf_next_linkable",
"symfony-cmf/routing-bundle": "To be able to enable the publish_workflow_listener",
"symfony-cmf/routing-bundle": "For the wtig extension functions cmf_prev_linkable/cmf_next_linkable and the publish_workflow_listener",
"symfony-cmf/sonata-admin-integration-bundle": "To provide an admin interface for the PHPCR ODM documents."
},
"autoload": {
Expand Down
3 changes: 0 additions & 3 deletions src/PublishWorkflow/PublishWorkflowChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public function __construct(
{
}

/**
* {@inheritdoc}
*/
public function isGranted(mixed $attribute, mixed $subject = null): bool
{
if (self::VIEW_ATTRIBUTE === $attribute
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/config/publish-workflow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

<services>

<service id="cmf_core.publish_workflow.access_decision_manager.strategy" class="Symfony\Component\Security\Core\Authorization\Strategy\UnanimousStrategy"/>
<service id="cmf_core.publish_workflow.access_decision_manager" class="Symfony\Component\Security\Core\Authorization\AccessDecisionManager">
<argument type="collection"/>
<argument>unanimous</argument>
<argument type="service" id="cmf_core.publish_workflow.access_decision_manager.strategy"/>
<argument>true</argument>
</service>

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/App/DataFixture/LoadRouteData.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
class LoadRouteData implements FixtureInterface
{
public function load(ObjectManager $manager)
public function load(ObjectManager $manager): void
{
$root = $manager->find(null, '/');

Expand Down
20 changes: 10 additions & 10 deletions tests/Fixtures/App/Document/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@

namespace Symfony\Cmf\Bundle\CoreBundle\Tests\Fixtures\App\Document;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCRODM;
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface;

/**
* @PHPCRODM\Document(referenceable=true)
*/
#[PHPCRODM\Document(referenceable: true)]
class Content implements RouteReferrersReadInterface
{
/** @PHPCRODM\Id */
public $id;
#[PHPCRODM\Id]
public string $id;

/** @PHPCRODM\Referrers(referringDocument="Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route", referencedBy="content") */
public $routes;
#[PHPCRODM\Referrers(referencedBy: 'content', referringDocument: Route::class)]
public array|Collection $routes;

public function getId()
public function getId(): string
{
return $this->id;
}

public function getRoutes()
public function getRoutes(): iterable
{
return $this->routes;
}
Expand Down
14 changes: 6 additions & 8 deletions tests/Fixtures/App/Document/RouteAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@

namespace Symfony\Cmf\Bundle\CoreBundle\Tests\Fixtures\App\Document;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCRODM;
use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface;

/**
* @PHPCRODM\Document()
*/
#[PHPCRODM\Document]
class RouteAware implements RouteReferrersReadInterface
{
/** @PHPCRODM\Id */
public $id;
#[PHPCRODM\Id]
public string $id;

public function getId()
public function getId(): string
{
return $this->id;
}

public function getRoutes()
public function getRoutes(): iterable
{
return [1, 2];
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/App/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

class Kernel extends TestKernel
{
public function configure()
public function configure(): void
{
$this->requireBundleSets(['default', 'phpcr_odm']);

$this->registerConfiguredBundles();
}

public function registerContainerConfiguration(LoaderInterface $loader)
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__.'/config/config.php');
}
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/App/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
$loader->import(__DIR__.'/cmf_core.yml');
$loader->import(__DIR__.'/cmf_routing.yml');
$loader->import(__DIR__.'/config.yml');
$loader->import(__DIR__.'/services.yaml');

$container->loadFromExtension('framework', [
'csrf_protection' => false,
Expand Down
13 changes: 11 additions & 2 deletions tests/Fixtures/App/config/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# for cmf routing bundle
framework:
property_access: ~
annotations: ~
property_access: ~
http_method_override: false
handle_all_throwables: true
php_errors:
log: true
session:
handler_id: null
cookie_secure: auto
cookie_samesite: lax
validation:
email_validation_mode: html5
4 changes: 4 additions & 0 deletions tests/Fixtures/App/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
form_factory_public:
public: true
alias: form.factory
2 changes: 1 addition & 1 deletion tests/Functional/Form/CheckboxUrlLabelFormTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function setUp(): void

public function testFormTwigTemplate(): void
{
$view = self::getContainer()->get('test.service_container')->get('form.factory')->createNamedBuilder('name')
$view = self::getContainer()->get('form_factory_public')->createNamedBuilder('name')
->add('terms', CheckboxUrlLabelFormType::class, [
'label' => '%a% and %b% and %c%',
'routes' => [
Expand Down
44 changes: 21 additions & 23 deletions tests/Functional/PublishWorkflow/PublishWorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,83 +16,81 @@
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\User\UserInterface;

class PublishWorkflowTest extends BaseTestCase
{
/**
* @var AuthorizationCheckerInterface
*/
private $publishWorkflowChecker;

/**
* @var TokenStorageInterface
*/
private $tokenStorage;
private AuthorizationCheckerInterface $publishWorkflowChecker;
private TokenStorageInterface $tokenStorage;

public function setUp(): void
{
$this->publishWorkflowChecker = $this->getContainer()->get('cmf_core.publish_workflow.checker');
$this->tokenStorage = $this->getContainer()->get('test.service_container')->get('security.token_storage');
$this->publishWorkflowChecker = self::getContainer()->get('cmf_core.publish_workflow.checker');
$this->tokenStorage = self::getContainer()->get('test.service_container')->get('security.token_storage');
}

public function testPublishable()
public function testPublishable(): void
{
$doc = $this->createMock(PublishableReadInterface::class);
$doc
->method('isPublishable')
->will($this->returnValue(true))
->willReturn(true)
;

$this->assertTrue($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $doc));
$this->assertTrue($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE, $doc));
}

public function testPublishPeriod()
public function testPublishPeriod(): void
{
$doc = $this->createMock(PublishModel::class);
$doc
->method('isPublishable')
->will($this->returnValue(true))
->willReturn(true)
;
$doc
->method('getPublishEndDate')
->will($this->returnValue(new \DateTime('01/01/1980')))
->willReturn(new \DateTime('01/01/1980'))
;

$this->assertFalse($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $doc));
$this->assertFalse($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE, $doc));
}

public function testIgnoreRoleHas()
public function testIgnoreRoleHas(): void
{
$doc = $this->createMock(PublishModel::class);
$doc
->method('isPublishable')
->will($this->returnValue(false))
->willReturn(false)
;
$roles = [
'ROLE_CAN_VIEW_NON_PUBLISHED',
];
$token = new UsernamePasswordToken('test', 'pass', 'testprovider', $roles);
$token = $this->createMock(TokenInterface::class);
$token->method('getUser')->willReturn($this->createMock(UserInterface::class)); // authorization checker will ignore roles if user is null
$token->method('getRoleNames')->willReturn($roles);
$this->tokenStorage->setToken($token);

$this->assertTrue($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $doc));
$this->assertFalse($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE, $doc));
}

public function testIgnoreRoleNotHas()
public function testIgnoreRoleNotHas(): void
{
$doc = $this->createMock(PublishModel::class);
$doc
->method('isPublishable')
->will($this->returnValue(false))
->willReturn(false)
;
$roles = [
'OTHER_ROLE',
];
$token = new UsernamePasswordToken('test', 'pass', 'testprovider', $roles);
$token = $this->createMock(TokenInterface::class);
$token->method('getUser')->willReturn($this->createMock(UserInterface::class));
$token->method('getRoleNames')->willReturn($roles);
$this->tokenStorage->setToken($token);

$this->assertFalse($this->publishWorkflowChecker->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $doc));
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Form/CheckboxUrlLabelFormTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class Router implements RouterInterface
{
public function setContext(RequestContext $context)
public function setContext(RequestContext $context): void
{
}

Expand Down

0 comments on commit b71e83b

Please sign in to comment.