Create tests for the basic functionality of the module

Created on 9 December 2024, 12 days ago

Problem/Motivation

We should implement the following tests:

Main module

  • Check if cookie is set with given parameters.
  • Check if the Parameters save mode works as expected.

Submodule

  • Check if the cookie content is saved on the correct User id, when a user is created
  • (Check, that the cookie content is not saved for non anonymous users)

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany Grevil

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Grevil
  • 🇩🇪Germany Grevil

    For some reason the cookie is empty inside the tests. This doesn't make sense and I tried to find a reason why, but couldn't.

    Not even @anybody could help us here, so we will end it here. The module functionality works great on actual sites, but for some reason not inside tests. Setting this to "Needs work". If anybody wants to finish this, go for it!

  • First commit to issue fork.
  • 🇩🇪Germany Anybody Porta Westfalica

    @Grevil: This is what ChatGPT says:

    The issue you're encountering is likely due to the way functional tests handle requests compared to regular requests in Symfony. In functional tests, the request stack might not be fully initialized or populated when you try to access it, which can result in `NULL` values.

    To work around this, you can manually set up the request stack in your functional tests. Here's an example of how you can do this:

    1. **Create a Test Client**: Use Symfony's test client to simulate requests.
    2. **Set Up the Request Stack**: Manually set up the request stack before making the request.

    Here's a sample code snippet:

    ```php
    use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\RequestStack;

    class YourFunctionalTest extends WebTestCase
    {
    public function testYourFunction()
    {
    // Create a client to make requests
    $client = static::createClient();

    // Create a request object
    $request = Request::createFromGlobals();

    // Create a request stack and set the current request
    $requestStack = new RequestStack();
    $requestStack->setCurrentRequest($request);

    // Now you can use $this->requestStack->getCurrentRequest()->query->all()
    $this->requestStack = $requestStack;

    // Make your request
    $crawler = $client->request('GET', '/your-route');

    // Perform your assertions
    $this->assertNotNull($this->requestStack->getCurrentRequest()->query->all());
    }
    }
    ```

    By manually setting up the request stack, you ensure that it is properly initialized and populated with the query parameters, allowing you to access them as expected.

    Source: https://github.com/symfony/symfony/issues/24492

    Looks valid?

  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica
Production build 0.71.5 2024