<commit_before><?php
/**
 * WellCommerce Open-Source E-Commerce Platform
 *
 * This file is part of the WellCommerce package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information,
 * please view the LICENSE file that was distributed with this source code.
 */

namespace WellCommerce\Bundle\WishlistBundle\Tests\Controller\Front;

use Doctrine\Common\Collections\Collection;
use WellCommerce\Bundle\CoreBundle\Test\Controller\Front\AbstractFrontControllerTestCase;
use WellCommerce\Bundle\ProductBundle\Entity\ProductInterface;
use WellCommerce\Bundle\WishlistBundle\Entity\WishlistInterface;

/**
 * Class WishlistControllerTest
 *
 * @author  <NAME> <<EMAIL>>
 */
class WishlistControllerTest extends AbstractFrontControllerTestCase
{
    public function testIndexActionForGuest()
    {
        $url         = $this->generateUrl('front.wishlist.index');
        $redirectUrl = $this->generateUrl('front.client.login', [], false);
        $this->client->request('GET', $url);
        
        $this->assertTrue($this->client->getResponse()->isRedirect($redirectUrl), sprintf(
            'Location: %s',
            'Redirect: %s',
            $this->client->getResponse()->headers->get('location'),
            $redirectUrl
        ));
    }
    
    public function testIndexClientActionForClient()
    {
        $this->logIn();
        $url = $this->generateUrl('front.wishlist.index');
        
        $this->client->request('GET', $url);
        $this->assertTrue($this->client->getResponse()->isSuccessful());
    }
    
    public function testAddActionForGuest()
    {
        $product = $this->container->get('product.repository')->findOneBy(['enabled' => true]);
        if ($product instanceof ProductInterface) {
            $url         = $this->generateUrl('front.wishlist.add', ['id' => $product->getId()]);
            $redirectUrl = $this->generateUrl('front.client.login', [], false);
            $this->client->request('GET', $url);
    
            $this->assertTrue($this->client->getResponse()->isRedirect($redirectUrl), sprintf(
                'Location: %s',
                'Redirect: %s',
                $this->client->getResponse()->headers->get('location'),
                $redirectUrl
            ));
        }
    }
    
    public function testAddActionForClient()
    {
        $this->logIn();
        
        $product = $this->container->get('product.repository')->findOneBy(['enabled' => true]);
        if ($product instanceof ProductInterface) {
            $url         = $this->generateUrl('front.wishlist.add', ['id' => $product->getId()]);
            $redirectUrl = $this->generateUrl('front.wishlist.index', [], false);
            $this->client->request('GET', $url);
            
            $this->assertTrue($this->client->getResponse()->isRedirect($redirectUrl));
        }
    }
    
    public function testDeleteAction()
    {
        $client = $this->logIn();
        
        /** @var Collection $wishlist */<commit_msg>Additional tests<commit_after><?php
/**
 * WellCommerce Open-Source E-Commerce Platform
 *
 * This file is part of the WellCommerce package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information,
 * please view the LICENSE file that was distributed with this source code.
 */

namespace WellCommerce\Bundle\WishlistBundle\Tests\Controller\Front;

use Doctrine\Common\Collections\Collection;
use WellCommerce\Bundle\CoreBundle\Test\Controller\Front\AbstractFrontControllerTestCase;
use WellCommerce\Bundle\ProductBundle\Entity\ProductInterface;
use WellCommerce\Bundle\WishlistBundle\Entity\WishlistInterface;

/**
 * Class WishlistControllerTest
 *
 * @author  <NAME> <<EMAIL>>
 */
class WishlistControllerTest extends AbstractFrontControllerTestCase
{
    public function testIndexActionForGuest()
    {
        $url         = $this->generateUrl('front.wishlist.index');
        $redirectUrl = $this->generateUrl('front.client.login', [], false);
        $this->client->request('GET', $url);
        
        $this->assertTrue($this->client->getResponse()->isRedirect($redirectUrl), sprintf(
            'Location: %s, Redirect: %s',
            $this->client->getResponse()->headers->get('location'),
            $redirectUrl
        ));
    }
    
    public function testIndexClientActionForClient()
    {
        $this->logIn();
        $url = $this->generateUrl('front.wishlist.index');
        
        $this->client->request('GET', $url);
        $this->assertTrue($this->client->getResponse()->isSuccessful());
    }
    
    public function testAddActionForGuest()
    {
        $product = $this->container->get('product.repository')->findOneBy(['enabled' => true]);
        if ($product instanceof ProductInterface) {
            $url         = $this->generateUrl('front.wishlist.add', ['id' => $product->getId()]);
            $redirectUrl = $this->generateUrl('front.client.login', [], false);
            $this->client->request('GET', $url);
    
            $this->assertTrue($this->client->getResponse()->isRedirect($redirectUrl), sprintf(
                'Location: %s, Redirect: %s',
                $this->client->getResponse()->headers->get('location'),
                $redirectUrl
            ));
        }
    }
    
    public function testAddActionForClient()
    {
        $this->logIn();
        
        $product = $this->container->get('product.repository')->findOneBy(['enabled' => true]);
        if ($product instanceof ProductInterface) {
            $url         = $this->generateUrl('front.wishlist.add', ['id' => $product->getId()]);
            $redirectUrl = $this->generateUrl('front.wishlist.index', [], false);
            $this->client->request('GET', $url);
            
            $this->assertTrue($this->client->getResponse()->isRedirect($redirectUrl));
        }
    }
    
    public function testDeleteAction()
    {
        $client = $this->logIn();
        
        /** @var Collection $wishlist */
{'fraction_non_alphanumeric': 0.1581675305132921, 'fraction_numerical': 0.0, 'mean_word_length': 2.7109181141439205, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 123, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '928155', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1621, 'n_words': 275}