<commit_before><?php
namespace Czim\CmsModels\Test;

use Czim\CmsCore\Contracts\Auth\AuthenticatorInterface;
use Czim\CmsCore\Providers\CmsCoreServiceProvider;
use Czim\CmsCore\Support\Enums\CmsMiddleware;
use Czim\CmsCore\Support\Enums\Component;
use Czim\CmsCore\Support\Enums\NamedRoute;
use Czim\CmsModels\Providers\CmsModelsServiceProvider;
use Czim\CmsModels\Test\Helpers\Http\Controllers\MockAuthController;
use Illuminate\Contracts\Foundation\Application;

abstract class CmsBootTestCase extends DatabaseTestCase
{

    /**
     * Whether the mocked user should be treated as a super admin.
     *
     * @var bool
     */
    protected $mockSuperAdmin = true;

    /**
     * Which permissions should be available for the (non-admin) mocked user.
     *
     * @var string[]
     */
    protected $mockPermissions = [];


    /**
     * {@inheritdoc}
     */
    protected function getEnvironmentSetUp($app)
    {
        parent::getEnvironmentSetUp($app);

        // Load the CMS even when unit testing
        $app['config']->set('cms-core.testing', true);

        // Set up service providers for tests, excluding what is not part of this package
        $app['config']->set('cms-core.providers', [
            \Czim\CmsCore\Providers\ModuleManagerServiceProvider::class,
            \Czim\CmsCore\Providers\LogServiceProvider::class,
            \Czim\CmsCore\Providers\MiddlewareServiceProvider::class,
            \Czim\CmsCore\Providers\MigrationServiceProvider::class,
            \Czim\CmsCore\Providers\ViewServiceProvider::class,

            //\Czim\CmsAuth\Providers\CmsAuthServiceProvider::class,
            //\Czim\CmsTheme\Providers\CmsThemeServiceProvider::class,
            //\Czim\CmsAuth\Providers\Api\OAuthSetupServiceProvider::class,

            CmsModelsServiceProvider::class,

            \Czim\CmsCore\Providers\Api\CmsCoreApiServiceProvider::class,
            \Czim\CmsCore\Providers\RouteServiceProvider::class,
            \Czim\CmsCore\Providers\Api\ApiRouteServiceProvider::class,
        ]);

        $app['config']->set('cms-api.providers', []);

        // Mock component bindings in the config
        $app['config']->set(
            'cms-core.bindings', [
            Component::BOOTCHECKER => $this->getTestBootCheckerBinding(),
            Component::CACHE       => \Czim\CmsCore\Core\Cache::class,
            Component::CORE        => \Czim\CmsCore\Core\Core::class,
            Component::MODULES     => \Czim\CmsCore\Modules\ModuleManager::class,
            Component::API         => \Czim\CmsCore\Api\ApiCore::class,
            Component::ACL         => \Czim\CmsCore\Auth\AclRepository::class,
            Component::MENU        => \Czim\CmsCore\Menu\MenuRepository::class,
            Component::AUTH        => 'mock-cms-auth',
        ]);

        $this->mockBoundCoreExternalComponents($app);

        $app->register(CmsCoreServiceProvider::class);
    }

    /**
     * @return string
     */
    protected function getTestBootCheckerBinding()
    {
        return \Czim\CmsCore\Core\BootChecker::class;
    }

