Skip to content

Commit

Permalink
Add compatiblity of CollaborationControllerTest for Symfony 6
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed May 3, 2022
1 parent 0641168 commit a5d33b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ security:
- { path: ^/admin/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin, roles: ROLE_USER }

session_fixation_strategy: none # required for the CollaborationControllerTest

firewalls:
test:
pattern: ^/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
use Sulu\Bundle\AdminBundle\Entity\Collaboration;
use Sulu\Bundle\TestBundle\Testing\SuluTestCase;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class CollaborationControllerTest extends SuluTestCase
{
Expand All @@ -30,8 +34,12 @@ public function setUp(): void

public function testPostWithSingleUser()
{
$session = $this->client->getContainer()->get('session');
$session->start();
$request = Request::create('/');
$this->client->getContainer()->get('test.session.listener')->onKernelRequest(new RequestEvent(self::$kernel, $request, HttpKernelInterface::MAIN_REQUEST));
$request->getSession()->start();
$sessionId = $request->getSession()->getId();
$this->client->getCookieJar()->set(new Cookie($request->getSession()->getName(), $sessionId));

$this->client->jsonRequest('PUT', '/admin/api/collaborations?id=4&resourceKey=page');

$this->assertHttpStatusCode(200, $this->client->getResponse());
Expand Down Expand Up @@ -86,9 +94,13 @@ public function testPostWithMultipleUsers()

public function testDelete()
{
$session = $this->client->getContainer()->get('session');
$session->start();
$cache = $this->getContainer()->get('sulu_admin.collaboration_cache');
$request = Request::create('/');
$this->client->getContainer()->get('test.session.listener')->onKernelRequest(new RequestEvent(self::$kernel, $request, HttpKernelInterface::MAIN_REQUEST));
$request->getSession()->start();
$sessionId = $request->getSession()->getId();
$this->client->getCookieJar()->set(new Cookie($request->getSession()->getName(), $sessionId));

$cache = $this->client->getContainer()->get('sulu_admin.collaboration_cache');

$cacheItem = $cache->getItem('page_4')->set([
new Collaboration('collaboration1', 1, 'Max', 'Max Mustermann', 'page', 4),
Expand All @@ -98,6 +110,7 @@ public function testDelete()
$cache->save($cacheItem);

$this->client->jsonRequest('PUT', '/admin/api/collaborations?id=4&resourceKey=page');

$this->assertHttpStatusCode(200, $this->client->getResponse());

$this->assertCount(3, $cache->getItem('page_4')->get());
Expand Down

0 comments on commit a5d33b9

Please sign in to comment.