<commit_before><?php
namespace TYPO3\Flow\Tests\Functional\Session;

/*
 * This file is part of the TYPO3.Flow package.
 *
 * (c) Contributors of the Neos Project - www.neos.io
 *
 * This package is Open Source Software. For the full copyright and license
 * information, please view the LICENSE file which was distributed with this
 * source code.
 */

use TYPO3\Flow\Mvc\Routing\Route;
use TYPO3\Flow\Tests\FunctionalTestCase;
use TYPO3\Flow\Session;

class SessionManagementTest extends FunctionalTestCase
{
    /**
     * @return void
     */
    public function setUp()
    {
        parent::setUp();

        $route = new Route();
        $route->setName('Functional Test - Session::SessionTest');
        $route->setUriPattern('test/session(/{@action})');
        $route->setDefaults([
            '@package' => 'TYPO3.Flow',
            '@subpackage' => 'Tests\Functional\Session\Fixtures',
            '@controller' => 'SessionTest',
            '@action' => 'sessionStart',
            '@format' =>'html'
        ]);
        $this->router->addRoute($route);
    }

    /**
     * @test
     */
    public function objectManagerAlwaysReturnsTheSameSessionIfInterfaceIsSpecified()
    {
        $session1 = $this->objectManager->get(Session\SessionInterface::class);
        $session2 = $this->objectManager->get(Session\SessionInterface::class);
        $this->assertSame($session1, $session2);
    }

    /**
     * @test
     */
    public function objectManagerAlwaysReturnsANewSessionInstanceIfClassNameIsSpecified()
    {
        $session1 = $this->objectManager->get(Session\Session::class);
        $session2 = $this->objectManager->get(Session\Session::class);
        $this->assertNotSame($session1, $session2);
    }

    /**
     * Checks if getCurrentSessionSession() returns the one and only session which can also
     * be retrieved through Dependency Injection using the SessionInterface.
     *
     * @test
     */
    public function getCurrentSessionReturnsTheCurrentlyActiveSession()
    {
        $injectedSession = $this->objectManager->get(Session\SessionInterface::class);
        $sessionManager = $this->objectManager->get(Session\SessionManagerInterface::class);
        $otherInjectedSession = $this->objectManager->get(Session\SessionInterface::class);

        $retrievedSession = $sessionManager->getCurrentSession();
        $this->assertSame($injectedSession, $retrievedSession);
        $this->assertSame($otherInjectedSession, $retrievedSession);
    }

    /**
     * Makes sure that the functional base testcase initializes an HTTP request and
     * an HTTP response which can be retrieved from the special request handler by
     * the session initialization in order to retrieve or set the session cookie.
     *
     * See bug #43590
     *
     * @test
     */
    public function aSessionCanBeStartedInAFunctionalTest()
    {
        $session = $this->objectManager->get(Session\SessionInterface::class);
        $session->start();
        // dummy assertion to avoid PHPUnit warning
        $this->assertTrue(true);
    }

    /**
     * This test makes sure that if a session is used through the HTTP Browser in
     * a functional test, the Session does not have side effects which result, for
     * example, in a cookie sent only at the end of the first request.
     *
     * @test
     */
    public function aSessionUsedInAFunctionalTestVirtualBrowserSendsCookiesOnEachRequest()
    {
        $response = $this->browser->request('http://localhost/test/session');
        $this->assertTrue($response->hasCookie('TYPO3_Flow_Session'), 'Available Cookies are: ' . implode(', ', array_keys($response->getCookies())));

        $response = $this->browser->request('http://localhost/test/session');
        $this->assertTrue($response->hasCookie('TYPO3_Flow_Session'), 'Available Cookies are: ' . implode(', ', array_keys($response->getCookies())));
    }
}<commit_msg>TASK: Fix session cookie name in SessionManagementTest<commit_after><?php
namespace TYPO3\Flow\Tests\Functional\Session;

