class EnvironmentSupportValidatorTest

@covers \Drupal\package_manager\Validator\EnvironmentSupportValidator @group package_manager @internal

Hierarchy

Expanded class hierarchy of EnvironmentSupportValidatorTest

File

core/modules/package_manager/tests/src/Kernel/EnvironmentSupportValidatorTest.php, line 18

Namespace

Drupal\Tests\package_manager\Kernel
View source
class EnvironmentSupportValidatorTest extends PackageManagerKernelTestBase {
    
    /**
     * Tests handling of an invalid URL in the environment support variable.
     */
    public function testInvalidUrl() : void {
        putenv(EnvironmentSupportValidator::VARIABLE_NAME . '=broken/url.org');
        $result = ValidationResult::createError([
            t('Package Manager is not supported by your environment.'),
        ]);
        foreach ([
            PreCreateEvent::class,
            StatusCheckEvent::class,
        ] as $event_class) {
            $this->assertEventPropagationStopped($event_class, [
                $this->container
                    ->get(EnvironmentSupportValidator::class),
                'validate',
            ]);
        }
        $this->assertStatusCheckResults([
            $result,
        ]);
        $this->assertResults([
            $result,
        ], PreCreateEvent::class);
    }
    
    /**
     * Tests an invalid URL in the environment support variable during pre-apply.
     */
    public function testInvalidUrlDuringPreApply() : void {
        $this->addEventTestListener(function () : void {
            putenv(EnvironmentSupportValidator::VARIABLE_NAME . '=broken/url.org');
        });
        $result = ValidationResult::createError([
            t('Package Manager is not supported by your environment.'),
        ]);
        $this->assertEventPropagationStopped(PreApplyEvent::class, [
            $this->container
                ->get(EnvironmentSupportValidator::class),
            'validate',
        ]);
        $this->assertResults([
            $result,
        ], PreApplyEvent::class);
    }
    
    /**
     * Tests that the validation message links to the provided URL.
     */
    public function testValidUrl() : void {
        $url = 'http://www.example.com';
        putenv(EnvironmentSupportValidator::VARIABLE_NAME . '=' . $url);
        $result = ValidationResult::createError([
            t('<a href=":url">Package Manager is not supported by your environment.</a>', [
                ':url' => $url,
            ]),
        ]);
        $this->assertStatusCheckResults([
            $result,
        ]);
        $this->assertResults([
            $result,
        ], PreCreateEvent::class);
    }
    
    /**
     * Tests that the validation message links to the provided URL during pre-apply.
     */
    public function testValidUrlDuringPreApply() : void {
        $url = 'http://www.example.com';
        $this->addEventTestListener(function () use ($url) : void {
            putenv(EnvironmentSupportValidator::VARIABLE_NAME . '=' . $url);
        });
        $result = ValidationResult::createError([
            t('<a href=":url">Package Manager is not supported by your environment.</a>', [
                ':url' => $url,
            ]),
        ]);
        $this->assertResults([
            $result,
        ], PreApplyEvent::class);
    }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.