    /**
     * Mocks components that should not be part of any core test.
     *
     * @param Application $app
     * @return $this
     */
    protected function mockBoundCoreExternalComponents($app)
    {
        $app->bind('mock-cms-auth', function () {

            $mock = $this->getMockBuilder(AuthenticatorInterface::class)->getMock();

            // Mock permissions of the user
            $mock->method('amin')->willReturn($this->mockSuperAdmin);
            $mock->method('can')->willReturnCallback(function ($permissions, $any = false) {
                if ($this->mockSuperAdmin) {
                    return true;
                }
                $permissions = (array) $permissions;
                if ($any) {
                    return (bool) count(array_intersect($permissions, $this->mockPermissions));
                }
                return ! (bool) array_diff($permissions, $this->mockPermissions);
            });
            $mock->method('canAnyOf')->willReturnCallback(function ($permissions) {
                if ($this->mockSuperAdmin) {
                    return true;
                }
                return (bool) count(array_intersect($permissions, $this->mockPermissions));
            });

            // Mock the authentication routes
            $mock->method('getRouteLoginAction')
                ->willReturn([
                    'middleware' => [ CmsMiddleware::GUEST ],<commit_msg>Fixed typo in mocked method<commit_after><?php
namespace Czim\CmsModels\Test;

use Czim\CmsCore\Contracts\Auth\AuthenticatorInterface;
use Czim\CmsCore\Providers\CmsCoreServiceProvider;
use Czim\CmsCore\Support\Enums\CmsMiddleware;
use Czim\CmsCore\Support\Enums\Component;
use Czim\CmsCore\Support\Enums\NamedRoute;
use Czim\CmsModels\Providers\CmsModelsServiceProvider;
use Czim\CmsModels\Test\Helpers\Http\Controllers\MockAuthController;
use Illuminate\Contracts\Foundation\Application;

abstract class CmsBootTestCase extends DatabaseTestCase
{

    /**
     * Whether the mocked user should be treated as a super admin.
     *
     * @var bool
     */
    protected $mockSuperAdmin = true;

    /**
     * Which permissions should be available for the (non-admin) mocked user.
     *
     * @var string[]
     */
    protected $mockPermissions = [];


    /**
     * {@inheritdoc}
     */
    protected function getEnvironmentSetUp($app)
    {
        parent::getEnvironmentSetUp($app);

        // Load the CMS even when unit testing
        $app['config']->set('cms-core.testing', true);

        // Set up service providers for tests, excluding what is not part of this package
        $app['config']->set('cms-core.providers', [
            \Czim\CmsCore\Providers\ModuleManagerServiceProvider::class,
            \Czim\CmsCore\Providers\LogServiceProvider::class,
            \Czim\CmsCore\Providers\MiddlewareServiceProvider::class,
            \Czim\CmsCore\Providers\MigrationServiceProvider::class,
            \Czim\CmsCore\Providers\ViewServiceProvider::class,

            //\Czim\CmsAuth\Providers\CmsAuthServiceProvider::class,
            //\Czim\CmsTheme\Providers\CmsThemeServiceProvider::class,
            //\Czim\CmsAuth\Providers\Api\OAuthSetupServiceProvider::class,

            CmsModelsServiceProvider::class,

            \Czim\CmsCore\Providers\Api\CmsCoreApiServiceProvider::class,
            \Czim\CmsCore\Providers\RouteServiceProvider::class,
            \Czim\CmsCore\Providers\Api\ApiRouteServiceProvider::class,
        ]);

        $app['config']->set('cms-api.providers', []);

        // Mock component bindings in the config
        $app['config']->set(
            'cms-core.bindings', [
            Component::BOOTCHECKER => $this->getTestBootCheckerBinding(),
            Component::CACHE       => \Czim\CmsCore\Core\Cache::class,
            Component::CORE        => \Czim\CmsCore\Core\Core::class,
            Component::MODULES     => \Czim\CmsCore\Modules\ModuleManager::class,
            Component::API         => \Czim\CmsCore\Api\ApiCore::class,
            Component::ACL         => \Czim\CmsCore\Auth\AclRepository::class,
            Component::MENU        => \Czim\CmsCore\Menu\MenuRepository::class,
            Component::AUTH        => 'mock-cms-auth',
        ]);

        $this->mockBoundCoreExternalComponents($app);

        $app->register(CmsCoreServiceProvider::class);
    }

    /**
     * @return string
     */
    protected function getTestBootCheckerBinding()
    {
        return \Czim\CmsCore\Core\BootChecker::class;
    }

    /**
     * Mocks components that should not be part of any core test.
     *
     * @param Application $app
     * @return $this
     */
    protected function mockBoundCoreExternalComponents($app)
    {
        $app->bind('mock-cms-auth', function () {

            $mock = $this->getMockBuilder(AuthenticatorInterface::class)->getMock();

            // Mock permissions of the user
            $mock->method('admin')->willReturn($this->mockSuperAdmin);
            $mock->method('can')->willReturnCallback(function ($permissions, $any = false) {
                if ($this->mockSuperAdmin) {
                    return true;
                }
                $permissions = (array) $permissions;
                if ($any) {
                    return (bool) count(array_intersect($permissions, $this->mockPermissions));
                }
                return ! (bool) array_diff($permissions, $this->mockPermissions);
            });
            $mock->method('canAnyOf')->willReturnCallback(function ($permissions) {
                if ($this->mockSuperAdmin) {
                    return true;
                }
                return (bool) count(array_intersect($permissions, $this->mockPermissions));
            });

            // Mock the authentication routes
            $mock->method('getRouteLoginAction')
                ->willReturn([
                    'middleware' => [ CmsMiddleware::GUEST ],
{'fraction_non_alphanumeric': 0.1247645429362881, 'fraction_numerical': 0.0, 'mean_word_length': 2.3074386222059364, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, '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': '5364166', 'n_tokens_mistral': 2589, 'n_tokens_neox': 2558, 'n_words': 398}