<commit_before><?php

namespace App\Test\TestCase\Event;

use App\Event\Controller\Api\LookupActionListener;
use App\Event\EventName;
use Cake\Controller\Controller;
use Cake\Event\Event;
use Cake\Http\ServerRequest;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;

class LookupActionListenerTest extends TestCase
{
    private $Users;

    public $fixtures = [
        'app.users',
        'plugin.Groups.groups',
        'plugin.Groups.groups_users',
    ];

    public function setUp()
    {
        parent::setUp();

        $this->Users = TableRegistry::get('Users');
    }

    public function testBeforeLookupEmptyQuery(): void
    {
        $query = $this->Users->find('all');
        $controller = new Controller($this->getRequest(), null, 'Users');
        $event = new Event(
            (string)EventName::API_LOOKUP_BEFORE_FIND(),
            $controller
        );

        $listener = new LookupActionListener();
        $listener->beforeLookup($event, $query);
        $this->assertEquals(10, $query->count());
    }

    public function testBeforeLookupWithQuery(): void
    {
        $query = $this->Users->find('all');
        $controller = new Controller($this->getRequest(['query' => 'user-1']), null, 'Users');
        $event = new Event(
            (string)EventName::API_LOOKUP_BEFORE_FIND(),
            $controller
        );

        $listener = new LookupActionListener();
        $listener->beforeLookup($event, $query);
        $this->assertEquals(1, $query->count());
    }

    /**
     * @param mixed[] $query Query parameters
     */
    private function getRequest(array $query = []): ServerRequest
    {
        return new ServerRequest([
            'params' => [
                'controller' => 'Users',
                'action' => 'lookup',
                'pass' => [],
                'prefix' => 'api/v1/v0',
                'plugin' => null,
                '_ext' => 'json',
                '_matchedRoute' => '/api/:controller/:action/*',
                'isAjax' => true
            ],
            'query' => $query,
        ]);
    }
}
<commit_msg>Adjusted assertion (task #8712)<commit_after><?php

namespace App\Test\TestCase\Event;

use App\Event\Controller\Api\LookupActionListener;
use App\Event\EventName;
use Cake\Controller\Controller;
use Cake\Event\Event;
use Cake\Http\ServerRequest;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;

class LookupActionListenerTest extends TestCase
{
    private $Users;

    public $fixtures = [
        'app.users',
        'plugin.Groups.groups',
        'plugin.Groups.groups_users',
    ];

    public function setUp()
    {
        parent::setUp();

        $this->Users = TableRegistry::get('Users');
    }

    public function testBeforeLookupEmptyQuery(): void
    {
        $query = $this->Users->find('all');
        $controller = new Controller($this->getRequest(), null, 'Users');
        $event = new Event(
            (string)EventName::API_LOOKUP_BEFORE_FIND(),
            $controller
        );

        $listener = new LookupActionListener();
        $listener->beforeLookup($event, $query);
        $this->assertFalse($query->isEmpty());
    }

    public function testBeforeLookupWithQuery(): void
    {
        $query = $this->Users->find('all');
        $controller = new Controller($this->getRequest(['query' => 'user-1']), null, 'Users');
        $event = new Event(
            (string)EventName::API_LOOKUP_BEFORE_FIND(),
            $controller
        );

        $listener = new LookupActionListener();
        $listener->beforeLookup($event, $query);
        $this->assertEquals(1, $query->count());
    }

    /**
     * @param mixed[] $query Query parameters
     */
    private function getRequest(array $query = []): ServerRequest
    {
        return new ServerRequest([
            'params' => [
                'controller' => 'Users',
                'action' => 'lookup',
                'pass' => [],
                'prefix' => 'api/v1/v0',
                'plugin' => null,
                '_ext' => 'json',
                '_matchedRoute' => '/api/:controller/:action/*',
                'isAjax' => true
            ],
            'query' => $query,
        ]);
    }
}

{'fraction_non_alphanumeric': 0.15242603550295858, 'fraction_numerical': 0.0033136094674556214, 'mean_word_length': 2.1608077786088256, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '6713692', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1175, 'n_words': 226}