class AnnounceFetcherUnitTest
Same name and namespace in other branches
- 11.x core/modules/announcements_feed/tests/src/Unit/AnnounceFetcherUnitTest.php \Drupal\Tests\announcements_feed\Unit\AnnounceFetcherUnitTest
- 10 core/modules/announcements_feed/tests/src/Unit/AnnounceFetcherUnitTest.php \Drupal\Tests\announcements_feed\Unit\AnnounceFetcherUnitTest
Simple test to ensure that asserts pass.
Attributes
#[Group('announcements_feed')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\announcements_feed\Unit\AnnounceFetcherUnitTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of AnnounceFetcherUnitTest
File
-
core/
modules/ announcements_feed/ tests/ src/ Unit/ AnnounceFetcherUnitTest.php, line 15
Namespace
Drupal\Tests\announcements_feed\UnitView source
class AnnounceFetcherUnitTest extends UnitTestCase {
/**
* The Fetcher service object.
*
* @var \Drupal\announcements_feed\AnnounceFetcher
*/
protected AnnounceFetcher $fetcher;
/**
* {@inheritdoc}
*/
public function setUp() : void {
parent::setUp();
$httpClient = $this->createMock('GuzzleHttp\\ClientInterface');
$config = $this->getConfigFactoryStub([
'announcements_feed.settings' => [
'max_age' => 86400,
'cron_interval' => 21600,
'limit' => 10,
],
]);
$tempStore = $this->createMock('Drupal\\Core\\KeyValueStore\\KeyValueExpirableFactoryInterface');
$tempStore->expects($this->once())
->method('get')
->willReturn($this->createMock('Drupal\\Core\\KeyValueStore\\KeyValueStoreExpirableInterface'));
$logger = $this->createMock('Psr\\Log\\LoggerInterface');
$this->fetcher = new AnnounceFetcher($httpClient, $config, $tempStore, $logger, 'https://www.drupal.org/announcements.json');
}
/**
* Test the ValidateUrl() method.
*
* @legacy-covers \Drupal\announcements_feed\AnnounceFetcher::validateUrl
*/
public function testValidateUrl($url, $isValid) : void {
$this->assertEquals($isValid, $this->fetcher
->validateUrl($url));
}
/**
* Data for the testValidateUrl.
*/
public static function urlProvider() : array {
return [
[
'https://www.drupal.org',
TRUE,
],
[
'https://drupal.org',
TRUE,
],
[
'https://api.drupal.org',
TRUE,
],
[
'https://a.drupal.org',
TRUE,
],
[
'https://123.drupal.org',
TRUE,
],
[
'https://api-new.drupal.org',
TRUE,
],
[
'https://api_new.drupal.org',
TRUE,
],
[
'https://api-.drupal.org',
TRUE,
],
[
'https://www.example.org',
FALSE,
],
[
'https://example.org',
FALSE,
],
[
'https://api.example.org/project/announce',
FALSE,
],
[
'https://-api.drupal.org',
FALSE,
],
[
'https://a.example.org/project/announce',
FALSE,
],
[
'https://test.drupaal.com',
FALSE,
],
[
'https://api.drupal.org.example.com',
FALSE,
],
[
'https://example.org/drupal.org',
FALSE,
],
];
}
}
Members
| Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title |
|---|---|---|---|---|---|
| AnnounceFetcherUnitTest::$fetcher | protected | property | The Fetcher service object. | ||
| AnnounceFetcherUnitTest::setUp | public | function | Overrides UnitTestCase::setUp | ||
| AnnounceFetcherUnitTest::testValidateUrl | public | function | Test the ValidateUrl() method. | ||
| AnnounceFetcherUnitTest::urlProvider | public static | function | Data for the testValidateUrl. | ||
| DrupalTestCaseTrait::checkErrorHandlerOnTearDown | public | function | Checks the test error handler after test execution. | ||
| ExpectDeprecationTrait::expectDeprecation | Deprecated | public | function | Adds an expected deprecation. | |
| ExpectDeprecationTrait::regularExpressionForFormatDescription | private | function | |||
| 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. | ||
| 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. | ||
| UnitTestCase::$root | protected | property | The app root. | ||
| UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | ||
| UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | ||
| UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | ||
| UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | ||
| UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | ||
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.