/*
 * This file is part of the TYPO3.Flow package.
 *
 * (c) Contributors of the Neos Project - www.neos.io
 *
 * This package is Open Source Software. For the full copyright and license
 * information, please view the LICENSE file which was distributed with this
 * source code.
 */

use TYPO3\Flow\Mvc\Routing\Route;
use TYPO3\Flow\Tests\FunctionalTestCase;
use TYPO3\Flow\Session;

class SessionManagementTest extends FunctionalTestCase
{
    /**
     * @return void
     */
    public function setUp()
    {
        parent::setUp();

        $route = new Route();
        $route->setName('Functional Test - Session::SessionTest');
        $route->setUriPattern('test/session(/{@action})');
        $route->setDefaults([
            '@package' => 'TYPO3.Flow',
            '@subpackage' => 'Tests\Functional\Session\Fixtures',
            '@controller' => 'SessionTest',
            '@action' => 'sessionStart',
            '@format' =>'html'
        ]);
        $this->router->addRoute($route);
    }

    /**
     * @test
     */
    public function objectManagerAlwaysReturnsTheSameSessionIfInterfaceIsSpecified()
    {
        $session1 = $this->objectManager->get(Session\SessionInterface::class);
        $session2 = $this->objectManager->get(Session\SessionInterface::class);
        $this->assertSame($session1, $session2);
    }

    /**
     * @test
     */
    public function objectManagerAlwaysReturnsANewSessionInstanceIfClassNameIsSpecified()
    {
        $session1 = $this->objectManager->get(Session\Session::class);
        $session2 = $this->objectManager->get(Session\Session::class);
        $this->assertNotSame($session1, $session2);
    }

    /**
     * Checks if getCurrentSessionSession() returns the one and only session which can also
     * be retrieved through Dependency Injection using the SessionInterface.
     *
     * @test
     */
    public function getCurrentSessionReturnsTheCurrentlyActiveSession()
    {
        $injectedSession = $this->objectManager->get(Session\SessionInterface::class);
        $sessionManager = $this->objectManager->get(Session\SessionManagerInterface::class);
        $otherInjectedSession = $this->objectManager->get(Session\SessionInterface::class);

        $retrievedSession = $sessionManager->getCurrentSession();
        $this->assertSame($injectedSession, $retrievedSession);
        $this->assertSame($otherInjectedSession, $retrievedSession);
    }

    /**
     * Makes sure that the functional base testcase initializes an HTTP request and
     * an HTTP response which can be retrieved from the special request handler by
     * the session initialization in order to retrieve or set the session cookie.
     *
     * See bug #43590
     *
     * @test
     */
    public function aSessionCanBeStartedInAFunctionalTest()
    {
        $session = $this->objectManager->get(Session\SessionInterface::class);
        $session->start();
        // dummy assertion to avoid PHPUnit warning
        $this->assertTrue(true);
    }

    /**
     * This test makes sure that if a session is used through the HTTP Browser in
     * a functional test, the Session does not have side effects which result, for
     * example, in a cookie sent only at the end of the first request.
     *
     * @test
     */
    public function aSessionUsedInAFunctionalTestVirtualBrowserSendsCookiesOnEachRequest()
    {
        $response = $this->browser->request('http://localhost/test/session');
        $this->assertTrue($response->hasCookie('Neos_Session'), 'Available Cookies are: ' . implode(', ', array_keys($response->getCookies())));

        $response = $this->browser->request('http://localhost/test/session');
        $this->assertTrue($response->hasCookie('Neos_Session'), 'Available Cookies are: ' . implode(', ', array_keys($response->getCookies())));
    }
}
{'fraction_non_alphanumeric': 0.12377808810460836, 'fraction_numerical': 0.00507807540941983, 'mean_word_length': 3.1484992101105846, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1691862', 'n_tokens_mistral': 2153, 'n_tokens_neox': 2115, 'n_words': 504}