class SecurityAdvisoriesFetcherTest

Same name in other branches
  1. 10 core/modules/system/tests/src/Kernel/SecurityAdvisories/SecurityAdvisoriesFetcherTest.php \Drupal\Tests\system\Kernel\SecurityAdvisories\SecurityAdvisoriesFetcherTest
  2. 11.x core/modules/system/tests/src/Kernel/SecurityAdvisories/SecurityAdvisoriesFetcherTest.php \Drupal\Tests\system\Kernel\SecurityAdvisories\SecurityAdvisoriesFetcherTest

@coversDefaultClass \Drupal\system\SecurityAdvisories\SecurityAdvisoriesFetcher

@group system

Hierarchy

Expanded class hierarchy of SecurityAdvisoriesFetcherTest

File

core/modules/system/tests/src/Kernel/SecurityAdvisories/SecurityAdvisoriesFetcherTest.php, line 23

Namespace

Drupal\Tests\system\Kernel\SecurityAdvisories
View source
class SecurityAdvisoriesFetcherTest extends KernelTestBase implements LoggerInterface {
    use RfcLoggerTrait;
    
    /**
     * The log messages from watchdog_exception.
     *
     * @var string[]
     */
    protected $watchdogExceptionMessages = [];
    
    /**
     * The log error log messages.
     *
     * @var string[]
     */
    protected $logErrorMessages = [];
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'system',
        'advisory_feed_test',
    ];
    
    /**
     * History of requests/responses.
     *
     * @var array
     */
    protected $history = [];
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->installConfig('system');
        $this->container
            ->get('logger.factory')
            ->addLogger($this);
    }
    
    /**
     * Tests contrib advisories that should be displayed.
     *
     * @param mixed[] $feed_item
     *   The feed item to test. 'title' and 'link' are omitted from this array
     *   because they do not need to vary between test cases.
     * @param string|null $existing_version
     *   The existing version of the module.
     *
     * @dataProvider providerShowAdvisories
     */
    public function testShowAdvisories(array $feed_item, string $existing_version = NULL) : void {
        $this->setFeedItems([
            $feed_item,
        ]);
        if ($existing_version !== NULL) {
            $this->setExistingProjectVersion($existing_version);
        }
        $links = $this->getAdvisories();
        $this->assertCount(1, $links);
        $this->assertSame('http://example.com', $links[0]->getUrl());
        $this->assertSame('SA title', $links[0]->getTitle());
        $this->assertCount(1, $this->history);
    }
    
    /**
     * Data provider for testShowAdvisories().
     */
    public function providerShowAdvisories() : array {
        return [
            'contrib:exact:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-1.0',
                    ],
                ],
                'existing_version' => '8.x-1.0',
            ],
            'contrib:semver:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '1.0.0',
                    ],
                ],
                'existing_version' => '1.0.0',
            ],
            'contrib:exact:psa' => [
                'feed_item' => [
                    'is_psa' => 1,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-1.0',
                    ],
                ],
                'existing_version' => '8.x-1.0',
            ],
            'contrib:not-exact:psa' => [
                'feed_item' => [
                    'is_psa' => 1,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-1.0',
                    ],
                ],
                'existing_version' => '1.0',
            ],
            'contrib:non-matching:psa' => [
                'feed_item' => [
                    'is_psa' => 1,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-1.0',
                    ],
                ],
                'existing_version' => '8.x-2.0',
            ],
            'contrib:no-insecure:psa' => [
                'feed_item' => [
                    'is_psa' => 1,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [],
                ],
                'existing_version' => '8.x-2.0',
            ],
            'contrib:no-existing-version:psa' => [
                'feed_item' => [
                    'is_psa' => 1,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-2.0',
                    ],
                ],
                'existing_version' => '',
            ],
            'contrib:dev:psa' => [
                'feed_item' => [
                    'is_psa' => 1,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [],
                ],
                'existing_version' => '8.x-2.x-dev',
            ],
            'contrib:existing-dev-match-minor:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-1.0',
                    ],
                ],
                'existing_version' => '8.x-1.x-dev',
            ],
            'contrib:existing-dev-match-major-semver:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.1.1',
                    ],
                ],
                'existing_version' => '8.x-dev',
            ],
            'contrib:existing-dev-match-minor-semver:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.2.1',
                    ],
                ],
                'existing_version' => '8.2.x-dev',
            ],
            'core:exact:psa' => [
                'feed_item' => [
                    'is_psa' => 1,
                    'type' => 'core',
                    'project' => 'drupal',
                    'insecure' => [
                        \Drupal::VERSION,
                    ],
                ],
            ],
            'core:exact:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'core',
                    'project' => 'drupal',
                    'insecure' => [
                        \Drupal::VERSION,
                    ],
                ],
            ],
            'core:not-exact:psa' => [
                'feed_item' => [
                    'is_psa' => 1,
                    'type' => 'core',
                    'project' => 'drupal',
                    'insecure' => [
                        '9.1',
                    ],
                ],
            ],
            'core:non-matching:psa' => [
                'feed_item' => [
                    'is_psa' => 1,
                    'type' => 'core',
                    'project' => 'drupal',
                    'insecure' => [
                        '9.0.0',
                    ],
                ],
            ],
            'core:no-insecure:psa' => [
                'feed_item' => [
                    'is_psa' => 1,
                    'type' => 'core',
                    'project' => 'drupal',
                    'insecure' => [],
                ],
            ],
        ];
    }
    
    /**
     * Tests advisories that should be ignored.
     *
     * @param mixed[] $feed_item
     *   The feed item to test. 'title' and 'link' are omitted from this array
     *   because they do not need to vary between test cases.
     * @param string|null $existing_version
     *   The existing version of the module.
     *
     * @dataProvider providerIgnoreAdvisories
     */
    public function testIgnoreAdvisories(array $feed_item, string $existing_version = NULL) : void {
        $this->setFeedItems([
            $feed_item,
        ]);
        if ($existing_version !== NULL) {
            $this->setExistingProjectVersion($existing_version);
        }
        $this->assertCount(0, $this->getAdvisories());
        $this->assertCount(1, $this->history);
    }
    
    /**
     * Data provider for testIgnoreAdvisories().
     */
    public function providerIgnoreAdvisories() : array {
        return [
            'contrib:not-exact:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '1.0',
                    ],
                ],
                'existing_version' => '8.x-1.0',
            ],
            'contrib:non-matching:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-1.1',
                    ],
                ],
                'existing_version' => '8.x-1.0',
            ],
            'contrib:not-exact:non-psa-reversed' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-1.0',
                    ],
                ],
                'existing_version' => '1.0',
            ],
            'contrib:semver-non-exact:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '1.0',
                    ],
                ],
                'existing_version' => '1.0.0',
            ],
            'contrib:semver-major-match-not-minor:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '1.1.0',
                    ],
                ],
                'existing_version' => '1.0.0',
            ],
            'contrib:semver-major-minor-match-not-patch:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '1.1.1',
                    ],
                ],
                'existing_version' => '1.1.0',
            ],
            'contrib:non-matching-not-exact:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '1.1',
                    ],
                ],
                'existing_version' => '8.x-1.0',
            ],
            'contrib:both-extra:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-1.0-extraStringNotSpecial',
                    ],
                ],
                'existing_version' => '8.x-1.0-alsoNotSpecialNotMatching',
            ],
            'contrib:semver-7major-match:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '7.x-1.0',
                    ],
                ],
                'existing_version' => '1.0.0',
            ],
            'contrib:different-majors:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '7.x-1.0',
                    ],
                ],
                'existing_version' => '8.x-1.0',
            ],
            'contrib:semver-different-majors:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '1.0.0',
                    ],
                ],
                'existing_version' => '2.0.0',
            ],
            'contrib:no-version:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-1.1',
                    ],
                ],
                'existing_version' => '',
            ],
            'contrib:insecure-extra:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-1.0-extraStringNotSpecial',
                    ],
                ],
                'existing_version' => '8.x-1.0',
            ],
            'contrib:existing-dev-different-minor:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-1.0',
                    ],
                ],
                'existing_version' => '8.x-2.x-dev',
            ],
            'contrib:existing-dev-different-major:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '7.x-1.0',
                    ],
                ],
                'existing_version' => '8.x-1.x-dev',
            ],
            'contrib:existing-dev-different-major-semver:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.0.0',
                    ],
                ],
                'existing_version' => '9.0.x-dev',
            ],
            'contrib:existing-dev-different-major-no-minor-semver:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.0.0',
                    ],
                ],
                'existing_version' => '9.x-dev',
            ],
            'contrib:existing-dev-different-minor-semver:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '1.0.0',
                    ],
                ],
                'existing_version' => '1.1.0-dev',
            ],
            'contrib:existing-dev-different-minor-x-semver:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '1.0.0',
                    ],
                ],
                'existing_version' => '1.1.x-dev',
            ],
            'contrib:existing-dev-different-8major-semver:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-1.0',
                    ],
                ],
                'existing_version' => '8.x-dev',
            ],
            'contrib:non-existing-project:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'non_existing_project',
                    'insecure' => [
                        '8.x-1.0',
                    ],
                ],
            ],
            'contrib:non-existing-project:psa' => [
                'feed_item' => [
                    'is_psa' => 1,
                    'type' => 'module',
                    'project' => 'non_existing_project',
                    'insecure' => [
                        '8.x-1.0',
                    ],
                ],
            ],
            'core:non-matching:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'core',
                    'project' => 'drupal',
                    'insecure' => [
                        '9.0.0',
                    ],
                ],
            ],
            'core:non-matching-not-exact:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'core',
                    'project' => 'drupal',
                    'insecure' => [
                        '9.1',
                    ],
                ],
            ],
            'core:no-insecure:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'core',
                    'project' => 'drupal',
                    'insecure' => [],
                ],
            ],
            'contrib:existing-extra:non-psa' => [
                'feed_item' => [
                    'is_psa' => 0,
                    'type' => 'module',
                    'project' => 'the_project',
                    'insecure' => [
                        '8.x-1.0',
                    ],
                ],
                'existing_version' => '8.x-1.0-extraStringNotSpecial',
            ],
        ];
    }
    
    /**
     * Sets the feed items to be returned for the test.
     *
     * @param mixed[][] $feed_items
     *   The feeds items to test. Every time the http_client makes a request the
     *   next item in this array will be returned. For each feed item 'title' and
     *   'link' are omitted because they do not need to vary between test cases.
     */
    protected function setFeedItems(array $feed_items) : void {
        $responses = [];
        foreach ($feed_items as $feed_item) {
            $feed_item += [
                'title' => 'SA title',
                'link' => 'http://example.com',
            ];
            $responses[] = new Response('200', [], json_encode([
                $feed_item,
            ]));
        }
        $this->setTestFeedResponses($responses);
    }
    
    /**
     * Sets the existing version of the project.
     *
     * @param string $existing_version
     *   The existing version of the project.
     */
    protected function setExistingProjectVersion(string $existing_version) : void {
        $module_list = $this->prophesize(ModuleExtensionList::class);
        $extension = $this->prophesize(Extension::class)
            ->reveal();
        $extension->info = [
            'project' => 'the_project',
        ];
        if (!empty($existing_version)) {
            $extension->info['version'] = $existing_version;
        }
        $module_list->getList()
            ->willReturn([
            $extension,
        ]);
        $this->container
            ->set('extension.list.module', $module_list->reveal());
    }
    
    /**
     * Tests that the stored advisories response is deleted on interval decrease.
     */
    public function testIntervalConfigUpdate() : void {
        $feed_item_1 = [
            'is_psa' => 1,
            'type' => 'core',
            'title' => 'Oh no🙀! Advisory 1',
            'project' => 'drupal',
            'insecure' => [
                \Drupal::VERSION,
            ],
        ];
        $feed_item_2 = [
            'is_psa' => 1,
            'type' => 'core',
            'title' => 'Oh no😱! Advisory 2',
            'project' => 'drupal',
            'insecure' => [
                \Drupal::VERSION,
            ],
        ];
        $this->setFeedItems([
            $feed_item_1,
            $feed_item_2,
        ]);
        $advisories = $this->getAdvisories();
        $this->assertCount(1, $advisories);
        $this->assertSame($feed_item_1['title'], $advisories[0]->getTitle());
        $this->assertCount(1, $this->history);
        // Ensure that new feed item is not retrieved because the stored response
        // has not expired.
        $advisories = $this->getAdvisories();
        $this->assertCount(1, $this->history);
        $this->assertCount(1, $advisories);
        $this->assertSame($feed_item_1['title'], $advisories[0]->getTitle());
        
        /** @var \Drupal\Core\Config\Config $config */
        $config = $this->container
            ->get('config.factory')
            ->getEditable('system.advisories');
        $interval = $config->get('interval_hours');
        $config->set('interval_hours', $interval + 1)
            ->save();
        // Ensure that new feed item is not retrieved when the interval is
        // increased.
        $advisories = $this->getAdvisories();
        $this->assertCount(1, $this->history);
        $this->assertCount(1, $advisories);
        $this->assertSame($feed_item_1['title'], $advisories[0]->getTitle());
        // Ensure that new feed item is retrieved when the interval is decreased.
        $config->set('interval_hours', $interval - 1)
            ->save();
        $advisories = $this->getAdvisories();
        $this->assertCount(2, $this->history);
        $this->assertCount(1, $advisories);
        $this->assertSame($feed_item_2['title'], $advisories[0]->getTitle());
    }
    
    /**
     * Tests that invalid JSON feed responses are not stored.
     */
    public function testInvalidJsonResponse() : void {
        $non_json_response = new Response(200, [], '1');
        $json_response = new Response(200, [], '[]');
        // Set 2 non-JSON responses and 1 JSON response.
        $this->setTestFeedResponses([
            $non_json_response,
            $non_json_response,
            $json_response,
        ]);
        $this->assertNull($this->getAdvisories());
        $this->assertCount(1, $this->history);
        $this->assertServiceAdvisoryLoggedErrors([
            'The security advisory JSON feed from Drupal.org could not be decoded.',
        ]);
        // Confirm that previous non-JSON response was not stored.
        $this->assertNull($this->getAdvisories());
        $this->assertCount(2, $this->history);
        $this->assertServiceAdvisoryLoggedErrors([
            'The security advisory JSON feed from Drupal.org could not be decoded.',
        ]);
        // Confirm that if $allow_http_request is set to FALSE a new request will
        // not be attempted.
        $this->assertNull($this->getAdvisories(FALSE));
        $this->assertCount(2, $this->history);
        // Make a 3rd request that will return a valid JSON response.
        $this->assertCount(0, $this->getAdvisories());
        $this->assertCount(3, $this->history);
        // Confirm that getting the advisories after a valid JSON response will use
        // the stored response and not make another 'http_client' request.
        $this->assertCount(0, $this->getAdvisories());
        $this->assertCount(3, $this->history);
        $this->assertServiceAdvisoryLoggedErrors([]);
    }
    
    /**
     * @covers ::doRequest
     * @covers ::getSecurityAdvisories
     */
    public function testHttpFallback() : void {
        $this->setSetting('update_fetch_with_http_fallback', TRUE);
        $feed_item = [
            'is_psa' => 1,
            'type' => 'core',
            'project' => 'drupal',
            'insecure' => [
                \Drupal::VERSION,
            ],
            'title' => 'SA title',
            'link' => 'http://example.com',
        ];
        $this->setTestFeedResponses([
            new Response('500', [], 'HTTPS failed'),
            new Response('200', [], json_encode([
                $feed_item,
            ])),
        ]);
        $advisories = $this->getAdvisories();
        // There should be two request / response pairs.
        $this->assertCount(2, $this->history);
        // The first request should have been HTTPS and should have failed.
        $first_try = $this->history[0];
        $this->assertNotEmpty($first_try);
        $this->assertEquals('https', $first_try['request']->getUri()
            ->getScheme());
        $this->assertEquals(500, $first_try['response']->getStatusCode());
        // The second request should have been the HTTP fallback and should have
        // worked.
        $second_try = $this->history[1];
        $this->assertNotEmpty($second_try);
        $this->assertEquals('http', $second_try['request']->getUri()
            ->getScheme());
        $this->assertEquals(200, $second_try['response']->getStatusCode());
        $this->assertCount(1, $advisories);
        $this->assertSame('http://example.com', $advisories[0]->getUrl());
        $this->assertSame('SA title', $advisories[0]->getTitle());
        $this->assertSame([
            "Server error: `GET https://updates.drupal.org/psa.json` resulted in a `500 Internal Server Error` response:\nHTTPS failed\n",
        ], $this->watchdogExceptionMessages);
    }
    
    /**
     * @covers ::doRequest
     * @covers ::getSecurityAdvisories
     */
    public function testNoHttpFallback() : void {
        $this->setTestFeedResponses([
            new Response('500', [], 'HTTPS failed'),
        ]);
        $exception_thrown = FALSE;
        try {
            $this->getAdvisories();
        } catch (TransferException $exception) {
            $this->assertSame("Server error: `GET https://updates.drupal.org/psa.json` resulted in a `500 Internal Server Error` response:\nHTTPS failed\n", $exception->getMessage());
            $exception_thrown = TRUE;
        }
        $this->assertTrue($exception_thrown);
        // There should only be one request / response pair.
        $this->assertCount(1, $this->history);
        $request = $this->history[0]['request'];
        $this->assertNotEmpty($request);
        // It should have only been an HTTPS request.
        $this->assertEquals('https', $request->getUri()
            ->getScheme());
        // And it should have failed.
        $response = $this->history[0]['response'];
        $this->assertEquals(500, $response->getStatusCode());
    }
    
    /**
     * Gets the advisories from the 'system.sa_fetcher' service.
     *
     * @param bool $allow_http_request
     *   Argument to pass on to
     *   SecurityAdvisoriesFetcher::getSecurityAdvisories().
     *
     * @return \Drupal\system\SecurityAdvisories\SecurityAdvisory[]|null
     *   The return value of SecurityAdvisoriesFetcher::getSecurityAdvisories().
     */
    protected function getAdvisories(bool $allow_http_request = TRUE) : ?array {
        $fetcher = $this->container
            ->get('system.sa_fetcher');
        return $fetcher->getSecurityAdvisories($allow_http_request);
    }
    
    /**
     * Sets test feed responses.
     *
     * @param \GuzzleHttp\Psr7\Response[] $responses
     *   The responses for the http_client service to return.
     */
    protected function setTestFeedResponses(array $responses) : void {
        // Create a mock and queue responses.
        $mock = new MockHandler($responses);
        $handler_stack = HandlerStack::create($mock);
        $history = Middleware::history($this->history);
        $handler_stack->push($history);
        // Rebuild the container because the 'system.sa_fetcher' service and other
        // services may already have an instantiated instance of the 'http_client'
        // service without these changes.
        $this->container
            ->get('kernel')
            ->rebuildContainer();
        $this->container = $this->container
            ->get('kernel')
            ->getContainer();
        $this->container
            ->get('logger.factory')
            ->addLogger($this);
        $this->container
            ->set('http_client', new Client([
            'handler' => $handler_stack,
        ]));
    }
    
    /**
     * Asserts the expected error messages were logged.
     *
     * @param string[] $expected_messages
     *   The expected error messages.
     *
     * @internal
     */
    protected function assertServiceAdvisoryLoggedErrors(array $expected_messages) : void {
        $this->assertSame($expected_messages, $this->logErrorMessages);
        $this->logErrorMessages = [];
    }
    
    /**
     * {@inheritdoc}
     */
    public function log($level, $message, array $context = []) : void {
        if (isset($context['@message'])) {
            $this->watchdogExceptionMessages[] = $context['@message'];
        }
        if ($level === RfcLogLevel::ERROR) {
            $this->logErrorMessages[] = $message;
        }
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
AssertContentTrait::$content protected property The current raw content.
AssertContentTrait::$drupalSettings protected property The drupalSettings value from the current raw $content.
AssertContentTrait::$elements protected property The XML structure parsed from the current raw $content. 1
AssertContentTrait::$plainTextContent protected property The plain-text content of raw $content (text nodes).
AssertContentTrait::assertEscaped protected function Passes if the raw text IS found escaped on the loaded page, fail otherwise.
AssertContentTrait::assertField protected function Asserts that a field exists with the given name or ID.
AssertContentTrait::assertFieldById protected function Asserts that a field exists with the given ID and value.
AssertContentTrait::assertFieldByName protected function Asserts that a field exists with the given name and value.
AssertContentTrait::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
AssertContentTrait::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
AssertContentTrait::assertFieldsByValue protected function Asserts that a field exists in the current page with a given Xpath result.
AssertContentTrait::assertLink protected function Passes if a link with the specified label is found.
AssertContentTrait::assertLinkByHref protected function Passes if a link containing a given href (part) is found.
AssertContentTrait::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
AssertContentTrait::assertNoEscaped protected function Passes if raw text IS NOT found escaped on loaded page, fail otherwise.
AssertContentTrait::assertNoField protected function Asserts that a field does not exist with the given name or ID.
AssertContentTrait::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
AssertContentTrait::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
AssertContentTrait::assertNoFieldByXPath protected function Asserts that a field does not exist or its value does not match, by XPath.
AssertContentTrait::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
AssertContentTrait::assertNoLink protected function Passes if a link with the specified label is not found.
AssertContentTrait::assertNoLinkByHref protected function Passes if a link containing a given href (part) is not found.
AssertContentTrait::assertNoLinkByHrefInMainRegion protected function Passes if a link containing a given href is not found in the main region.
AssertContentTrait::assertNoOption protected function Asserts that a select option in the current page does not exist.
AssertContentTrait::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
AssertContentTrait::assertNoPattern protected function Triggers a pass if the perl regex pattern is not found in raw content.
AssertContentTrait::assertNoRaw protected function Passes if the raw text is NOT found on the loaded page, fail otherwise.
AssertContentTrait::assertNoText protected function Passes if the page (with HTML stripped) does not contains the text.
AssertContentTrait::assertNoTitle protected function Pass if the page title is not the given string.
AssertContentTrait::assertNoUniqueText protected function Passes if the text is found MORE THAN ONCE on the text version of the page.
AssertContentTrait::assertOption protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertOptionByText protected function Asserts that a select option with the visible text exists.
AssertContentTrait::assertOptionSelected protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionSelectedWithDrupalSelector protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionWithDrupalSelector protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertPattern protected function Triggers a pass if the Perl regex pattern is found in the raw content.
AssertContentTrait::assertRaw protected function Passes if the raw text IS found on the loaded page, fail otherwise.
AssertContentTrait::assertText protected function Passes if the page (with HTML stripped) contains the text.
AssertContentTrait::assertTextHelper protected function Helper for assertText and assertNoText.
AssertContentTrait::assertTextPattern protected function Asserts that a Perl regex pattern is found in the plain-text content.
AssertContentTrait::assertThemeOutput protected function Asserts themed output.
AssertContentTrait::assertTitle protected function Pass if the page title is the given string.
AssertContentTrait::assertUniqueText protected function Passes if the text is found ONLY ONCE on the text version of the page.
AssertContentTrait::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
AssertContentTrait::buildXPathQuery protected function Builds an XPath query.
AssertContentTrait::constructFieldXpath protected function Helper: Constructs an XPath for the given set of attributes and value.
AssertContentTrait::cssSelect protected function Searches elements using a CSS selector in the raw content.
AssertContentTrait::getAllOptions protected function Get all option elements, including nested options, in a select.
AssertContentTrait::getDrupalSettings protected function Gets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::getRawContent protected function Gets the current raw content.
AssertContentTrait::getSelectedItem protected function Get the selected value from a select field.
AssertContentTrait::getTextContent protected function Retrieves the plain-text content from the current raw content.
AssertContentTrait::getUrl protected function Get the current URL from the cURL handler. 1
AssertContentTrait::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
AssertContentTrait::removeWhiteSpace protected function Removes all white-space between HTML tags from the raw content.
AssertContentTrait::setDrupalSettings protected function Sets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::setRawContent protected function Sets the raw content (e.g. HTML).
AssertContentTrait::xpath protected function Performs an xpath search on the contents of the internal browser.
AssertLegacyTrait::assert Deprecated protected function
AssertLegacyTrait::assertEqual Deprecated protected function
AssertLegacyTrait::assertIdentical Deprecated protected function
AssertLegacyTrait::assertIdenticalObject Deprecated protected function
AssertLegacyTrait::assertNotEqual Deprecated protected function
AssertLegacyTrait::assertNotIdentical Deprecated protected function
AssertLegacyTrait::pass Deprecated protected function
AssertLegacyTrait::verbose Deprecated protected function
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
ExtensionListTestTrait::getModulePath protected function Gets the path for the specified module.
ExtensionListTestTrait::getThemePath protected function Gets the path for the specified theme.
KernelTestBase::$backupGlobals protected property Back up and restore any global variables that may be changed by tests.
KernelTestBase::$backupStaticAttributes protected property Back up and restore static class properties that may be changed by tests.
KernelTestBase::$backupStaticAttributesBlacklist protected property Contains a few static class properties for performance.
KernelTestBase::$classLoader protected property
KernelTestBase::$configImporter protected property @todo Move into Config test base class. 6
KernelTestBase::$configSchemaCheckerExclusions protected static property An array of config object names that are excluded from schema checking.
KernelTestBase::$container protected property
KernelTestBase::$databasePrefix protected property
KernelTestBase::$keyValue protected property The key_value service that must persist between container rebuilds.
KernelTestBase::$preserveGlobalState protected property Do not forward any global state from the parent process to the processes
that run the actual tests.
KernelTestBase::$root protected property The app root.
KernelTestBase::$runTestInSeparateProcess protected property Kernel tests are run in separate processes because they allow autoloading
of code from extensions. Running the test in a separate process isolates
this behavior from other tests. Subclasses should not override this
property.
KernelTestBase::$siteDirectory protected property
KernelTestBase::$strictConfigSchema protected property Set to TRUE to strict check all configuration saved. 7
KernelTestBase::$vfsRoot protected property The virtual filesystem root directory.
KernelTestBase::assertPostConditions protected function 1
KernelTestBase::bootEnvironment protected function Bootstraps a basic test environment.
KernelTestBase::bootKernel private function Bootstraps a kernel for a test.
KernelTestBase::config protected function Configuration accessor for tests. Returns non-overridden configuration.
KernelTestBase::disableModules protected function Disables modules for this test.
KernelTestBase::enableModules protected function Enables modules for this test.
KernelTestBase::getConfigSchemaExclusions protected function Gets the config schema exclusions for this test.
KernelTestBase::getDatabaseConnectionInfo protected function Returns the Database connection info to be used for this test. 3
KernelTestBase::getDatabasePrefix public function
KernelTestBase::getExtensionsForModules private function Returns Extension objects for $modules to enable.
KernelTestBase::getModulesToEnable private static function Returns the modules to enable for this test.
KernelTestBase::initFileCache protected function Initializes the FileCache component.
KernelTestBase::installConfig protected function Installs default configuration for a given list of modules.
KernelTestBase::installEntitySchema protected function Installs the storage schema for a specific entity type.
KernelTestBase::installSchema protected function Installs database tables from a module schema definition.
KernelTestBase::register public function Registers test-specific services. Overrides ServiceProviderInterface::register 26
KernelTestBase::render protected function Renders a render array. 1
KernelTestBase::setInstallProfile protected function Sets the install profile and rebuilds the container to update it.
KernelTestBase::setSetting protected function Sets an in-memory Settings variable.
KernelTestBase::setUpBeforeClass public static function 1
KernelTestBase::setUpFilesystem protected function Sets up the filesystem, so things like the file directory. 3
KernelTestBase::stop protected function Stops test execution.
KernelTestBase::tearDown protected function 5
KernelTestBase::tearDownCloseDatabaseConnection public function @after
KernelTestBase::vfsDump protected function Dumps the current state of the virtual filesystem to STDOUT.
KernelTestBase::__sleep public function Prevents serializing any properties.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RandomGeneratorTrait::$randomGenerator protected property The random generator.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers. 1
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate public function Callback for random string validation.
RfcLoggerTrait::alert public function
RfcLoggerTrait::critical public function
RfcLoggerTrait::debug public function
RfcLoggerTrait::emergency public function
RfcLoggerTrait::error public function
RfcLoggerTrait::info public function
RfcLoggerTrait::notice public function
RfcLoggerTrait::warning public function
SecurityAdvisoriesFetcherTest::$history protected property History of requests/responses.
SecurityAdvisoriesFetcherTest::$logErrorMessages protected property The log error log messages.
SecurityAdvisoriesFetcherTest::$modules protected static property Modules to enable. Overrides KernelTestBase::$modules
SecurityAdvisoriesFetcherTest::$watchdogExceptionMessages protected property The log messages from watchdog_exception.
SecurityAdvisoriesFetcherTest::assertServiceAdvisoryLoggedErrors protected function Asserts the expected error messages were logged.
SecurityAdvisoriesFetcherTest::getAdvisories protected function Gets the advisories from the 'system.sa_fetcher' service.
SecurityAdvisoriesFetcherTest::log public function Overrides RfcLoggerTrait::log
SecurityAdvisoriesFetcherTest::providerIgnoreAdvisories public function Data provider for testIgnoreAdvisories().
SecurityAdvisoriesFetcherTest::providerShowAdvisories public function Data provider for testShowAdvisories().
SecurityAdvisoriesFetcherTest::setExistingProjectVersion protected function Sets the existing version of the project.
SecurityAdvisoriesFetcherTest::setFeedItems protected function Sets the feed items to be returned for the test.
SecurityAdvisoriesFetcherTest::setTestFeedResponses protected function Sets test feed responses.
SecurityAdvisoriesFetcherTest::setUp protected function Overrides KernelTestBase::setUp
SecurityAdvisoriesFetcherTest::testHttpFallback public function @covers ::doRequest
@covers ::getSecurityAdvisories
SecurityAdvisoriesFetcherTest::testIgnoreAdvisories public function Tests advisories that should be ignored.
SecurityAdvisoriesFetcherTest::testIntervalConfigUpdate public function Tests that the stored advisories response is deleted on interval decrease.
SecurityAdvisoriesFetcherTest::testInvalidJsonResponse public function Tests that invalid JSON feed responses are not stored.
SecurityAdvisoriesFetcherTest::testNoHttpFallback public function @covers ::doRequest
@covers ::getSecurityAdvisories
SecurityAdvisoriesFetcherTest::testShowAdvisories public function Tests contrib advisories that should be displayed.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements protected function Check module requirements for the Drupal use case.
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.

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