class AnnounceFetcherUnitTest
Same name in other branches
- 11.x core/modules/announcements_feed/tests/src/Unit/AnnounceFetcherUnitTest.php \Drupal\Tests\announcements_feed\Unit\AnnounceFetcherUnitTest
Simple test to ensure that asserts pass.
@group announcements_feed
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- 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.
*
* @covers \Drupal\announcements_feed\AnnounceFetcher::validateUrl
*
* @dataProvider urlProvider
*/
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 | Overrides |
---|---|---|---|---|---|---|
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. | |||
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::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. | |||
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | ||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
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::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |||
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::setUpBeforeClass | public static | function | ||||
UnitTestCase::__get | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.