Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -0,0 +1,61 @@
<?php
namespace Drupal\Tests\Component\Annotation\Plugin\Discovery;
use Drupal\Component\Annotation\Plugin;
use Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator;
use Drupal\Component\Plugin\Definition\PluginDefinition;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator
* @group Plugin
*/
class AnnotationBridgeDecoratorTest extends UnitTestCase {
/**
* @covers ::getDefinitions
*/
public function testGetDefinitions() {
$definitions = [];
$definitions['object'] = new ObjectDefinition(['id' => 'foo']);
$definitions['array'] = ['id' => 'bar'];
$discovery = $this->prophesize(DiscoveryInterface::class);
$discovery->getDefinitions()->willReturn($definitions);
$decorator = new AnnotationBridgeDecorator($discovery->reveal(), TestAnnotation::class);
$expected = [
'object' => new ObjectDefinition(['id' => 'foo']),
'array' => new ObjectDefinition(['id' => 'bar']),
];
$this->assertEquals($expected, $decorator->getDefinitions());
}
}
class TestAnnotation extends Plugin {
/**
* {@inheritdoc}
*/
public function get() {
return new ObjectDefinition($this->definition);
}
}
class ObjectDefinition extends PluginDefinition {
/**
* ObjectDefinition constructor.
*
* @param array $definition
*/
public function __construct(array $definition) {
foreach ($definition as $property => $value) {
$this->{$property} = $value;
}
}
}

View file

@ -80,41 +80,41 @@ class ZfExtensionManagerSfContainerTest extends UnitTestCase {
* array('-' => '', '_' => '', ' ' => '', '\\' => '', '/' => '')
*/
public function canonicalizeNameProvider() {
return array(
array(
return [
[
'foobar',
'foobar',
),
array(
],
[
'foo-bar',
'foobar',
),
array(
],
[
'foo_bar',
'foobar',
),
array(
],
[
'foo bar',
'foobar',
),
array(
],
[
'foo\\bar',
'foobar',
),
array(
],
[
'foo/bar',
'foobar',
),
],
// There is also a strtolower in canonicalizeName.
array(
[
'Foo/bAr',
'foobar',
),
array(
],
[
'foo/-_\\ bar',
'foobar',
),
);
],
];
}
}

View file

@ -98,11 +98,13 @@ class DateTimePlusTest extends UnitTestCase {
* Input argument for DateTimePlus.
* @param string $timezone
* Timezone argument for DateTimePlus.
* @param string $class
* The Exception subclass to expect to be thrown.
*
* @dataProvider providerTestInvalidDateArrays
* @expectedException \Exception
*/
public function testInvalidDateArrays($input, $timezone) {
public function testInvalidDateArrays($input, $timezone, $class) {
$this->setExpectedException($class);
$this->assertInstanceOf(
'\Drupal\Component\DateTimePlus',
DateTimePlus::createFromArray($input, $timezone)
@ -234,11 +236,13 @@ class DateTimePlusTest extends UnitTestCase {
* Format argument for DateTimePlus.
* @param string $message
* Message to print if no errors are thrown by the invalid dates.
* @param string $class
* The Exception subclass to expect to be thrown.
*
* @dataProvider providerTestInvalidDates
* @expectedException \Exception
*/
public function testInvalidDates($input, $timezone, $format, $message) {
public function testInvalidDates($input, $timezone, $format, $message, $class) {
$this->setExpectedException($class);
DateTimePlus::createFromFormat($format, $input, $timezone);
}
@ -289,21 +293,21 @@ class DateTimePlusTest extends UnitTestCase {
* @see DateTimePlusTest::testDates()
*/
public function providerTestDates() {
return array(
return [
// String input.
// Create date object from datetime string.
array('2009-03-07 10:30', 'America/Chicago', '2009-03-07T10:30:00-06:00'),
['2009-03-07 10:30', 'America/Chicago', '2009-03-07T10:30:00-06:00'],
// Same during daylight savings time.
array('2009-06-07 10:30', 'America/Chicago', '2009-06-07T10:30:00-05:00'),
['2009-06-07 10:30', 'America/Chicago', '2009-06-07T10:30:00-05:00'],
// Create date object from date string.
array('2009-03-07', 'America/Chicago', '2009-03-07T00:00:00-06:00'),
['2009-03-07', 'America/Chicago', '2009-03-07T00:00:00-06:00'],
// Same during daylight savings time.
array('2009-06-07', 'America/Chicago', '2009-06-07T00:00:00-05:00'),
['2009-06-07', 'America/Chicago', '2009-06-07T00:00:00-05:00'],
// Create date object from date string.
array('2009-03-07 10:30', 'Australia/Canberra', '2009-03-07T10:30:00+11:00'),
['2009-03-07 10:30', 'Australia/Canberra', '2009-03-07T10:30:00+11:00'],
// Same during daylight savings time.
array('2009-06-07 10:30', 'Australia/Canberra', '2009-06-07T10:30:00+10:00'),
);
['2009-06-07 10:30', 'Australia/Canberra', '2009-06-07T10:30:00+10:00'],
];
}
/**
@ -316,17 +320,17 @@ class DateTimePlusTest extends UnitTestCase {
* @see DateTimePlusTest::testDates()
*/
public function providerTestDateArrays() {
return array(
return [
// Array input.
// Create date object from date array, date only.
array(array('year' => 2010, 'month' => 2, 'day' => 28), 'America/Chicago', '2010-02-28T00:00:00-06:00'),
[['year' => 2010, 'month' => 2, 'day' => 28], 'America/Chicago', '2010-02-28T00:00:00-06:00'],
// Create date object from date array with hour.
array(array('year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 10), 'America/Chicago', '2010-02-28T10:00:00-06:00'),
[['year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 10], 'America/Chicago', '2010-02-28T10:00:00-06:00'],
// Create date object from date array, date only.
array(array('year' => 2010, 'month' => 2, 'day' => 28), 'Europe/Berlin', '2010-02-28T00:00:00+01:00'),
[['year' => 2010, 'month' => 2, 'day' => 28], 'Europe/Berlin', '2010-02-28T00:00:00+01:00'],
// Create date object from date array with hour.
array(array('year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 10), 'Europe/Berlin', '2010-02-28T10:00:00+01:00'),
);
[['year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 10], 'Europe/Berlin', '2010-02-28T10:00:00+01:00'],
];
}
/**
@ -343,16 +347,16 @@ class DateTimePlusTest extends UnitTestCase {
* @see testDateFormats()
*/
public function providerTestDateFormat() {
return array(
return [
// Create a year-only date.
array('2009', NULL, 'Y', 'Y', '2009'),
['2009', NULL, 'Y', 'Y', '2009'],
// Create a month and year-only date.
array('2009-10', NULL, 'Y-m', 'Y-m', '2009-10'),
['2009-10', NULL, 'Y-m', 'Y-m', '2009-10'],
// Create a time-only date.
array('T10:30:00', NULL, '\TH:i:s', 'H:i:s', '10:30:00'),
['T10:30:00', NULL, '\TH:i:s', 'H:i:s', '10:30:00'],
// Create a time-only date.
array('10:30:00', NULL, 'H:i:s', 'H:i:s', '10:30:00'),
);
['10:30:00', NULL, 'H:i:s', 'H:i:s', '10:30:00'],
];
}
/**
@ -368,20 +372,20 @@ class DateTimePlusTest extends UnitTestCase {
* @see testInvalidDates
*/
public function providerTestInvalidDates() {
return array(
return [
// Test for invalid month names when we are using a short version
// of the month.
array('23 abc 2012', NULL, 'd M Y', "23 abc 2012 contains an invalid month name and did not produce errors."),
['23 abc 2012', NULL, 'd M Y', "23 abc 2012 contains an invalid month name and did not produce errors.", \InvalidArgumentException::class],
// Test for invalid hour.
array('0000-00-00T45:30:00', NULL, 'Y-m-d\TH:i:s', "0000-00-00T45:30:00 contains an invalid hour and did not produce errors."),
['0000-00-00T45:30:00', NULL, 'Y-m-d\TH:i:s', "0000-00-00T45:30:00 contains an invalid hour and did not produce errors.", \UnexpectedValueException::class],
// Test for invalid day.
array('0000-00-99T05:30:00', NULL, 'Y-m-d\TH:i:s', "0000-00-99T05:30:00 contains an invalid day and did not produce errors."),
['0000-00-99T05:30:00', NULL, 'Y-m-d\TH:i:s', "0000-00-99T05:30:00 contains an invalid day and did not produce errors.", \UnexpectedValueException::class],
// Test for invalid month.
array('0000-75-00T15:30:00', NULL, 'Y-m-d\TH:i:s', "0000-75-00T15:30:00 contains an invalid month and did not produce errors."),
['0000-75-00T15:30:00', NULL, 'Y-m-d\TH:i:s', "0000-75-00T15:30:00 contains an invalid month and did not produce errors.", \UnexpectedValueException::class],
// Test for invalid year.
array('11-08-01T15:30:00', NULL, 'Y-m-d\TH:i:s', "11-08-01T15:30:00 contains an invalid year and did not produce errors."),
['11-08-01T15:30:00', NULL, 'Y-m-d\TH:i:s', "11-08-01T15:30:00 contains an invalid year and did not produce errors.", \UnexpectedValueException::class],
);
];
}
/**
@ -395,20 +399,20 @@ class DateTimePlusTest extends UnitTestCase {
* @see testInvalidDateArrays
*/
public function providerTestInvalidDateArrays() {
return array(
return [
// One year larger than the documented upper limit of checkdate().
array(array('year' => 32768, 'month' => 1, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0), 'America/Chicago'),
[['year' => 32768, 'month' => 1, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0], 'America/Chicago', \InvalidArgumentException::class],
// One year smaller than the documented lower limit of checkdate().
array(array('year' => 0, 'month' => 1, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0), 'America/Chicago'),
[['year' => 0, 'month' => 1, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0], 'America/Chicago', \InvalidArgumentException::class],
// Test for invalid month from date array.
array(array('year' => 2010, 'month' => 27, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0), 'America/Chicago'),
[['year' => 2010, 'month' => 27, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0], 'America/Chicago', \InvalidArgumentException::class],
// Test for invalid hour from date array.
array(array('year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 80, 'minute' => 0, 'second' => 0), 'America/Chicago'),
[['year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 80, 'minute' => 0, 'second' => 0], 'America/Chicago', \InvalidArgumentException::class],
// Test for invalid minute from date array.
array(array('year' => 2010, 'month' => 7, 'day' => 8, 'hour' => 8, 'minute' => 88, 'second' => 0), 'America/Chicago'),
[['year' => 2010, 'month' => 7, 'day' => 8, 'hour' => 8, 'minute' => 88, 'second' => 0], 'America/Chicago', \InvalidArgumentException::class],
// Regression test for https://www.drupal.org/node/2084455.
array(array('hour' => 59, 'minute' => 1, 'second' => 1), 'America/Chicago'),
);
[['hour' => 59, 'minute' => 1, 'second' => 1], 'America/Chicago', \InvalidArgumentException::class],
];
}
/**
@ -430,17 +434,17 @@ class DateTimePlusTest extends UnitTestCase {
// Detect the system timezone.
$system_timezone = date_default_timezone_get();
return array(
return [
// Create a date object with an unspecified timezone, which should
// end up using the system timezone.
array($date_string, NULL, $system_timezone, 'DateTimePlus uses the system timezone when there is no site timezone.'),
[$date_string, NULL, $system_timezone, 'DateTimePlus uses the system timezone when there is no site timezone.'],
// Create a date object with a specified timezone name.
array($date_string, 'America/Yellowknife', 'America/Yellowknife', 'DateTimePlus uses the specified timezone if provided.'),
[$date_string, 'America/Yellowknife', 'America/Yellowknife', 'DateTimePlus uses the specified timezone if provided.'],
// Create a date object with a timezone object.
array($date_string, new \DateTimeZone('Australia/Canberra'), 'Australia/Canberra', 'DateTimePlus uses the specified timezone if provided.'),
[$date_string, new \DateTimeZone('Australia/Canberra'), 'Australia/Canberra', 'DateTimePlus uses the specified timezone if provided.'],
// Create a date object with another date object.
array(new DateTimePlus('now', 'Pacific/Midway'), NULL, 'Pacific/Midway', 'DateTimePlus uses the specified timezone if provided.'),
);
[new DateTimePlus('now', 'Pacific/Midway'), NULL, 'Pacific/Midway', 'DateTimePlus uses the specified timezone if provided.'],
];
}
/**
@ -453,46 +457,46 @@ class DateTimePlusTest extends UnitTestCase {
* @see testTimestamp()
*/
public function providerTestTimestamp() {
return array(
return [
// Create date object from a unix timestamp and display it in
// local time.
array(
[
'input' => 0,
'initial' => array(
'initial' => [
'timezone' => 'UTC',
'format' => 'c',
'expected_date' => '1970-01-01T00:00:00+00:00',
'expected_timezone' => 'UTC',
'expected_offset' => 0,
),
'transform' => array(
],
'transform' => [
'timezone' => 'America/Los_Angeles',
'format' => 'c',
'expected_date' => '1969-12-31T16:00:00-08:00',
'expected_timezone' => 'America/Los_Angeles',
'expected_offset' => '-28800',
),
),
],
],
// Create a date using the timestamp of zero, then display its
// value both in UTC and the local timezone.
array(
[
'input' => 0,
'initial' => array(
'initial' => [
'timezone' => 'America/Los_Angeles',
'format' => 'c',
'expected_date' => '1969-12-31T16:00:00-08:00',
'expected_timezone' => 'America/Los_Angeles',
'expected_offset' => '-28800',
),
'transform' => array(
],
'transform' => [
'timezone' => 'UTC',
'format' => 'c',
'expected_date' => '1970-01-01T00:00:00+00:00',
'expected_timezone' => 'UTC',
'expected_offset' => 0,
),
),
);
],
],
];
}
/**
@ -505,63 +509,63 @@ class DateTimePlusTest extends UnitTestCase {
* @see testDateTimestamp()
*/
public function providerTestDateTimestamp() {
return array(
return [
// Create date object from datetime string in UTC, and convert
// it to a local date.
array(
[
'input' => '1970-01-01 00:00:00',
'initial' => array(
'initial' => [
'timezone' => 'UTC',
'format' => 'c',
'expected_date' => '1970-01-01T00:00:00+00:00',
'expected_timezone' => 'UTC',
'expected_offset' => 0,
),
'transform' => array(
],
'transform' => [
'timezone' => 'America/Los_Angeles',
'format' => 'c',
'expected_date' => '1969-12-31T16:00:00-08:00',
'expected_timezone' => 'America/Los_Angeles',
'expected_offset' => '-28800',
),
),
],
],
// Convert the local time to UTC using string input.
array(
[
'input' => '1969-12-31 16:00:00',
'initial' => array(
'initial' => [
'timezone' => 'America/Los_Angeles',
'format' => 'c',
'expected_date' => '1969-12-31T16:00:00-08:00',
'expected_timezone' => 'America/Los_Angeles',
'expected_offset' => '-28800',
),
'transform' => array(
],
'transform' => [
'timezone' => 'UTC',
'format' => 'c',
'expected_date' => '1970-01-01T00:00:00+00:00',
'expected_timezone' => 'UTC',
'expected_offset' => 0,
),
),
],
],
// Convert the local time to UTC using string input.
array(
[
'input' => '1969-12-31 16:00:00',
'initial' => array(
'initial' => [
'timezone' => 'Europe/Warsaw',
'format' => 'c',
'expected_date' => '1969-12-31T16:00:00+01:00',
'expected_timezone' => 'Europe/Warsaw',
'expected_offset' => '+3600',
),
'transform' => array(
],
'transform' => [
'timezone' => 'UTC',
'format' => 'c',
'expected_date' => '1969-12-31T15:00:00+00:00',
'expected_timezone' => 'UTC',
'expected_offset' => 0,
),
),
);
],
],
];
}
/**
@ -586,60 +590,60 @@ class DateTimePlusTest extends UnitTestCase {
$negative_1_hour = new \DateInterval('PT1H');
$negative_1_hour->invert = 1;
return array(
return [
// There should be a 19 hour time interval between
// new years in Sydney and new years in LA in year 2000.
array(
[
'input2' => DateTimePlus::createFromFormat('Y-m-d H:i:s', '2000-01-01 00:00:00', new \DateTimeZone('Australia/Sydney')),
'input1' => DateTimePlus::createFromFormat('Y-m-d H:i:s', '2000-01-01 00:00:00', new \DateTimeZone('America/Los_Angeles')),
'absolute' => FALSE,
'expected' => $positive_19_hours,
),
],
// In 1970 Sydney did not observe daylight savings time
// So there is only a 18 hour time interval.
array(
[
'input2' => DateTimePlus::createFromFormat('Y-m-d H:i:s', '1970-01-01 00:00:00', new \DateTimeZone('Australia/Sydney')),
'input1' => DateTimePlus::createFromFormat('Y-m-d H:i:s', '1970-01-01 00:00:00', new \DateTimeZone('America/Los_Angeles')),
'absolute' => FALSE,
'expected' => $positive_18_hours,
),
array(
],
[
'input1' => DateTimePlus::createFromFormat('U', 3600, new \DateTimeZone('America/Los_Angeles')),
'input2' => DateTimePlus::createFromFormat('U', 0, new \DateTimeZone('UTC')),
'absolute' => FALSE,
'expected' => $negative_1_hour,
),
array(
],
[
'input1' => DateTimePlus::createFromFormat('U', 3600),
'input2' => DateTimePlus::createFromFormat('U', 0),
'absolute' => FALSE,
'expected' => $negative_1_hour,
),
array(
],
[
'input1' => DateTimePlus::createFromFormat('U', 3600),
'input2' => \DateTime::createFromFormat('U', 0),
'absolute' => FALSE,
'expected' => $negative_1_hour,
),
array(
],
[
'input1' => DateTimePlus::createFromFormat('U', 3600),
'input2' => DateTimePlus::createFromFormat('U', 0),
'absolute' => TRUE,
'expected' => $positive_1_hour,
),
array(
],
[
'input1' => DateTimePlus::createFromFormat('U', 3600),
'input2' => \DateTime::createFromFormat('U', 0),
'absolute' => TRUE,
'expected' => $positive_1_hour,
),
array(
],
[
'input1' => DateTimePlus::createFromFormat('U', 0),
'input2' => DateTimePlus::createFromFormat('U', 0),
'absolute' => FALSE,
'expected' => $empty_interval,
),
);
],
];
}
/**
@ -652,18 +656,126 @@ class DateTimePlusTest extends UnitTestCase {
* @see DateTimePlusTest::testInvalidDateDiff()
*/
public function providerTestInvalidDateDiff() {
return array(
array(
return [
[
'input1' => DateTimePlus::createFromFormat('U', 3600),
'input2' => '1970-01-01 00:00:00',
'absolute' => FALSE,
),
array(
],
[
'input1' => DateTimePlus::createFromFormat('U', 3600),
'input2' => NULL,
'absolute' => FALSE,
),
);
],
];
}
/**
* Tests invalid values passed to constructor.
*
* @param string $time
* A date/time string.
* @param string[] $errors
* An array of error messages.
*
* @covers ::__construct
*
* @dataProvider providerTestInvalidConstructor
*/
public function testInvalidConstructor($time, array $errors) {
$date = new DateTimePlus($time);
$this->assertEquals(TRUE, $date->hasErrors());
$this->assertEquals($errors, $date->getErrors());
}
/**
* Provider for testInvalidConstructor().
*
* @return array
* An array of invalid date/time strings, and corresponding error messages.
*/
public function providerTestInvalidConstructor() {
return [
[
'YYYY-MM-DD',
[
'The timezone could not be found in the database',
'Unexpected character',
'Double timezone specification',
],
],
[
'2017-MM-DD',
[
'Unexpected character',
'The timezone could not be found in the database',
],
],
[
'YYYY-03-DD',
[
'The timezone could not be found in the database',
'Unexpected character',
'Double timezone specification',
],
],
[
'YYYY-MM-07',
[
'The timezone could not be found in the database',
'Unexpected character',
'Double timezone specification',
],
],
[
'2017-13-55',
[
'Unexpected character',
],
],
[
'YYYY-MM-DD hh:mm:ss',
[
'The timezone could not be found in the database',
'Unexpected character',
'Double timezone specification',
],
],
[
'2017-03-07 25:70:80',
[
'Unexpected character',
'Double time specification',
],
],
[
'lorem ipsum dolor sit amet',
[
'The timezone could not be found in the database',
'Double timezone specification',
],
],
];
}
/**
* Tests the $settings['validate_format'] parameter in ::createFromFormat().
*/
public function testValidateFormat() {
// Check that an input that does not strictly follow the input format will
// produce the desired date. In this case the year string '11' doesn't
// precisely match the 'Y' formater parameter, but PHP will parse it
// regardless. However, when formatted with the same string, the year will
// be output with four digits. With the ['validate_format' => FALSE]
// $settings, this will not thrown an exception.
$date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '11-03-31 17:44:00', 'UTC', ['validate_format' => FALSE]);
$this->assertEquals('0011-03-31 17:44:00', $date->format('Y-m-d H:i:s'));
// Parse the same date with ['validate_format' => TRUE] and make sure we
// get the expected exception.
$this->setExpectedException(\UnexpectedValueException::class);
$date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '11-03-31 17:44:00', 'UTC', ['validate_format' => TRUE]);
}
}

View file

@ -0,0 +1,123 @@
<?php
namespace Drupal\Tests\Component\Datetime;
use Drupal\Component\Datetime\Time;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
/**
* @coversDefaultClass \Drupal\Component\Datetime\Time
* @group Datetime
*
* Isolate the tests to prevent side effects from altering system time.
*
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class TimeTest extends UnitTestCase {
/**
* The mocked request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack|\PHPUnit_Framework_MockObject_MockObject
*/
protected $requestStack;
/**
* The mocked time class.
*
* @var \Drupal\Component\Datetime\Time
*/
protected $time;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack');
$this->time = new Time($this->requestStack);
}
/**
* Tests the getRequestTime method.
*
* @covers ::getRequestTime
*/
public function testGetRequestTime() {
$expected = 12345678;
$request = Request::createFromGlobals();
$request->server->set('REQUEST_TIME', $expected);
// Mocks a the request stack getting the current request.
$this->requestStack->expects($this->any())
->method('getCurrentRequest')
->willReturn($request);
$this->assertEquals($expected, $this->time->getRequestTime());
}
/**
* Tests the getRequestMicroTime method.
*
* @covers ::getRequestMicroTime
*/
public function testGetRequestMicroTime() {
$expected = 1234567.89;
$request = Request::createFromGlobals();
$request->server->set('REQUEST_TIME_FLOAT', $expected);
// Mocks a the request stack getting the current request.
$this->requestStack->expects($this->any())
->method('getCurrentRequest')
->willReturn($request);
$this->assertEquals($expected, $this->time->getRequestMicroTime());
}
/**
* Tests the getCurrentTime method.
*
* @covers ::getCurrentTime
*/
public function testGetCurrentTime() {
$expected = 12345678;
$this->assertEquals($expected, $this->time->getCurrentTime());
}
/**
* Tests the getCurrentMicroTime method.
*
* @covers ::getCurrentMicroTime
*/
public function testGetCurrentMicroTime() {
$expected = 1234567.89;
$this->assertEquals($expected, $this->time->getCurrentMicroTime());
}
}
namespace Drupal\Component\Datetime;
/**
* Shadow time() system call.
*
* @returns int
*/
function time() {
return 12345678;
}
/**
* Shadow microtime system call.
*
* @returns float
*/
function microtime() {
return 1234567.89;
}

View file

@ -7,8 +7,14 @@
namespace Drupal\Tests\Component\DependencyInjection;
use Drupal\Component\Utility\Crypt;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Prophecy\Argument;
/**
@ -59,12 +65,11 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* Tests that passing a non-supported format throws an InvalidArgumentException.
*
* @covers ::__construct
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
public function testConstruct() {
$container_definition = $this->getMockContainerDefinition();
$container_definition['machine_format'] = !$this->machineFormat;
$this->setExpectedException(InvalidArgumentException::class);
$container = new $this->containerClass($container_definition);
}
@ -85,10 +90,9 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* @covers ::getParameter
* @covers ::getParameterAlternatives
* @covers ::getAlternatives
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException
*/
public function testGetParameterIfNotFound() {
$this->setExpectedException(ParameterNotFoundException::class);
$this->container->getParameter('parameter_that_does_not_exist');
}
@ -96,10 +100,9 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* Tests that Container::getParameter() works properly for NULL parameters.
*
* @covers ::getParameter
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException
*/
public function testGetParameterIfNotFoundBecauseNull() {
$this->setExpectedException(ParameterNotFoundException::class);
$this->container->getParameter(NULL);
}
@ -130,11 +133,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* Tests that Container::setParameter() in a frozen case works properly.
*
* @covers ::setParameter
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
*/
public function testSetParameterWithFrozenContainer() {
$this->container = new $this->containerClass($this->containerDefinition);
$this->setExpectedException(LogicException::class);
$this->container->setParameter('some_config', 'new_value');
}
@ -235,11 +237,11 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
/**
* Tests that Container::get() for circular dependencies works properly.
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
* @covers ::get
* @covers ::createService
*/
public function testGetForCircularServices() {
$this->setExpectedException(ServiceCircularReferenceException::class);
$this->container->get('circular_dependency');
}
@ -250,10 +252,9 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* @covers ::createService
* @covers ::getAlternatives
* @covers ::getServiceAlternatives
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
*/
public function testGetForNonExistantService() {
$this->setExpectedException(ServiceNotFoundException::class);
$this->container->get('service_not_exists');
}
@ -295,8 +296,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* @covers ::get
* @covers ::createService
* @covers ::resolveServicesAndParameters
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
public function testGetForParameterDependencyWithExceptionOnSecondCall() {
$service = $this->container->get('service_parameter_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE);
@ -304,6 +303,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
// Reset the service.
$this->container->set('service_parameter_not_exists', NULL);
$this->setExpectedException(InvalidArgumentException::class);
$this->container->get('service_parameter_not_exists');
}
@ -313,10 +313,9 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* @covers ::get
* @covers ::createService
* @covers ::resolveServicesAndParameters
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
public function testGetForNonExistantParameterDependencyWithException() {
$this->setExpectedException(InvalidArgumentException::class);
$this->container->get('service_parameter_not_exists');
}
@ -339,10 +338,9 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* @covers ::createService
* @covers ::resolveServicesAndParameters
* @covers ::getAlternatives
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
*/
public function testGetForNonExistantServiceDependencyWithException() {
$this->setExpectedException(ServiceNotFoundException::class);
$this->container->get('service_dependency_not_exists');
}
@ -360,10 +358,9 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* Tests that Container::get() for NULL service works properly.
* @covers ::get
* @covers ::createService
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
*/
public function testGetForNonExistantNULLService() {
$this->setExpectedException(ServiceNotFoundException::class);
$this->container->get(NULL);
}
@ -386,11 +383,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* @covers ::get
* @covers ::createService
* @covers ::getAlternatives
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
*/
public function testGetForNonExistantServiceWithExceptionOnSecondCall() {
$this->assertNull($this->container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'Not found service does nto throw exception.');
$this->setExpectedException(ServiceNotFoundException::class);
$this->container->get('service_not_exists');
}
@ -424,10 +420,9 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
*
* @covers ::get
* @covers ::createService
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
*/
public function testGetForSyntheticServiceWithException() {
$this->setExpectedException(RuntimeException::class);
$this->container->get('synthetic');
}
@ -451,7 +446,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* @covers ::resolveServicesAndParameters
*/
public function testGetForInstantiationWithVariousArgumentLengths() {
$args = array();
$args = [];
for ($i = 0; $i < 12; $i++) {
$instantiation_service = $this->container->get('service_test_instantiation_' . $i);
$this->assertEquals($args, $instantiation_service->getArguments());
@ -464,10 +459,9 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
*
* @covers ::get
* @covers ::createService
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
*/
public function testGetForWrongFactory() {
$this->setExpectedException(RuntimeException::class);
$this->container->get('wrong_factory');
}
@ -503,10 +497,9 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
*
* @covers ::get
* @covers ::createService
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
public function testGetForConfiguratorWithException() {
$this->setExpectedException(InvalidArgumentException::class);
$this->container->get('configurable_service_exception');
}
@ -602,10 +595,9 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* @covers ::get
* @covers ::createService
* @covers ::resolveServicesAndParameters
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
public function testResolveServicesAndParametersForInvalidArgument() {
$this->setExpectedException(InvalidArgumentException::class);
$this->container->get('invalid_argument_service');
}
@ -615,12 +607,11 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* @covers ::get
* @covers ::createService
* @covers ::resolveServicesAndParameters
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
public function testResolveServicesAndParametersForInvalidArguments() {
// In case the machine-optimized format is not used, we need to simulate the
// test failure.
$this->setExpectedException(InvalidArgumentException::class);
if (!$this->machineFormat) {
throw new InvalidArgumentException('Simulating the test failure.');
}
@ -671,16 +662,15 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
* @covers ::hasScope
* @covers ::isScopeActive
*
* @expectedException \BadMethodCallException
*
* @dataProvider scopeExceptionTestProvider
*/
public function testScopeFunctionsWithException($method, $argument) {
$callable = array(
$callable = [
$this->container,
$method,
);
];
$this->setExpectedException(\BadMethodCallException::class);
$callable($argument);
}
@ -694,13 +684,13 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
*/
public function scopeExceptionTestProvider() {
$scope = $this->prophesize('\Symfony\Component\DependencyInjection\ScopeInterface')->reveal();
return array(
array('enterScope', 'test_scope'),
array('leaveScope', 'test_scope'),
array('hasScope', 'test_scope'),
array('isScopeActive', 'test_scope'),
array('addScope', $scope),
);
return [
['enterScope', 'test_scope'],
['leaveScope', 'test_scope'],
['hasScope', 'test_scope'],
['isScopeActive', 'test_scope'],
['addScope', $scope],
];
}
/**
@ -728,7 +718,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
*/
protected function getMockContainerDefinition() {
$fake_service = new \stdClass();
$parameters = array();
$parameters = [];
$parameters['some_parameter_class'] = get_class($fake_service);
$parameters['some_private_config'] = 'really_private_lama';
$parameters['some_config'] = 'foo';
@ -737,262 +727,262 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
// Also test alias resolving.
$parameters['service_from_parameter'] = $this->getServiceCall('service.provider_alias');
$services = array();
$services['service_container'] = array(
$services = [];
$services['service_container'] = [
'class' => '\Drupal\service_container\DependencyInjection\Container',
);
$services['other.service'] = array(
];
$services['other.service'] = [
'class' => get_class($fake_service),
);
];
$services['non_shared_service'] = array(
$services['non_shared_service'] = [
'class' => get_class($fake_service),
'shared' => FALSE,
);
];
$services['other.service_class_from_parameter'] = array(
$services['other.service_class_from_parameter'] = [
'class' => $this->getParameterCall('some_parameter_class'),
);
$services['late.service'] = array(
];
$services['late.service'] = [
'class' => get_class($fake_service),
);
$services['service.provider'] = array(
];
$services['service.provider'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection(array(
'arguments' => $this->getCollection([
$this->getServiceCall('other.service'),
$this->getParameterCall('some_config'),
)),
'properties' => $this->getCollection(array('_someProperty' => 'foo')),
'calls' => array(
array('setContainer', $this->getCollection(array(
]),
'properties' => $this->getCollection(['_someProperty' => 'foo']),
'calls' => [
['setContainer', $this->getCollection([
$this->getServiceCall('service_container'),
))),
array('setOtherConfigParameter', $this->getCollection(array(
])],
['setOtherConfigParameter', $this->getCollection([
$this->getParameterCall('some_other_config'),
))),
),
])],
],
'priority' => 0,
);
];
// Test private services.
$private_service = array(
$private_service = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection(array(
'arguments' => $this->getCollection([
$this->getServiceCall('other.service'),
$this->getParameterCall('some_private_config'),
)),
]),
'public' => FALSE,
);
];
$services['service_using_private'] = array(
$services['service_using_private'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection(array(
'arguments' => $this->getCollection([
$this->getPrivateServiceCall(NULL, $private_service),
$this->getParameterCall('some_config'),
)),
);
$services['another_service_using_private'] = array(
]),
];
$services['another_service_using_private'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection(array(
'arguments' => $this->getCollection([
$this->getPrivateServiceCall(NULL, $private_service),
$this->getParameterCall('some_config'),
)),
);
]),
];
// Test shared private services.
$id = 'private_service_shared_1';
$services['service_using_shared_private'] = array(
$services['service_using_shared_private'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection(array(
'arguments' => $this->getCollection([
$this->getPrivateServiceCall($id, $private_service, TRUE),
$this->getParameterCall('some_config'),
)),
);
$services['another_service_using_shared_private'] = array(
]),
];
$services['another_service_using_shared_private'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection(array(
'arguments' => $this->getCollection([
$this->getPrivateServiceCall($id, $private_service, TRUE),
$this->getParameterCall('some_config'),
)),
);
]),
];
// Tests service with invalid argument.
$services['invalid_argument_service'] = array(
$services['invalid_argument_service'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection(array(
'arguments' => $this->getCollection([
1, // Test passing non-strings, too.
(object) array(
(object) [
'type' => 'invalid',
),
)),
);
],
]),
];
$services['invalid_arguments_service'] = array(
$services['invalid_arguments_service'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => (object) array(
'arguments' => (object) [
'type' => 'invalid',
),
);
],
];
// Test service that needs deep-traversal.
$services['service_using_array'] = array(
$services['service_using_array'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection(array(
$this->getCollection(array(
'arguments' => $this->getCollection([
$this->getCollection([
$this->getServiceCall('other.service'),
)),
]),
$this->getParameterCall('some_private_config'),
)),
);
]),
];
$services['service_with_optional_dependency'] = array(
$services['service_with_optional_dependency'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection(array(
'arguments' => $this->getCollection([
$this->getServiceCall('service.does_not_exist', ContainerInterface::NULL_ON_INVALID_REFERENCE),
$this->getParameterCall('some_private_config'),
)),
]),
);
];
$services['factory_service'] = array(
$services['factory_service'] = [
'class' => '\Drupal\service_container\ServiceContainer\ControllerInterface',
'factory' => array(
'factory' => [
$this->getServiceCall('service.provider'),
'getFactoryMethod',
),
'arguments' => $this->getCollection(array(
],
'arguments' => $this->getCollection([
$this->getParameterCall('factory_service_class'),
)),
);
$services['factory_class'] = array(
]),
];
$services['factory_class'] = [
'class' => '\Drupal\service_container\ServiceContainer\ControllerInterface',
'factory' => '\Drupal\Tests\Component\DependencyInjection\MockService::getFactoryMethod',
'arguments' => array(
'arguments' => [
'\Drupal\Tests\Component\DependencyInjection\MockService',
array(NULL, 'bar'),
),
'calls' => array(
array('setContainer', $this->getCollection(array(
[NULL, 'bar'],
],
'calls' => [
['setContainer', $this->getCollection([
$this->getServiceCall('service_container'),
))),
),
);
])],
],
];
$services['wrong_factory'] = array(
$services['wrong_factory'] = [
'class' => '\Drupal\service_container\ServiceContainer\ControllerInterface',
'factory' => (object) array('I am not a factory, but I pretend to be.'),
);
'factory' => (object) ['I am not a factory, but I pretend to be.'],
];
$services['circular_dependency'] = array(
$services['circular_dependency'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection(array(
'arguments' => $this->getCollection([
$this->getServiceCall('circular_dependency'),
)),
);
$services['synthetic'] = array(
]),
];
$services['synthetic'] = [
'synthetic' => TRUE,
);
];
// The file could have been named as a .php file. The reason it is a .data
// file is that SimpleTest tries to load it. SimpleTest does not like such
// fixtures and hence we use a neutral name like .data.
$services['container_test_file_service_test'] = array(
$services['container_test_file_service_test'] = [
'class' => '\stdClass',
'file' => __DIR__ . '/Fixture/container_test_file_service_test_service_function.data',
);
];
// Test multiple arguments.
$args = array();
$args = [];
for ($i = 0; $i < 12; $i++) {
$services['service_test_instantiation_' . $i] = array(
$services['service_test_instantiation_' . $i] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockInstantiationService',
// Also test a collection that does not need resolving.
'arguments' => $this->getCollection($args, FALSE),
);
];
$args[] = 'arg_' . $i;
}
$services['service_parameter_not_exists'] = array(
$services['service_parameter_not_exists'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection(array(
'arguments' => $this->getCollection([
$this->getServiceCall('service.provider'),
$this->getParameterCall('not_exists'),
)),
);
$services['service_dependency_not_exists'] = array(
]),
];
$services['service_dependency_not_exists'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection(array(
'arguments' => $this->getCollection([
$this->getServiceCall('service_not_exists'),
$this->getParameterCall('some_config'),
)),
);
]),
];
$services['service_with_parameter_service'] = array(
$services['service_with_parameter_service'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => $this->getCollection(array(
'arguments' => $this->getCollection([
$this->getParameterCall('service_from_parameter'),
// Also test deep collections that don't need resolving.
$this->getCollection(array(
$this->getCollection([
1,
), FALSE),
)),
);
], FALSE),
]),
];
// To ensure getAlternatives() finds something.
$services['service_not_exists_similar'] = array(
$services['service_not_exists_similar'] = [
'synthetic' => TRUE,
);
];
// Test configurator.
$services['configurator'] = array(
$services['configurator'] = [
'synthetic' => TRUE,
);
$services['configurable_service'] = array(
];
$services['configurable_service'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => array(),
'configurator' => array(
'arguments' => [],
'configurator' => [
$this->getServiceCall('configurator'),
'configureService'
),
);
$services['configurable_service_exception'] = array(
],
];
$services['configurable_service_exception'] = [
'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
'arguments' => array(),
'arguments' => [],
'configurator' => 'configurator_service_test_does_not_exist',
);
];
$aliases = array();
$aliases = [];
$aliases['service.provider_alias'] = 'service.provider';
$aliases['late.service_alias'] = 'late.service';
return array(
return [
'aliases' => $aliases,
'parameters' => $parameters,
'services' => $services,
'frozen' => TRUE,
'machine_format' => $this->machineFormat,
);
];
}
/**
* Helper function to return a service definition.
*/
protected function getServiceCall($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) {
return (object) array(
return (object) [
'type' => 'service',
'id' => $id,
'invalidBehavior' => $invalid_behavior,
);
];
}
/**
* Helper function to return a service definition.
*/
protected function getParameterCall($name) {
return (object) array(
return (object) [
'type' => 'parameter',
'name' => $name,
);
];
}
/**
@ -1000,26 +990,26 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
*/
protected function getPrivateServiceCall($id, $service_definition, $shared = FALSE) {
if (!$id) {
$hash = sha1(serialize($service_definition));
$hash = Crypt::hashBase64(serialize($service_definition));
$id = 'private__' . $hash;
}
return (object) array(
return (object) [
'type' => 'private_service',
'id' => $id,
'value' => $service_definition,
'shared' => $shared,
);
];
}
/**
* Helper function to return a machine-optimized collection.
*/
protected function getCollection($collection, $resolve = TRUE) {
return (object) array(
return (object) [
'type' => 'collection',
'value' => $collection,
'resolve' => $resolve,
);
];
}
}
@ -1188,7 +1178,7 @@ class MockService {
* @return object
* The instantiated service object.
*/
public static function getFactoryMethod($class, $arguments = array()) {
public static function getFactoryMethod($class, $arguments = []) {
$r = new \ReflectionClass($class);
$service = ($r->getConstructor() === NULL) ? $r->newInstance() : $r->newInstanceArgs($arguments);

View file

@ -7,12 +7,15 @@
namespace Drupal\Tests\Component\DependencyInjection\Dumper {
use Drupal\Component\Utility\Crypt;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
/**
* @coversDefaultClass \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper
@ -61,15 +64,15 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
protected function setUp() {
// Setup a mock container builder.
$this->containerBuilder = $this->prophesize('\Symfony\Component\DependencyInjection\ContainerBuilder');
$this->containerBuilder->getAliases()->willReturn(array());
$this->containerBuilder->getAliases()->willReturn([]);
$this->containerBuilder->getParameterBag()->willReturn(new ParameterBag());
$this->containerBuilder->getDefinitions()->willReturn(NULL);
$this->containerBuilder->isFrozen()->willReturn(TRUE);
$definition = array();
$definition['aliases'] = array();
$definition['parameters'] = array();
$definition['services'] = array();
$definition = [];
$definition['aliases'] = [];
$definition['parameters'] = [];
$definition['services'] = [];
$definition['frozen'] = TRUE;
$definition['machine_format'] = $this->machineFormat;
@ -113,17 +116,17 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
* - aliases as expected in the container definition.
*/
public function getAliasesDataProvider() {
return array(
array(array(), array()),
array(
array('foo' => 'foo.alias'),
array('foo' => 'foo.alias'),
),
array(
array('foo' => 'foo.alias', 'foo.alias' => 'foo.alias.alias'),
array('foo' => 'foo.alias.alias', 'foo.alias' => 'foo.alias.alias'),
),
);
return [
[[], []],
[
['foo' => 'foo.alias'],
['foo' => 'foo.alias'],
],
[
['foo' => 'foo.alias', 'foo.alias' => 'foo.alias.alias'],
['foo' => 'foo.alias.alias', 'foo.alias' => 'foo.alias.alias'],
],
];
}
/**
@ -163,34 +166,34 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
* - frozen value
*/
public function getParametersDataProvider() {
return array(
array(array(), array(), TRUE),
array(
array('foo' => 'value_foo'),
array('foo' => 'value_foo'),
return [
[[], [], TRUE],
[
['foo' => 'value_foo'],
['foo' => 'value_foo'],
TRUE,
),
array(
array('foo' => array('llama' => 'yes')),
array('foo' => array('llama' => 'yes')),
],
[
['foo' => ['llama' => 'yes']],
['foo' => ['llama' => 'yes']],
TRUE,
),
array(
array('foo' => '%llama%', 'llama' => 'yes'),
array('foo' => '%%llama%%', 'llama' => 'yes'),
],
[
['foo' => '%llama%', 'llama' => 'yes'],
['foo' => '%%llama%%', 'llama' => 'yes'],
TRUE,
),
array(
array('foo' => '%llama%', 'llama' => 'yes'),
array('foo' => '%llama%', 'llama' => 'yes'),
],
[
['foo' => '%llama%', 'llama' => 'yes'],
['foo' => '%llama%', 'llama' => 'yes'],
FALSE,
),
array(
array('reference' => new Reference('referenced_service')),
array('reference' => $this->getServiceCall('referenced_service')),
],
[
['reference' => new Reference('referenced_service')],
['reference' => $this->getServiceCall('referenced_service')],
TRUE,
),
);
],
];
}
/**
@ -235,164 +238,164 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
* - frozen value
*/
public function getDefinitionsDataProvider() {
$base_service_definition = array(
$base_service_definition = [
'class' => '\stdClass',
'public' => TRUE,
'file' => FALSE,
'synthetic' => FALSE,
'lazy' => FALSE,
'arguments' => array(),
'arguments' => [],
'arguments_count' => 0,
'properties' => array(),
'calls' => array(),
'properties' => [],
'calls' => [],
'scope' => ContainerInterface::SCOPE_CONTAINER,
'shared' => TRUE,
'factory' => FALSE,
'configurator' => FALSE,
);
];
// Test basic flags.
$service_definitions[] = array() + $base_service_definition;
$service_definitions[] = [] + $base_service_definition;
$service_definitions[] = array(
$service_definitions[] = [
'public' => FALSE,
) + $base_service_definition;
] + $base_service_definition;
$service_definitions[] = array(
$service_definitions[] = [
'file' => 'test_include.php',
) + $base_service_definition;
] + $base_service_definition;
$service_definitions[] = array(
$service_definitions[] = [
'synthetic' => TRUE,
) + $base_service_definition;
] + $base_service_definition;
$service_definitions[] = array(
$service_definitions[] = [
'shared' => FALSE,
) + $base_service_definition;
] + $base_service_definition;
$service_definitions[] = array(
$service_definitions[] = [
'lazy' => TRUE,
) + $base_service_definition;
] + $base_service_definition;
// Test a basic public Reference.
$service_definitions[] = array(
'arguments' => array('foo', new Reference('bar')),
$service_definitions[] = [
'arguments' => ['foo', new Reference('bar')],
'arguments_count' => 2,
'arguments_expected' => $this->getCollection(array('foo', $this->getServiceCall('bar'))),
) + $base_service_definition;
'arguments_expected' => $this->getCollection(['foo', $this->getServiceCall('bar')]),
] + $base_service_definition;
// Test a public reference that should not throw an Exception.
$reference = new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE);
$service_definitions[] = array(
'arguments' => array($reference),
$service_definitions[] = [
'arguments' => [$reference],
'arguments_count' => 1,
'arguments_expected' => $this->getCollection(array($this->getServiceCall('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE))),
) + $base_service_definition;
'arguments_expected' => $this->getCollection([$this->getServiceCall('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE)]),
] + $base_service_definition;
// Test a private shared service, denoted by having a Reference.
$private_definition = array(
$private_definition = [
'class' => '\stdClass',
'public' => FALSE,
'arguments_count' => 0,
);
];
$service_definitions[] = array(
'arguments' => array('foo', new Reference('private_definition')),
$service_definitions[] = [
'arguments' => ['foo', new Reference('private_definition')],
'arguments_count' => 2,
'arguments_expected' => $this->getCollection(array(
'arguments_expected' => $this->getCollection([
'foo',
$this->getPrivateServiceCall('private_definition', $private_definition, TRUE),
)),
) + $base_service_definition;
]),
] + $base_service_definition;
// Test a private non-shared service, denoted by having a Definition.
$private_definition_object = new Definition('\stdClass');
$private_definition_object->setPublic(FALSE);
$service_definitions[] = array(
'arguments' => array('foo', $private_definition_object),
$service_definitions[] = [
'arguments' => ['foo', $private_definition_object],
'arguments_count' => 2,
'arguments_expected' => $this->getCollection(array(
'arguments_expected' => $this->getCollection([
'foo',
$this->getPrivateServiceCall(NULL, $private_definition),
)),
) + $base_service_definition;
]),
] + $base_service_definition;
// Test a deep collection without a reference.
$service_definitions[] = array(
'arguments' => array(array(array('foo'))),
$service_definitions[] = [
'arguments' => [[['foo']]],
'arguments_count' => 1,
) + $base_service_definition;
] + $base_service_definition;
// Test a deep collection with a reference to resolve.
$service_definitions[] = array(
'arguments' => array(array(new Reference('bar'))),
$service_definitions[] = [
'arguments' => [[new Reference('bar')]],
'arguments_count' => 1,
'arguments_expected' => $this->getCollection(array($this->getCollection(array($this->getServiceCall('bar'))))),
) + $base_service_definition;
'arguments_expected' => $this->getCollection([$this->getCollection([$this->getServiceCall('bar')])]),
] + $base_service_definition;
// Test a collection with a variable to resolve.
$service_definitions[] = array(
'arguments' => array(new Parameter('llama_parameter')),
$service_definitions[] = [
'arguments' => [new Parameter('llama_parameter')],
'arguments_count' => 1,
'arguments_expected' => $this->getCollection(array($this->getParameterCall('llama_parameter'))),
) + $base_service_definition;
'arguments_expected' => $this->getCollection([$this->getParameterCall('llama_parameter')]),
] + $base_service_definition;
// Test objects that have _serviceId property.
$drupal_service = new \stdClass();
$drupal_service->_serviceId = 'bar';
$service_definitions[] = array(
'arguments' => array($drupal_service),
$service_definitions[] = [
'arguments' => [$drupal_service],
'arguments_count' => 1,
'arguments_expected' => $this->getCollection(array($this->getServiceCall('bar'))),
) + $base_service_definition;
'arguments_expected' => $this->getCollection([$this->getServiceCall('bar')]),
] + $base_service_definition;
// Test getMethodCalls.
$calls = array(
array('method', $this->getCollection(array())),
array('method2', $this->getCollection(array())),
);
$service_definitions[] = array(
$calls = [
['method', $this->getCollection([])],
['method2', $this->getCollection([])],
];
$service_definitions[] = [
'calls' => $calls,
) + $base_service_definition;
] + $base_service_definition;
$service_definitions[] = array(
$service_definitions[] = [
'scope' => ContainerInterface::SCOPE_PROTOTYPE,
'shared' => FALSE,
) + $base_service_definition;
] + $base_service_definition;
$service_definitions[] = array(
$service_definitions[] = [
'shared' => FALSE,
) + $base_service_definition;
] + $base_service_definition;
// Test factory.
$service_definitions[] = array(
'factory' => array(new Reference('bar'), 'factoryMethod'),
'factory_expected' => array($this->getServiceCall('bar'), 'factoryMethod'),
) + $base_service_definition;
$service_definitions[] = [
'factory' => [new Reference('bar'), 'factoryMethod'],
'factory_expected' => [$this->getServiceCall('bar'), 'factoryMethod'],
] + $base_service_definition;
// Test invalid factory - needed to test deep dumpValue().
$service_definitions[] = array(
'factory' => array(array('foo', 'llama'), 'factoryMethod'),
) + $base_service_definition;
$service_definitions[] = [
'factory' => [['foo', 'llama'], 'factoryMethod'],
] + $base_service_definition;
// Test properties.
$service_definitions[] = array(
'properties' => array('_value' => 'llama'),
) + $base_service_definition;
$service_definitions[] = [
'properties' => ['_value' => 'llama'],
] + $base_service_definition;
// Test configurator.
$service_definitions[] = array(
'configurator' => array(new Reference('bar'), 'configureService'),
'configurator_expected' => array($this->getServiceCall('bar'), 'configureService'),
) + $base_service_definition;
$service_definitions[] = [
'configurator' => [new Reference('bar'), 'configureService'],
'configurator_expected' => [$this->getServiceCall('bar'), 'configureService'],
] + $base_service_definition;
$services_provided = array();
$services_provided[] = array(
array(),
array(),
);
$services_provided = [];
$services_provided[] = [
[],
[],
];
foreach ($service_definitions as $service_definition) {
$definition = $this->prophesize('\Symfony\Component\DependencyInjection\Definition');
@ -411,7 +414,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
$definition->getConfigurator()->willReturn($service_definition['configurator']);
// Preserve order.
$filtered_service_definition = array();
$filtered_service_definition = [];
foreach ($base_service_definition as $key => $value) {
$filtered_service_definition[$key] = $service_definition[$key];
unset($service_definition[$key]);
@ -429,7 +432,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
$filtered_service_definition += $service_definition;
// Allow to set _expected values.
foreach (array('arguments', 'factory', 'configurator') as $key) {
foreach (['arguments', 'factory', 'configurator'] as $key) {
$expected = $key . '_expected';
if (isset($filtered_service_definition[$expected])) {
$filtered_service_definition[$key] = $filtered_service_definition[$expected];
@ -441,17 +444,17 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
unset($filtered_service_definition['scope']);
if (isset($filtered_service_definition['public']) && $filtered_service_definition['public'] === FALSE) {
$services_provided[] = array(
array('foo_service' => $definition->reveal()),
array(),
);
$services_provided[] = [
['foo_service' => $definition->reveal()],
[],
];
continue;
}
$services_provided[] = array(
array('foo_service' => $definition->reveal()),
array('foo_service' => $this->serializeDefinition($filtered_service_definition)),
);
$services_provided[] = [
['foo_service' => $definition->reveal()],
['foo_service' => $this->serializeDefinition($filtered_service_definition)],
];
}
return $services_provided;
@ -470,19 +473,17 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
* Helper function to return a service definition.
*/
protected function getServiceCall($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) {
return (object) array(
return (object) [
'type' => 'service',
'id' => $id,
'invalidBehavior' => $invalid_behavior,
);
];
}
/**
* Tests that the correct InvalidArgumentException is thrown for getScope().
*
* @covers ::getServiceDefinition
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
public function testGetServiceDefinitionWithInvalidScope() {
$bar_definition = new Definition('\stdClass');
@ -490,6 +491,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
$services['bar'] = $bar_definition;
$this->containerBuilder->getDefinitions()->willReturn($services);
$this->setExpectedException(InvalidArgumentException::class);
$this->dumper->getArray();
}
@ -502,9 +504,9 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
*/
public function testGetServiceDefinitionWithReferenceToAlias($public) {
$bar_definition = new Definition('\stdClass');
$bar_definition_php_array = array(
$bar_definition_php_array = [
'class' => '\stdClass',
);
];
if (!$public) {
$bar_definition->setPublic(FALSE);
$bar_definition_php_array['public'] = FALSE;
@ -530,21 +532,21 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
else {
$service_definition = $this->getPrivateServiceCall('bar', $bar_definition_php_array, TRUE);
}
$data = array(
$data = [
'class' => '\stdClass',
'arguments' => $this->getCollection(array(
'arguments' => $this->getCollection([
$service_definition,
)),
]),
'arguments_count' => 1,
);
];
$this->assertEquals($this->serializeDefinition($data), $dump['services']['foo'], 'Expected definition matches dump.');
}
public function publicPrivateDataProvider() {
return array(
array(TRUE),
array(FALSE),
);
return [
[TRUE],
[FALSE],
];
}
/**
@ -554,8 +556,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
* getDecoratedService().
*
* @covers ::getServiceDefinition
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
public function testGetServiceDefinitionForDecoratedService() {
$bar_definition = new Definition('\stdClass');
@ -563,6 +563,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
$services['bar'] = $bar_definition;
$this->containerBuilder->getDefinitions()->willReturn($services);
$this->setExpectedException(InvalidArgumentException::class);
$this->dumper->getArray();
}
@ -570,8 +571,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
* Tests that the correct RuntimeException is thrown for expressions.
*
* @covers ::dumpValue
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
*/
public function testGetServiceDefinitionForExpression() {
$expression = new Expression();
@ -581,6 +580,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
$services['bar'] = $bar_definition;
$this->containerBuilder->getDefinitions()->willReturn($services);
$this->setExpectedException(RuntimeException::class);
$this->dumper->getArray();
}
@ -588,8 +588,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
* Tests that the correct RuntimeException is thrown for dumping an object.
*
* @covers ::dumpValue
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
*/
public function testGetServiceDefinitionForObject() {
$service = new \stdClass();
@ -599,6 +597,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
$services['bar'] = $bar_definition;
$this->containerBuilder->getDefinitions()->willReturn($services);
$this->setExpectedException(RuntimeException::class);
$this->dumper->getArray();
}
@ -606,8 +605,6 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
* Tests that the correct RuntimeException is thrown for dumping a resource.
*
* @covers ::dumpValue
*
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
*/
public function testGetServiceDefinitionForResource() {
$resource = fopen('php://memory', 'r');
@ -617,6 +614,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
$services['bar'] = $bar_definition;
$this->containerBuilder->getDefinitions()->willReturn($services);
$this->setExpectedException(RuntimeException::class);
$this->dumper->getArray();
}
@ -625,36 +623,36 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
*/
protected function getPrivateServiceCall($id, $service_definition, $shared = FALSE) {
if (!$id) {
$hash = sha1(serialize($service_definition));
$hash = Crypt::hashBase64(serialize($service_definition));
$id = 'private__' . $hash;
}
return (object) array(
return (object) [
'type' => 'private_service',
'id' => $id,
'value' => $service_definition,
'shared' => $shared,
);
];
}
/**
* Helper function to return a machine-optimized collection.
*/
protected function getCollection($collection, $resolve = TRUE) {
return (object) array(
return (object) [
'type' => 'collection',
'value' => $collection,
'resolve' => $resolve,
);
];
}
/**
* Helper function to return a parameter definition.
*/
protected function getParameterCall($name) {
return (object) array(
return (object) [
'type' => 'parameter',
'name' => $name,
);
];
}
}

View file

@ -34,12 +34,12 @@ class YamlDiscoveryTest extends UnitTestCase {
file_put_contents($url . '/test_2/test_4.test.yml', '');
// Set up the directories to search.
$directories = array(
$directories = [
'test_1' => $url . '/test_1',
'test_2' => $url . '/test_1',
'test_3' => $url . '/test_2',
'test_4' => $url . '/test_2',
);
];
$discovery = new YamlDiscovery('test', $directories);
$data = $discovery->findAll();
@ -50,12 +50,12 @@ class YamlDiscoveryTest extends UnitTestCase {
$this->assertArrayHasKey('test_3', $data);
$this->assertArrayHasKey('test_4', $data);
foreach (array('test_1', 'test_2', 'test_3') as $key) {
foreach (['test_1', 'test_2', 'test_3'] as $key) {
$this->assertArrayHasKey('name', $data[$key]);
$this->assertEquals($data[$key]['name'], 'test');
}
$this->assertSame(array(), $data['test_4']);
$this->assertSame([], $data['test_4']);
}
}

View file

@ -42,7 +42,7 @@ class DrupalComponentTest extends UnitTestCase {
* An array of class paths.
*/
protected function findPhpClasses($dir) {
$classes = array();
$classes = [];
foreach (new \DirectoryIterator($dir) as $file) {
if ($file->isDir() && !$file->isDot()) {
$classes = array_merge($classes, $this->findPhpClasses($file->getPathname()));
@ -80,26 +80,26 @@ class DrupalComponentTest extends UnitTestCase {
* - File data as a string. This will be used as a virtual file.
*/
public function providerAssertNoCoreUseage() {
return array(
array(
return [
[
TRUE,
'@see \\Drupal\\Core\\Something',
),
array(
],
[
FALSE,
'\\Drupal\\Core\\Something',
),
array(
],
[
FALSE,
"@see \\Drupal\\Core\\Something\n" .
'\\Drupal\\Core\\Something',
),
array(
],
[
FALSE,
"\\Drupal\\Core\\Something\n" .
'@see \\Drupal\\Core\\Something',
),
);
],
];
}
/**

View file

@ -55,12 +55,10 @@ class FileCacheFactoryTest extends UnitTestCase {
/**
* @covers ::get
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Required prefix configuration is missing
*/
public function testGetNoPrefix() {
FileCacheFactory::setPrefix(NULL);
$this->setExpectedException(\InvalidArgumentException::class, 'Required prefix configuration is missing');
FileCacheFactory::get('test_foo_settings', []);
}
@ -101,8 +99,8 @@ class FileCacheFactoryTest extends UnitTestCase {
// Get a unique FileCache class.
$file_cache = $this->getMockBuilder(FileCache::class)
->disableOriginalConstructor()
->getMock();
->disableOriginalConstructor()
->getMock();
$class = get_class($file_cache);
// Test fallback configuration.

View file

@ -48,22 +48,22 @@ class PoHeaderTest extends UnitTestCase {
* value.
*/
public function providerTestPluralsFormula() {
return array(
array(
return [
[
'nplurals=1; plural=0;',
array('default' => 0),
),
array(
['default' => 0],
],
[
'nplurals=2; plural=(n > 1);',
array(0 => 0, 1 => 0, 'default' => 1),
),
array(
[0 => 0, 1 => 0, 'default' => 1],
],
[
'nplurals=2; plural=(n!=1);',
array(1 => 0, 'default' => 1),
),
array(
[1 => 0, 'default' => 1],
],
[
'nplurals=2; plural=(((n==1)||((n%10)==1))?(0):1);',
array(
[
1 => 0,
11 => 0,
21 => 0,
@ -85,11 +85,11 @@ class PoHeaderTest extends UnitTestCase {
181 => 0,
191 => 0,
'default' => 1,
),
),
array(
],
],
[
'nplurals=3; plural=((((n%10)==1)&&((n%100)!=11))?(0):(((((n%10)>=2)&&((n%10)<=4))&&(((n%100)<10)||((n%100)>=20)))?(1):2));',
array(
[
1 => 0,
2 => 1,
3 => 1,
@ -163,21 +163,21 @@ class PoHeaderTest extends UnitTestCase {
193 => 1,
194 => 1,
'default' => 2,
),
),
array(
],
],
[
'nplurals=3; plural=((n==1)?(0):(((n>=2)&&(n<=4))?(1):2));',
array(
[
1 => 0,
2 => 1,
3 => 1,
4 => 1,
'default' => 2,
),
),
array(
],
],
[
'nplurals=3; plural=((n==1)?(0):(((n==0)||(((n%100)>0)&&((n%100)<20)))?(1):2));',
array(
[
0 => 1,
1 => 0,
2 => 1,
@ -218,11 +218,11 @@ class PoHeaderTest extends UnitTestCase {
118 => 1,
119 => 1,
'default' => 2,
),
),
array(
],
],
[
'nplurals=3; plural=((n==1)?(0):(((((n%10)>=2)&&((n%10)<=4))&&(((n%100)<10)||((n%100)>=20)))?(1):2));',
array(
[
1 => 0,
2 => 1,
3 => 1,
@ -279,10 +279,10 @@ class PoHeaderTest extends UnitTestCase {
193 => 1,
194 => 1,
'default' => 2,
),),
array(
], ],
[
'nplurals=4; plural=(((n==1)||(n==11))?(0):(((n==2)||(n==12))?(1):(((n>2)&&(n<20))?(2):3)));',
array(
[
1 => 0,
2 => 1,
3 => 2,
@ -303,11 +303,11 @@ class PoHeaderTest extends UnitTestCase {
18 => 2,
19 => 2,
'default' => 3,
),
),
array(
],
],
[
'nplurals=4; plural=(((n%100)==1)?(0):(((n%100)==2)?(1):((((n%100)==3)||((n%100)==4))?(2):3)));',
array(
[
1 => 0,
2 => 1,
3 => 2,
@ -317,11 +317,11 @@ class PoHeaderTest extends UnitTestCase {
103 => 2,
104 => 2,
'default' => 3,
),
),
array(
],
],
[
'nplurals=5; plural=((n==1)?(0):((n==2)?(1):((n<7)?(2):((n<11)?(3):4))));',
array(
[
0 => 2,
1 => 0,
2 => 1,
@ -334,11 +334,11 @@ class PoHeaderTest extends UnitTestCase {
9 => 3,
10 => 3,
'default' => 4,
),
),
array(
],
],
[
'nplurals=6; plural=((n==1)?(0):((n==0)?(1):((n==2)?(2):((((n%100)>=3)&&((n%100)<=10))?(3):((((n%100)>=11)&&((n%100)<=99))?(4):5)))));',
array(
[
0 => 1,
1 => 0,
2 => 2,
@ -362,9 +362,9 @@ class PoHeaderTest extends UnitTestCase {
109 => 3,
110 => 3,
'default' => 4,
),
),
);
],
],
];
}
}

View file

@ -21,59 +21,59 @@ class GraphTest extends UnitTestCase {
// | | |
// | | |
// +---> 4 <-- 7 8 ---> 9
$graph = $this->normalizeGraph(array(
1 => array(2),
2 => array(3, 4),
3 => array(),
4 => array(3),
5 => array(6),
7 => array(4, 5),
8 => array(9),
9 => array(),
));
$graph = $this->normalizeGraph([
1 => [2],
2 => [3, 4],
3 => [],
4 => [3],
5 => [6],
7 => [4, 5],
8 => [9],
9 => [],
]);
$graph_object = new Graph($graph);
$graph = $graph_object->searchAndSort();
$expected_paths = array(
1 => array(2, 3, 4),
2 => array(3, 4),
3 => array(),
4 => array(3),
5 => array(6),
7 => array(4, 3, 5, 6),
8 => array(9),
9 => array(),
);
$expected_paths = [
1 => [2, 3, 4],
2 => [3, 4],
3 => [],
4 => [3],
5 => [6],
7 => [4, 3, 5, 6],
8 => [9],
9 => [],
];
$this->assertPaths($graph, $expected_paths);
$expected_reverse_paths = array(
1 => array(),
2 => array(1),
3 => array(2, 1, 4, 7),
4 => array(2, 1, 7),
5 => array(7),
7 => array(),
8 => array(),
9 => array(8),
);
$expected_reverse_paths = [
1 => [],
2 => [1],
3 => [2, 1, 4, 7],
4 => [2, 1, 7],
5 => [7],
7 => [],
8 => [],
9 => [8],
];
$this->assertReversePaths($graph, $expected_reverse_paths);
// Assert that DFS didn't created "missing" vertexes automatically.
$this->assertFalse(isset($graph[6]), 'Vertex 6 has not been created');
$expected_components = array(
array(1, 2, 3, 4, 5, 7),
array(8, 9),
);
$expected_components = [
[1, 2, 3, 4, 5, 7],
[8, 9],
];
$this->assertComponents($graph, $expected_components);
$expected_weights = array(
array(1, 2, 3),
array(2, 4, 3),
array(7, 4, 3),
array(7, 5),
array(8, 9),
);
$expected_weights = [
[1, 2, 3],
[2, 4, 3],
[7, 4, 3],
[7, 5],
[8, 9],
];
$this->assertWeights($graph, $expected_weights);
}
@ -87,10 +87,10 @@ class GraphTest extends UnitTestCase {
* The normalized version of a graph.
*/
protected function normalizeGraph($graph) {
$normalized_graph = array();
$normalized_graph = [];
foreach ($graph as $vertex => $edges) {
// Create vertex even if it hasn't any edges.
$normalized_graph[$vertex] = array();
$normalized_graph[$vertex] = [];
foreach ($edges as $edge) {
$normalized_graph[$vertex]['edges'][$edge] = TRUE;
}
@ -110,7 +110,7 @@ class GraphTest extends UnitTestCase {
foreach ($expected_paths as $vertex => $paths) {
// Build an array with keys = $paths and values = TRUE.
$expected = array_fill_keys($paths, TRUE);
$result = isset($graph[$vertex]['paths']) ? $graph[$vertex]['paths'] : array();
$result = isset($graph[$vertex]['paths']) ? $graph[$vertex]['paths'] : [];
$this->assertEquals($expected, $result, sprintf('Expected paths for vertex %s: %s, got %s', $vertex, $this->displayArray($expected, TRUE), $this->displayArray($result, TRUE)));
}
}
@ -128,7 +128,7 @@ class GraphTest extends UnitTestCase {
foreach ($expected_reverse_paths as $vertex => $paths) {
// Build an array with keys = $paths and values = TRUE.
$expected = array_fill_keys($paths, TRUE);
$result = isset($graph[$vertex]['reverse_paths']) ? $graph[$vertex]['reverse_paths'] : array();
$result = isset($graph[$vertex]['reverse_paths']) ? $graph[$vertex]['reverse_paths'] : [];
$this->assertEquals($expected, $result, sprintf('Expected reverse paths for vertex %s: %s, got %s', $vertex, $this->displayArray($expected, TRUE), $this->displayArray($result, TRUE)));
}
}
@ -144,14 +144,14 @@ class GraphTest extends UnitTestCase {
protected function assertComponents($graph, $expected_components) {
$unassigned_vertices = array_fill_keys(array_keys($graph), TRUE);
foreach ($expected_components as $component) {
$result_components = array();
$result_components = [];
foreach ($component as $vertex) {
$result_components[] = $graph[$vertex]['component'];
unset($unassigned_vertices[$vertex]);
}
$this->assertEquals(1, count(array_unique($result_components)), sprintf('Expected one unique component for vertices %s, got %s', $this->displayArray($component), $this->displayArray($result_components)));
}
$this->assertEquals(array(), $unassigned_vertices, sprintf('Vertices not assigned to a component: %s', $this->displayArray($unassigned_vertices, TRUE)));
$this->assertEquals([], $unassigned_vertices, sprintf('Vertices not assigned to a component: %s', $this->displayArray($unassigned_vertices, TRUE)));
}
/**

View file

@ -33,15 +33,15 @@ class FileStorageReadOnlyTest extends PhpStorageTestBase {
protected function setUp() {
parent::setUp();
$this->standardSettings = array(
$this->standardSettings = [
'directory' => $this->directory,
'bin' => 'test',
);
$this->readonlyStorage = array(
];
$this->readonlyStorage = [
'directory' => $this->directory,
// Let this read from the bin where the other instance is writing.
'bin' => 'test',
);
];
}
/**

View file

@ -24,10 +24,10 @@ class FileStorageTest extends PhpStorageTestBase {
protected function setUp() {
parent::setUp();
$this->standardSettings = array(
$this->standardSettings = [
'directory' => $this->directory,
'bin' => 'test',
);
];
}
/**

View file

@ -19,7 +19,7 @@ class MTimeProtectedFastFileStorageTest extends MTimeProtectedFileStorageBase {
* include the hacked file on the first try but the second test will change
* the directory mtime and so on the second try the file will not be included.
*/
protected $expected = array(TRUE, FALSE);
protected $expected = [TRUE, FALSE];
/**
* The PHP storage class to test.

View file

@ -2,6 +2,8 @@
namespace Drupal\Tests\Component\PhpStorage;
use Drupal\Component\Utility\Crypt;
/**
* Base test class for MTime protected storage.
*/
@ -36,11 +38,11 @@ abstract class MTimeProtectedFileStorageBase extends PhpStorageTestBase {
$this->secret = $this->randomMachineName();
$this->settings = array(
$this->settings = [
'directory' => $this->directory,
'bin' => 'test',
'secret' => $this->secret,
);
];
}
/**
@ -77,7 +79,7 @@ abstract class MTimeProtectedFileStorageBase extends PhpStorageTestBase {
$expected_directory = $expected_root_directory . '/' . $name;
}
$directory_mtime = filemtime($expected_directory);
$expected_filename = $expected_directory . '/' . hash_hmac('sha256', $name, $this->secret . $directory_mtime) . '.php';
$expected_filename = $expected_directory . '/' . Crypt::hmacBase64($name, $this->secret . $directory_mtime) . '.php';
// Ensure the file exists and that it and the containing directory have
// minimal permissions. fileperms() can return high bits unrelated to
@ -88,7 +90,7 @@ abstract class MTimeProtectedFileStorageBase extends PhpStorageTestBase {
// Ensure the root directory for the bin has a .htaccess file denying web
// access.
$this->assertSame(file_get_contents($expected_root_directory . '/.htaccess'), call_user_func(array($this->storageClass, 'htaccessLines')));
$this->assertSame(file_get_contents($expected_root_directory . '/.htaccess'), call_user_func([$this->storageClass, 'htaccessLines']));
// Ensure that if the file is replaced with an untrusted one (due to another
// script's file upload vulnerability), it does not get loaded. Since mtime

View file

@ -18,7 +18,7 @@ class MTimeProtectedFileStorageTest extends MTimeProtectedFileStorageBase {
* The default implementation protects against even the filemtime change so
* both iterations will return FALSE.
*/
protected $expected = array(FALSE, FALSE);
protected $expected = [FALSE, FALSE];
/**
* The PHP storage class to test.

View file

@ -30,7 +30,7 @@ class ContextTest extends UnitTestCase {
// Mock a Context object.
$mock_context = $this->getMockBuilder('Drupal\Component\Plugin\Context\Context')
->disableOriginalConstructor()
->setMethods(array('getContextDefinition'))
->setMethods(['getContextDefinition'])
->getMock();
// If the context value exists, getContextValue() behaves like a normal
@ -49,7 +49,7 @@ class ContextTest extends UnitTestCase {
else {
// Create a mock definition.
$mock_definition = $this->getMockBuilder('Drupal\Component\Plugin\Context\ContextDefinitionInterface')
->setMethods(array('isRequired', 'getDataType'))
->setMethods(['isRequired', 'getDataType'])
->getMockForAbstractClass();
// Set expectation for isRequired().
@ -87,7 +87,7 @@ class ContextTest extends UnitTestCase {
*/
public function testDefaultValue() {
$mock_definition = $this->getMockBuilder('Drupal\Component\Plugin\Context\ContextDefinitionInterface')
->setMethods(array('getDefaultValue'))
->setMethods(['getDefaultValue'])
->getMockForAbstractClass();
$mock_definition->expects($this->once())

View file

@ -3,6 +3,7 @@
namespace Drupal\Tests\Component\Plugin;
use Drupal\Component\Plugin\Definition\PluginDefinitionInterface;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\plugin_test\Plugin\plugin_test\fruit\Cherry;
use Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface;
@ -47,11 +48,9 @@ class DefaultFactoryTest extends UnitTestCase {
* Tests getPluginClass() with a missing class definition.
*
* @covers ::getPluginClass
*
* @expectedException \Drupal\Component\Plugin\Exception\PluginException
* @expectedExceptionMessage The plugin (cherry) did not specify an instance class.
*/
public function testGetPluginClassWithMissingClassWithArrayPluginDefinition() {
$this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.');
DefaultFactory::getPluginClass('cherry', []);
}
@ -59,12 +58,10 @@ class DefaultFactoryTest extends UnitTestCase {
* Tests getPluginClass() with a missing class definition.
*
* @covers ::getPluginClass
*
* @expectedException \Drupal\Component\Plugin\Exception\PluginException
* @expectedExceptionMessage The plugin (cherry) did not specify an instance class.
*/
public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() {
$plugin_definition = $this->getMock(PluginDefinitionInterface::class);
$this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.');
DefaultFactory::getPluginClass('cherry', $plugin_definition);
}
@ -72,11 +69,9 @@ class DefaultFactoryTest extends UnitTestCase {
* Tests getPluginClass() with a not existing class definition.
*
* @covers ::getPluginClass
*
* @expectedException \Drupal\Component\Plugin\Exception\PluginException
* @expectedExceptionMessage Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.
*/
public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition() {
$this->setExpectedException(PluginException::class, 'Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.');
DefaultFactory::getPluginClass('kiwifruit', ['class' => '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit']);
}
@ -84,8 +79,6 @@ class DefaultFactoryTest extends UnitTestCase {
* Tests getPluginClass() with a not existing class definition.
*
* @covers ::getPluginClass
*
* @expectedException \Drupal\Component\Plugin\Exception\PluginException
*/
public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition() {
$plugin_class = '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit';
@ -93,6 +86,7 @@ class DefaultFactoryTest extends UnitTestCase {
$plugin_definition->expects($this->atLeastOnce())
->method('getClass')
->willReturn($plugin_class);
$this->setExpectedException(PluginException::class);
DefaultFactory::getPluginClass('kiwifruit', $plugin_definition);
}
@ -128,12 +122,10 @@ class DefaultFactoryTest extends UnitTestCase {
* Tests getPluginClass() with a required interface but no implementation.
*
* @covers ::getPluginClass
*
* @expectedException \Drupal\Component\Plugin\Exception\PluginException
* @expectedExceptionMessage Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.
*/
public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDefinition() {
$plugin_class = Kale::class;
$this->setExpectedException(PluginException::class, 'Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.');
DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class, 'provider' => 'core'], FruitInterface::class);
}
@ -141,8 +133,6 @@ class DefaultFactoryTest extends UnitTestCase {
* Tests getPluginClass() with a required interface but no implementation.
*
* @covers ::getPluginClass
*
* @expectedException \Drupal\Component\Plugin\Exception\PluginException
*/
public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDefinition() {
$plugin_class = Kale::class;
@ -150,6 +140,7 @@ class DefaultFactoryTest extends UnitTestCase {
$plugin_definition->expects($this->atLeastOnce())
->method('getClass')
->willReturn($plugin_class);
$this->setExpectedException(PluginException::class);
DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class);
}

View file

@ -21,11 +21,11 @@ class DiscoveryCachedTraitTest extends UnitTestCase {
* - Plugin name to query for.
*/
public function providerGetDefinition() {
return array(
return [
['definition', [], ['plugin_name' => 'definition'], 'plugin_name'],
['definition', ['plugin_name' => 'definition'], [], 'plugin_name'],
[NULL, ['plugin_name' => 'definition'], [], 'bad_plugin_name'],
);
];
}
/**

View file

@ -2,6 +2,7 @@
namespace Drupal\Tests\Component\Plugin\Discovery;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Tests\UnitTestCase;
/**
@ -19,10 +20,10 @@ class DiscoveryTraitTest extends UnitTestCase {
* - Plugin ID to get, passed to doGetDefinition().
*/
public function providerDoGetDefinition() {
return array(
return [
['definition', ['plugin_name' => 'definition'], 'plugin_name'],
[NULL, ['plugin_name' => 'definition'], 'bad_plugin_name'],
);
];
}
/**
@ -51,14 +52,13 @@ class DiscoveryTraitTest extends UnitTestCase {
* - Plugin ID to get, passed to doGetDefinition().
*/
public function providerDoGetDefinitionException() {
return array(
return [
[FALSE, ['plugin_name' => 'definition'], 'bad_plugin_name'],
);
];
}
/**
* @covers ::doGetDefinition
* @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @dataProvider providerDoGetDefinitionException
* @uses \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
@ -69,10 +69,8 @@ class DiscoveryTraitTest extends UnitTestCase {
$method_ref = new \ReflectionMethod($trait, 'doGetDefinition');
$method_ref->setAccessible(TRUE);
// Call doGetDefinition, with $exception_on_invalid always TRUE.
$this->assertSame(
$expected,
$method_ref->invoke($trait, $definitions, $plugin_id, TRUE)
);
$this->setExpectedException(PluginNotFoundException::class);
$method_ref->invoke($trait, $definitions, $plugin_id, TRUE);
}
/**
@ -96,7 +94,6 @@ class DiscoveryTraitTest extends UnitTestCase {
/**
* @covers ::getDefinition
* @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @dataProvider providerDoGetDefinitionException
* @uses \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
@ -109,10 +106,8 @@ class DiscoveryTraitTest extends UnitTestCase {
->method('getDefinitions')
->willReturn($definitions);
// Call getDefinition(), with $exception_on_invalid always TRUE.
$this->assertSame(
$expected,
$trait->getDefinition($plugin_id, TRUE)
);
$this->setExpectedException(PluginNotFoundException::class);
$trait->getDefinition($plugin_id, TRUE);
}
/**
@ -123,10 +118,10 @@ class DiscoveryTraitTest extends UnitTestCase {
* - Plugin ID to look for.
*/
public function providerHasDefinition() {
return array(
return [
[TRUE, 'valid'],
[FALSE, 'not_valid'],
);
];
}
/**
@ -135,16 +130,16 @@ class DiscoveryTraitTest extends UnitTestCase {
*/
public function testHasDefinition($expected, $plugin_id) {
$trait = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\DiscoveryTrait')
->setMethods(array('getDefinition'))
->setMethods(['getDefinition'])
->getMockForTrait();
// Set up our mocked getDefinition() to return TRUE for 'valid' and FALSE
// for 'not_valid'.
$trait->expects($this->once())
->method('getDefinition')
->will($this->returnValueMap(array(
->will($this->returnValueMap([
['valid', FALSE, TRUE],
['not_valid', FALSE, FALSE],
)));
]));
// Call hasDefinition().
$this->assertSame(
$expected,

View file

@ -23,7 +23,7 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
*/
public function getRegisterDefinitionsCallback() {
$mock_callable = $this->getMockBuilder('\stdClass')
->setMethods(array('registerDefinitionsCallback'))
->setMethods(['registerDefinitionsCallback'])
->getMock();
// Set expectations for the callback method.
$mock_callable->expects($this->once())
@ -62,7 +62,7 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
// Mock our StaticDiscoveryDecorator.
$mock_decorator = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator')
->disableOriginalConstructor()
->setMethods(array('registeredDefintionCallback'))
->setMethods(['registeredDefintionCallback'])
->getMock();
// Set up the ::$registerDefinitions property.
@ -72,7 +72,7 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
// Set the callback object on the mocked decorator.
$ref_register_definitions->setValue(
$mock_decorator,
array($this->getRegisterDefinitionsCallback(), 'registerDefinitionsCallback')
[$this->getRegisterDefinitionsCallback(), 'registerDefinitionsCallback']
);
}
else {
@ -83,11 +83,11 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
// Set up ::$definitions to an empty array.
$ref_definitions = new \ReflectionProperty($mock_decorator, 'definitions');
$ref_definitions->setAccessible(TRUE);
$ref_definitions->setValue($mock_decorator, array());
$ref_definitions->setValue($mock_decorator, []);
// Mock a decorated object.
$mock_decorated = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\DiscoveryInterface')
->setMethods(array('getDefinitions'))
->setMethods(['getDefinitions'])
->getMockForAbstractClass();
// Return our definitions from getDefinitions().
$mock_decorated->expects($this->once())
@ -132,7 +132,7 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
// Mock our StaticDiscoveryDecorator.
$mock_decorator = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator')
->disableOriginalConstructor()
->setMethods(array('registeredDefintionCallback'))
->setMethods(['registeredDefintionCallback'])
->getMock();
// Set up the ::$registerDefinitions property.
@ -142,7 +142,7 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
// Set the callback object on the mocked decorator.
$ref_register_definitions->setValue(
$mock_decorator,
array($this->getRegisterDefinitionsCallback(), 'registerDefinitionsCallback')
[$this->getRegisterDefinitionsCallback(), 'registerDefinitionsCallback']
);
}
else {
@ -153,11 +153,11 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
// Set up ::$definitions to an empty array.
$ref_definitions = new \ReflectionProperty($mock_decorator, 'definitions');
$ref_definitions->setAccessible(TRUE);
$ref_definitions->setValue($mock_decorator, array());
$ref_definitions->setValue($mock_decorator, []);
// Mock a decorated object.
$mock_decorated = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\DiscoveryInterface')
->setMethods(array('getDefinitions'))
->setMethods(['getDefinitions'])
->getMockForAbstractClass();
// Our mocked method will return any arguments sent to it.
$mock_decorated->expects($this->once())
@ -199,7 +199,7 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
public function testCall($method, $args) {
// Mock a decorated object.
$mock_decorated = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\DiscoveryInterface')
->setMethods(array($method))
->setMethods([$method])
->getMockForAbstractClass();
// Our mocked method will return any arguments sent to it.
$mock_decorated->expects($this->once())
@ -222,7 +222,7 @@ class StaticDiscoveryDecoratorTest extends UnitTestCase {
// Exercise __call.
$this->assertArrayEquals(
$args,
\call_user_func_array(array($mock_decorated, $method), $args)
\call_user_func_array([$mock_decorated, $method], $args)
);
}

View file

@ -88,7 +88,7 @@ class ReflectionFactoryTest extends UnitTestCase {
public function testCreateInstance($expected, $reflector_name, $plugin_id, $plugin_definition, $configuration) {
// Create a mock DiscoveryInterface which can return our plugin definition.
$mock_discovery = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\DiscoveryInterface')
->setMethods(array('getDefinition', 'getDefinitions', 'hasDefinition'))
->setMethods(['getDefinition', 'getDefinitions', 'hasDefinition'])
->getMock();
$mock_discovery->expects($this->never())->method('getDefinitions');
$mock_discovery->expects($this->never())->method('hasDefinition');

View file

@ -15,11 +15,11 @@ class PluginBaseTest extends UnitTestCase {
* @covers ::getPluginId
*/
public function testGetPluginId($plugin_id, $expected) {
$plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', array(
array(),
$plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
[],
$plugin_id,
array(),
));
[],
]);
$this->assertEquals($expected, $plugin_base->getPluginId());
}
@ -30,10 +30,10 @@ class PluginBaseTest extends UnitTestCase {
* @return array
*/
public function providerTestGetPluginId() {
return array(
array('base_id', 'base_id'),
array('base_id:derivative', 'base_id:derivative'),
);
return [
['base_id', 'base_id'],
['base_id:derivative', 'base_id:derivative'],
];
}
/**
@ -42,11 +42,11 @@ class PluginBaseTest extends UnitTestCase {
*/
public function testGetBaseId($plugin_id, $expected) {
/** @var \Drupal\Component\Plugin\PluginBase|\PHPUnit_Framework_MockObject_MockObject $plugin_base */
$plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', array(
array(),
$plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
[],
$plugin_id,
array(),
));
[],
]);
$this->assertEquals($expected, $plugin_base->getBaseId());
}
@ -57,10 +57,10 @@ class PluginBaseTest extends UnitTestCase {
* @return array
*/
public function providerTestGetBaseId() {
return array(
array('base_id', 'base_id'),
array('base_id:derivative', 'base_id'),
);
return [
['base_id', 'base_id'],
['base_id:derivative', 'base_id'],
];
}
@ -70,11 +70,11 @@ class PluginBaseTest extends UnitTestCase {
*/
public function testGetDerivativeId($plugin_id = NULL, $expected = NULL) {
/** @var \Drupal\Component\Plugin\PluginBase|\PHPUnit_Framework_MockObject_MockObject $plugin_base */
$plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', array(
array(),
$plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
[],
$plugin_id,
array(),
));
[],
]);
$this->assertEquals($expected, $plugin_base->getDerivativeId());
}
@ -85,23 +85,23 @@ class PluginBaseTest extends UnitTestCase {
* @return array
*/
public function providerTestGetDerivativeId() {
return array(
array('base_id', NULL),
array('base_id:derivative', 'derivative'),
);
return [
['base_id', NULL],
['base_id:derivative', 'derivative'],
];
}
/**
* @covers ::getPluginDefinition
*/
public function testGetPluginDefinition() {
$plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', array(
array(),
$plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
[],
'plugin_id',
array('value', array('key' => 'value')),
));
['value', ['key' => 'value']],
]);
$this->assertEquals(array('value', array('key' => 'value')), $plugin_base->getPluginDefinition());
$this->assertEquals(['value', ['key' => 'value']], $plugin_base->getPluginDefinition());
}
}

View file

@ -21,10 +21,10 @@ class PluginManagerBaseTest extends UnitTestCase {
if ('invalid' == $plugin_id) {
throw new PluginNotFoundException($plugin_id);
}
return array(
return [
'plugin_id' => $plugin_id,
'configuration' => $configuration,
);
];
}
/**
@ -32,11 +32,11 @@ class PluginManagerBaseTest extends UnitTestCase {
*/
public function getMockFactoryInterface($expects_count) {
$mock_factory = $this->getMockBuilder('Drupal\Component\Plugin\Factory\FactoryInterface')
->setMethods(array('createInstance'))
->setMethods(['createInstance'])
->getMockForAbstractClass();
$mock_factory->expects($this->exactly($expects_count))
->method('createInstance')
->willReturnCallback(array($this, 'createInstanceCallback'));
->willReturnCallback([$this, 'createInstanceCallback']);
return $mock_factory;
}
@ -55,7 +55,7 @@ class PluginManagerBaseTest extends UnitTestCase {
$factory_ref->setValue($manager, $this->getMockFactoryInterface(1));
// Finally the test.
$configuration_array = array('config' => 'something');
$configuration_array = ['config' => 'something'];
$result = $manager->createInstance('valid', $configuration_array);
$this->assertEquals('valid', $result['plugin_id']);
$this->assertArrayEquals($configuration_array, $result['configuration']);
@ -75,7 +75,7 @@ class PluginManagerBaseTest extends UnitTestCase {
$factory_ref->setAccessible(TRUE);
// Set up the configuration array.
$configuration_array = array('config' => 'something');
$configuration_array = ['config' => 'something'];
// Test with fallback interface and valid plugin_id.
$factory_ref->setValue($manager, $this->getMockFactoryInterface(1));

View file

@ -20,7 +20,7 @@ class StubFallbackPluginManager extends PluginManagerBase implements FallbackPlu
/**
* {@inheritdoc}
*/
public function getFallbackPluginId($plugin_id, array $configuration = array()) {
public function getFallbackPluginId($plugin_id, array $configuration = []) {
// Minimally implement getFallbackPluginId so that we can test it.
return $plugin_id . '_fallback';
}

View file

@ -381,7 +381,7 @@ class TestServiceMethodWithParameter {
class TestServiceComplexMethod {
public function complexMethod($parameter, callable $function, TestServiceNoMethod $test_service = NULL, array &$elements = array()) {
public function complexMethod($parameter, callable $function, TestServiceNoMethod $test_service = NULL, array &$elements = []) {
}

View file

@ -31,23 +31,23 @@ class HtmlEscapedTextTest extends UnitTestCase {
*
* @see testToString()
*/
function providerToString() {
public function providerToString() {
// Checks that invalid multi-byte sequences are escaped.
$tests[] = array("Foo\xC0barbaz", 'Foo<6F>barbaz', 'Escapes invalid sequence "Foo\xC0barbaz"');
$tests[] = array("\xc2\"", '<27>&quot;', 'Escapes invalid sequence "\xc2\""');
$tests[] = array("Fooÿñ", "Fooÿñ", 'Does not escape valid sequence "Fooÿñ"');
$tests[] = ["Foo\xC0barbaz", 'Foo<6F>barbaz', 'Escapes invalid sequence "Foo\xC0barbaz"'];
$tests[] = ["\xc2\"", '<27>&quot;', 'Escapes invalid sequence "\xc2\""'];
$tests[] = ["Fooÿñ", "Fooÿñ", 'Does not escape valid sequence "Fooÿñ"'];
// Checks that special characters are escaped.
$script_tag = $this->prophesize(MarkupInterface::class);
$script_tag->__toString()->willReturn('<script>');
$script_tag = $script_tag->reveal();
$tests[] = array($script_tag, '&lt;script&gt;', 'Escapes &lt;script&gt; even inside an object that implements MarkupInterface.');
$tests[] = array("<script>", '&lt;script&gt;', 'Escapes &lt;script&gt;');
$tests[] = array('<>&"\'', '&lt;&gt;&amp;&quot;&#039;', 'Escapes reserved HTML characters.');
$tests[] = [$script_tag, '&lt;script&gt;', 'Escapes &lt;script&gt; even inside an object that implements MarkupInterface.'];
$tests[] = ["<script>", '&lt;script&gt;', 'Escapes &lt;script&gt;'];
$tests[] = ['<>&"\'', '&lt;&gt;&amp;&quot;&#039;', 'Escapes reserved HTML characters.'];
$specialchars = $this->prophesize(MarkupInterface::class);
$specialchars->__toString()->willReturn('<>&"\'');
$specialchars = $specialchars->reveal();
$tests[] = array($specialchars, '&lt;&gt;&amp;&quot;&#039;', 'Escapes reserved HTML characters even inside an object that implements MarkupInterface.');
$tests[] = [$specialchars, '&lt;&gt;&amp;&quot;&#039;', 'Escapes reserved HTML characters even inside an object that implements MarkupInterface.'];
return $tests;
}

View file

@ -48,9 +48,9 @@ class JsonTest extends UnitTestCase {
// Characters that must be escaped.
// We check for unescaped " separately.
$this->htmlUnsafe = array('<', '>', '\'', '&');
$this->htmlUnsafe = ['<', '>', '\'', '&'];
// The following are the encoded forms of: < > ' & "
$this->htmlUnsafeEscaped = array('\u003C', '\u003E', '\u0027', '\u0026', '\u0022');
$this->htmlUnsafeEscaped = ['\u003C', '\u003E', '\u0027', '\u0026', '\u0022'];
}
/**
@ -100,7 +100,7 @@ class JsonTest extends UnitTestCase {
public function testStructuredReversibility() {
// Verify reversibility for structured data. Also verify that necessary
// characters are escaped.
$source = array(TRUE, FALSE, 0, 1, '0', '1', $this->string, array('key1' => $this->string, 'key2' => array('nested' => TRUE)));
$source = [TRUE, FALSE, 0, 1, '0', '1', $this->string, ['key1' => $this->string, 'key2' => ['nested' => TRUE]]];
$json = Json::encode($source);
foreach ($this->htmlUnsafe as $char) {
$this->assertTrue(strpos($json, $char) === FALSE, sprintf('A JSON encoded string does not contain %s.', $char));

View file

@ -2,6 +2,7 @@
namespace Drupal\Tests\Component\Serialization;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use Drupal\Component\Serialization\YamlPecl;
/**
@ -74,9 +75,9 @@ foo:
* Tests that invalid YAML throws an exception.
*
* @covers ::errorHandler
* @expectedException \Drupal\Component\Serialization\Exception\InvalidDataTypeException
*/
public function testError() {
$this->setExpectedException(InvalidDataTypeException::class);
YamlPecl::decode('foo: [ads');
}

View file

@ -2,6 +2,7 @@
namespace Drupal\Tests\Component\Serialization;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use Drupal\Component\Serialization\YamlSymfony;
/**
@ -56,9 +57,9 @@ class YamlSymfonyTest extends YamlTestBase {
* Tests that invalid YAML throws an exception.
*
* @covers ::decode
* @expectedException \Drupal\Component\Serialization\Exception\InvalidDataTypeException
*/
public function testError() {
$this->setExpectedException(InvalidDataTypeException::class);
YamlSymfony::decode('foo: [ads');
}

View file

@ -40,32 +40,32 @@ class PhpTransliterationTest extends UnitTestCase {
* self::testRemoveDiacritics().
*/
public function providerTestPhpTransliterationRemoveDiacritics() {
return array(
return [
// Test all characters in the Unicode range 0x00bf to 0x017f.
array('ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ', 'AAAAAAÆCEEEEIIII'),
array('ÐÑÒÓÔÕÖרÙÚÛÜÝÞß', 'ÐNOOOOO×OUUUUYÞß'),
array('àáâãäåæçèéêëìíîï', 'aaaaaaæceeeeiiii'),
array('ðñòóôõö÷øùúûüýþÿ', 'ðnooooo÷ouuuuyþy'),
array('ĀāĂ㥹ĆćĈĉĊċČčĎď', 'AaAaAaCcCcCcCcDd'),
array('ĐđĒēĔĕĖėĘęĚěĜĝĞğ', 'DdEeEeEeEeEeGgGg'),
array('ĠġĢģĤĥĦħĨĩĪīĬĭĮį', 'GgGgHhHhIiIiIiIi'),
array('İıIJijĴĵĶķĸĹĺĻļĽľĿ', 'IiIJijJjKkĸLlLlLlL'),
array('ŀŁłŃńŅņŇňʼnŊŋŌōŎŏ', 'lLlNnNnNnʼnŊŋOoOo'),
array('ŐőŒœŔŕŖŗŘřŚśŜŝŞş', 'OoŒœRrRrRrSsSsSs'),
array('ŠšŢţŤťŦŧŨũŪūŬŭŮů', 'SsTtTtTtUuUuUuUu'),
array('ŰűŲųŴŵŶŷŸŹźŻżŽž', 'UuUuWwYyYZzZzZz'),
['ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ', 'AAAAAAÆCEEEEIIII'],
['ÐÑÒÓÔÕÖרÙÚÛÜÝÞß', 'ÐNOOOOO×OUUUUYÞß'],
['àáâãäåæçèéêëìíîï', 'aaaaaaæceeeeiiii'],
['ðñòóôõö÷øùúûüýþÿ', 'ðnooooo÷ouuuuyþy'],
['ĀāĂ㥹ĆćĈĉĊċČčĎď', 'AaAaAaCcCcCcCcDd'],
['ĐđĒēĔĕĖėĘęĚěĜĝĞğ', 'DdEeEeEeEeEeGgGg'],
['ĠġĢģĤĥĦħĨĩĪīĬĭĮį', 'GgGgHhHhIiIiIiIi'],
['İıIJijĴĵĶķĸĹĺĻļĽľĿ', 'IiIJijJjKkĸLlLlLlL'],
['ŀŁłŃńŅņŇňʼnŊŋŌōŎŏ', 'lLlNnNnNnʼnŊŋOoOo'],
['ŐőŒœŔŕŖŗŘřŚśŜŝŞş', 'OoŒœRrRrRrSsSsSs'],
['ŠšŢţŤťŦŧŨũŪūŬŭŮů', 'SsTtTtTtUuUuUuUu'],
['ŰűŲųŴŵŶŷŸŹźŻżŽž', 'UuUuWwYyYZzZzZz'],
// Test all characters in the Unicode range 0x01CD to 0x024F.
array('ǍǎǏ', 'AaI'),
array('ǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟ', 'iOoUuUuUuUuUuǝAa'),
array('ǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯ', 'AaǢǣGgGgKkOoOoǮǯ'),
array('ǰDZDzdzǴǵǶǷǸǹǺǻǼǽǾǿ', 'jDZDzdzGgǶǷNnAaǼǽOo'),
array('ȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏ', 'AaAaEeEeIiIiOoOo'),
array('ȐȑȒȓȔȕȖȗȘșȚțȜȝȞȟ', 'RrRrUuUuSsTtȜȝHh'),
array('ȠȡȢȣȤȥȦȧȨȩȪȫȬȭȮȯ', 'ȠȡȢȣZzAaEeOoOoOo'),
array('ȰȱȲȳȴȵȶȷȸȹȺȻȼȽȾȿ', 'OoYylntjȸȹACcLTs'),
array('ɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏ', 'zɁɂBUɅEeJjQqRrYy'),
);
['ǍǎǏ', 'AaI'],
['ǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟ', 'iOoUuUuUuUuUuǝAa'],
['ǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯ', 'AaǢǣGgGgKkOoOoǮǯ'],
['ǰDZDzdzǴǵǶǷǸǹǺǻǼǽǾǿ', 'jDZDzdzGgǶǷNnAaǼǽOo'],
['ȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏ', 'AaAaEeEeIiIiOoOo'],
['ȐȑȒȓȔȕȖȗȘșȚțȜȝȞȟ', 'RrRrUuUuSsTtȜȝHh'],
['ȠȡȢȣȤȥȦȧȨȩȪȫȬȭȮȯ', 'ȠȡȢȣZzAaEeOoOoOo'],
['ȰȱȲȳȴȵȶȷȸȹȺȻȼȽȾȿ', 'OoYylntjȸȹACcLTs'],
['ɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏ', 'zɁɂBUɅEeJjQqRrYy'],
];
}
/**
@ -117,36 +117,36 @@ class PhpTransliterationTest extends UnitTestCase {
// They are not in our tables, but should at least give us '?' (unknown).
$five_byte = html_entity_decode('&#x10330;&#x10338;', ENT_NOQUOTES, 'UTF-8');
return array(
return [
// Each test case is (language code, input, output).
// Test ASCII in English.
array('en', $random, $random),
['en', $random, $random],
// Test ASCII in some other language with no overrides.
array('fr', $random, $random),
['fr', $random, $random],
// Test 3 and 4-byte characters in a language without overrides.
// Note: if the data tables change, these will need to change too! They
// are set up to test that data table loading works, so values come
// directly from the data files.
array('fr', $three_byte, 'c'),
array('fr', $four_byte, 'wii'),
['fr', $three_byte, 'c'],
['fr', $four_byte, 'wii'],
// Test 5-byte characters.
array('en', $five_byte, '??'),
['en', $five_byte, '??'],
// Test a language with no overrides.
array('en', $two_byte, 'A O U A O aouaohello'),
['en', $two_byte, 'A O U A O aouaohello'],
// Test language overrides provided by core.
array('de', $two_byte, 'Ae Oe Ue A O aeoeueaohello'),
array('de', $random, $random),
array('dk', $two_byte, 'A O U Aa Oe aouaaoehello'),
array('dk', $random, $random),
array('kg', $three_byte, 'ts'),
['de', $two_byte, 'Ae Oe Ue A O aeoeueaohello'],
['de', $random, $random],
['dk', $two_byte, 'A O U Aa Oe aouaaoehello'],
['dk', $random, $random],
['kg', $three_byte, 'ts'],
// Test strings in some other languages.
// Turkish, provided by drupal.org user Kartagis.
array('tr', 'Abayı serdiler bize. Söyleyeceğim yüzlerine. Sanırım hepimiz aynı şeyi düşünüyoruz.', 'Abayi serdiler bize. Soyleyecegim yuzlerine. Sanirim hepimiz ayni seyi dusunuyoruz.'),
['tr', 'Abayı serdiler bize. Söyleyeceğim yüzlerine. Sanırım hepimiz aynı şeyi düşünüyoruz.', 'Abayi serdiler bize. Soyleyecegim yuzlerine. Sanirim hepimiz ayni seyi dusunuyoruz.'],
// Illegal/unknown unicode.
array('en', chr(0xF8) . chr(0x80) . chr(0x80) . chr(0x80) . chr(0x80), '?'),
['en', chr(0xF8) . chr(0x80) . chr(0x80) . chr(0x80) . chr(0x80), '?'],
// Max length.
array('de', $two_byte, 'Ae Oe', '?', 5),
);
['de', $two_byte, 'Ae Oe', '?', 5],
];
}
/**

View file

@ -121,9 +121,6 @@ class ArgumentsResolverTest extends UnitTestCase {
* Tests getArgument() with a wildcard parameter with no typehint.
*
* Without the typehint, the wildcard object will not be passed to the callable.
*
* @expectedException \RuntimeException
* @expectedExceptionMessage requires a value for the "$route" argument.
*/
public function testGetWildcardArgumentNoTypehint() {
$a = $this->getMock('\Drupal\Tests\Component\Utility\TestInterface1');
@ -131,8 +128,8 @@ class ArgumentsResolverTest extends UnitTestCase {
$resolver = new ArgumentsResolver([], [], $wildcards);
$callable = function($route) {};
$arguments = $resolver->getArguments($callable);
$this->assertNull($arguments);
$this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.');
$resolver->getArguments($callable);
}
/**
@ -152,9 +149,6 @@ class ArgumentsResolverTest extends UnitTestCase {
/**
* Tests handleUnresolvedArgument() for a scalar argument.
*
* @expectedException \RuntimeException
* @expectedExceptionMessage requires a value for the "$foo" argument.
*/
public function testHandleNotUpcastedArgument() {
$objects = ['foo' => 'bar'];
@ -162,22 +156,19 @@ class ArgumentsResolverTest extends UnitTestCase {
$resolver = new ArgumentsResolver($scalars, $objects, []);
$callable = function(\stdClass $foo) {};
$arguments = $resolver->getArguments($callable);
$this->assertNull($arguments);
$this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.');
$resolver->getArguments($callable);
}
/**
* Tests handleUnresolvedArgument() for missing arguments.
*
* @expectedException \RuntimeException
* @expectedExceptionMessage requires a value for the "$foo" argument.
*
* @dataProvider providerTestHandleUnresolvedArgument
*/
public function testHandleUnresolvedArgument($callable) {
$resolver = new ArgumentsResolver([], [], []);
$arguments = $resolver->getArguments($callable);
$this->assertNull($arguments);
$this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.');
$resolver->getArguments($callable);
}
/**

View file

@ -40,21 +40,21 @@ class BytesTest extends UnitTestCase {
* value.
*/
public function providerTestToInt() {
return array(
array('1', 1),
array('1 byte', 1),
array('1 KB' , Bytes::KILOBYTE),
array('1 MB' , pow(Bytes::KILOBYTE, 2)),
array('1 GB' , pow(Bytes::KILOBYTE, 3)),
array('1 TB' , pow(Bytes::KILOBYTE, 4)),
array('1 PB' , pow(Bytes::KILOBYTE, 5)),
array('1 EB' , pow(Bytes::KILOBYTE, 6)),
array('1 ZB' , pow(Bytes::KILOBYTE, 7)),
array('1 YB' , pow(Bytes::KILOBYTE, 8)),
array('23476892 bytes', 23476892),
array('76MRandomStringThatShouldBeIgnoredByParseSize.', 79691776), // 76 MB
array('76.24 Giggabyte', 81862076662), // 76.24 GB (with typo)
);
return [
['1', 1],
['1 byte', 1],
['1 KB' , Bytes::KILOBYTE],
['1 MB' , pow(Bytes::KILOBYTE, 2)],
['1 GB' , pow(Bytes::KILOBYTE, 3)],
['1 TB' , pow(Bytes::KILOBYTE, 4)],
['1 PB' , pow(Bytes::KILOBYTE, 5)],
['1 EB' , pow(Bytes::KILOBYTE, 6)],
['1 ZB' , pow(Bytes::KILOBYTE, 7)],
['1 YB' , pow(Bytes::KILOBYTE, 8)],
['23476892 bytes', 23476892],
['76MRandomStringThatShouldBeIgnoredByParseSize.', 79691776], // 76 MB
['76.24 Giggabyte', 81862076662], // 76.24 GB (with typo)
];
}
}

View file

@ -43,35 +43,35 @@ class ColorTest extends UnitTestCase {
* - (optional) Boolean indicating invalid status. Defaults to FALSE.
*/
public function providerTestHexToRgb() {
$invalid = array();
$invalid = [];
// Any invalid arguments should throw an exception.
foreach (array('', '-1', '1', '12', '12345', '1234567', '123456789', '123456789a', 'foo') as $value) {
$invalid[] = array($value, '', TRUE);
foreach (['', '-1', '1', '12', '12345', '1234567', '123456789', '123456789a', 'foo'] as $value) {
$invalid[] = [$value, '', TRUE];
}
// Duplicate all invalid value tests with additional '#' prefix.
// The '#' prefix inherently turns the data type into a string.
foreach ($invalid as $value) {
$invalid[] = array('#' . $value[0], '', TRUE);
$invalid[] = ['#' . $value[0], '', TRUE];
}
// Add invalid data types (hex value must be a string).
foreach (array(
foreach ([
1, 12, 1234, 12345, 123456, 1234567, 12345678, 123456789, 123456789,
-1, PHP_INT_MAX, PHP_INT_MAX + 1, -PHP_INT_MAX, 0x0, 0x010
) as $value) {
$invalid[] = array($value, '', TRUE);
] as $value) {
$invalid[] = [$value, '', TRUE];
}
// And some valid values.
$valid = array(
$valid = [
// Shorthands without alpha.
array('hex' => '#000', 'rgb' => array('red' => 0, 'green' => 0, 'blue' => 0)),
array('hex' => '#fff', 'rgb' => array('red' => 255, 'green' => 255, 'blue' => 255)),
array('hex' => '#abc', 'rgb' => array('red' => 170, 'green' => 187, 'blue' => 204)),
array('hex' => 'cba', 'rgb' => array('red' => 204, 'green' => 187, 'blue' => 170)),
['hex' => '#000', 'rgb' => ['red' => 0, 'green' => 0, 'blue' => 0]],
['hex' => '#fff', 'rgb' => ['red' => 255, 'green' => 255, 'blue' => 255]],
['hex' => '#abc', 'rgb' => ['red' => 170, 'green' => 187, 'blue' => 204]],
['hex' => 'cba', 'rgb' => ['red' => 204, 'green' => 187, 'blue' => 170]],
// Full without alpha.
array('hex' => '#000000', 'rgb' => array('red' => 0, 'green' => 0, 'blue' => 0)),
array('hex' => '#ffffff', 'rgb' => array('red' => 255, 'green' => 255, 'blue' => 255)),
array('hex' => '#010203', 'rgb' => array('red' => 1, 'green' => 2, 'blue' => 3)),
);
['hex' => '#000000', 'rgb' => ['red' => 0, 'green' => 0, 'blue' => 0]],
['hex' => '#ffffff', 'rgb' => ['red' => 255, 'green' => 255, 'blue' => 255]],
['hex' => '#010203', 'rgb' => ['red' => 1, 'green' => 2, 'blue' => 3]],
];
return array_merge($invalid, $valid);
}
@ -101,19 +101,19 @@ class ColorTest extends UnitTestCase {
*/
public function providerTestRbgToHex() {
// Input using named RGB array (e.g., as returned by Color::hexToRgb()).
$tests = array(
array(array('red' => 0, 'green' => 0, 'blue' => 0), '#000000'),
array(array('red' => 255, 'green' => 255, 'blue' => 255), '#ffffff'),
array(array('red' => 119, 'green' => 119, 'blue' => 119), '#777777'),
array(array('red' => 1, 'green' => 2, 'blue' => 3), '#010203'),
);
$tests = [
[['red' => 0, 'green' => 0, 'blue' => 0], '#000000'],
[['red' => 255, 'green' => 255, 'blue' => 255], '#ffffff'],
[['red' => 119, 'green' => 119, 'blue' => 119], '#777777'],
[['red' => 1, 'green' => 2, 'blue' => 3], '#010203'],
];
// Input using indexed RGB array (e.g.: array(10, 10, 10)).
foreach ($tests as $test) {
$tests[] = array(array_values($test[0]), $test[1]);
$tests[] = [array_values($test[0]), $test[1]];
}
// Input using CSS RGB string notation (e.g.: 10, 10, 10).
foreach ($tests as $test) {
$tests[] = array(implode(', ', $test[0]), $test[1]);
$tests[] = [implode(', ', $test[0]), $test[1]];
}
return $tests;
}

View file

@ -0,0 +1,71 @@
<?php
namespace Drupal\Tests\Component\Utility;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Utility\Crypt;
/**
* Tests random byte generation fallback exception situations.
*
* @group Utility
*
* @runTestsInSeparateProcesses
*
* @coversDefaultClass \Drupal\Component\Utility\Crypt
*/
class CryptRandomFallbackTest extends UnitTestCase {
static protected $functionCalled = 0;
/**
* Allows the test to confirm that the namespaced random_bytes() was called.
*/
public static function functionCalled() {
static::$functionCalled++;
}
/**
* Tests random byte generation using the fallback generator.
*
* If the call to random_bytes() throws an exception, Crypt::random_bytes()
* should still return a useful string of random bytes.
*
* @covers ::randomBytes
*
* @see \Drupal\Tests\Component\Utility\CryptTest::testRandomBytes()
*/
public function testRandomBytesFallback() {
// This loop is a copy of
// \Drupal\Tests\Component\Utility\CryptTest::testRandomBytes().
for ($i = 0; $i < 10; $i++) {
$count = rand(10, 10000);
// Check that different values are being generated.
$this->assertNotEquals(Crypt::randomBytes($count), Crypt::randomBytes($count));
// Check the length.
$this->assertEquals($count, strlen(Crypt::randomBytes($count)));
}
$this->assertEquals(30, static::$functionCalled, 'The namespaced function was called the expected number of times.');
}
}
namespace Drupal\Component\Utility;
use \Drupal\Tests\Component\Utility\CryptRandomFallbackTest;
/**
* Defines a function in same namespace as Drupal\Component\Utility\Crypt.
*
* Forces throwing an exception in this test environment because the function
* in the namespace is used in preference to the global function.
*
* @param int $count
* Matches the global function definition.
*
* @throws \Exception
*/
function random_bytes($count) {
CryptRandomFallbackTest::functionCalled();
throw new \Exception($count);
}

View file

@ -18,6 +18,8 @@ class CryptTest extends UnitTestCase {
* Tests random byte generation.
*
* @covers ::randomBytes
*
* @see \Drupal\Tests\Component\Utility\CryptRandomFallbackTest::testRandomBytesFallback
*/
public function testRandomBytes() {
for ($i = 1; $i < 10; $i++) {
@ -67,7 +69,6 @@ class CryptTest extends UnitTestCase {
* Tests the hmacBase64 method with invalid parameters.
*
* @dataProvider providerTestHmacBase64Invalid
* @expectedException InvalidArgumentException
* @covers ::hmacBase64
*
* @param string $data
@ -76,6 +77,7 @@ class CryptTest extends UnitTestCase {
* Key to use in hashing process.
*/
public function testHmacBase64Invalid($data, $key) {
$this->setExpectedException(\InvalidArgumentException::class);
Crypt::hmacBase64($data, $key);
}
@ -85,16 +87,16 @@ class CryptTest extends UnitTestCase {
* @return array Test data.
*/
public function providerTestHashBase64() {
return array(
array(
return [
[
'data' => 'The SHA (Secure Hash Algorithm) is one of a number of cryptographic hash functions. A cryptographic hash is like a signature for a text or a data file. SHA-256 algorithm generates an almost-unique, fixed size 256-bit (32-byte) hash. Hash is a one way function it cannot be decrypted back. This makes it suitable for password validation, challenge hash authentication, anti-tamper, digital signatures.',
'expectedHash' => '034rT6smZAVRxpq8O98cFFNLIVx_Ph1EwLZQKcmRR_s',
),
array(
],
[
'data' => 'SHA-256 is one of the successor hash functions to SHA-1, and is one of the strongest hash functions available.',
'expected_hash' => 'yuqkDDYqprL71k4xIb6K6D7n76xldO4jseRhEkEE6SI',
),
);
],
];
}
/**
@ -103,13 +105,13 @@ class CryptTest extends UnitTestCase {
* @return array Test data.
*/
public function providerTestHmacBase64() {
return array(
array(
return [
[
'data' => 'Calculates a base-64 encoded, URL-safe sha-256 hmac.',
'key' => 'secret-key',
'expected_hmac' => '2AaH63zwjhekWZlEpAiufyfhAHIzbQhl9Hd9oCi3_c8',
),
);
],
];
}
/**
@ -118,33 +120,33 @@ class CryptTest extends UnitTestCase {
* @return array Test data.
*/
public function providerTestHmacBase64Invalid() {
return array(
array(new \stdClass(), new \stdClass()),
array(new \stdClass(), 'string'),
array(new \stdClass(), 1),
array(new \stdClass(), 0),
array(NULL, new \stdClass()),
array('string', new \stdClass()),
array(1, new \stdClass()),
array(0, new \stdClass()),
array(array(), array()),
array(array(), NULL),
array(array(), 'string'),
array(array(), 1),
array(array(), 0),
array(NULL, array()),
array(1, array()),
array(0, array()),
array('string', array()),
array(array(), NULL),
array(NULL, NULL),
array(NULL, 'string'),
array(NULL, 1),
array(NULL, 0),
array(1, NULL),
array(0, NULL),
array('string', NULL),
);
return [
[new \stdClass(), new \stdClass()],
[new \stdClass(), 'string'],
[new \stdClass(), 1],
[new \stdClass(), 0],
[NULL, new \stdClass()],
['string', new \stdClass()],
[1, new \stdClass()],
[0, new \stdClass()],
[[], []],
[[], NULL],
[[], 'string'],
[[], 1],
[[], 0],
[NULL, []],
[1, []],
[0, []],
['string', []],
[[], NULL],
[NULL, NULL],
[NULL, 'string'],
[NULL, 1],
[NULL, 0],
[1, NULL],
[0, NULL],
['string', NULL],
];
}
}

View file

@ -47,16 +47,16 @@ class EnvironmentTest extends UnitTestCase {
$memory_limit = ini_get('memory_limit');
$twice_avail_memory = ($memory_limit * 2) . 'MB';
return array(
return [
// Minimal amount of memory should be available.
array('30MB', NULL, TRUE),
['30MB', NULL, TRUE],
// Exceed a custom (unlimited) memory limit.
array($twice_avail_memory, -1, TRUE),
[$twice_avail_memory, -1, TRUE],
// Exceed a custom memory limit.
array('30MB', '16MB', FALSE),
['30MB', '16MB', FALSE],
// Available = required.
array('30MB', '30MB', TRUE),
);
['30MB', '30MB', TRUE],
];
}
}

View file

@ -59,25 +59,25 @@ class HtmlTest extends UnitTestCase {
$id1 = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789';
$id2 = '¡¢£¤¥';
$id3 = 'css__identifier__with__double__underscores';
return array(
return [
// Verify that no valid ASCII characters are stripped from the identifier.
array($id1, $id1, array()),
[$id1, $id1, []],
// Verify that valid UTF-8 characters are not stripped from the identifier.
array($id2, $id2, array()),
[$id2, $id2, []],
// Verify that invalid characters (including non-breaking space) are stripped from the identifier.
array($id3, $id3),
[$id3, $id3],
// Verify that double underscores are not stripped from the identifier.
array('invalididentifier', 'invalid !"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ identifier', array()),
['invalididentifier', 'invalid !"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ identifier', []],
// Verify that an identifier starting with a digit is replaced.
array('_cssidentifier', '1cssidentifier', array()),
['_cssidentifier', '1cssidentifier', []],
// Verify that an identifier starting with a hyphen followed by a digit is
// replaced.
array('__cssidentifier', '-1cssidentifier', array()),
['__cssidentifier', '-1cssidentifier', []],
// Verify that an identifier starting with two hyphens is replaced.
array('__cssidentifier', '--cssidentifier', array()),
['__cssidentifier', '--cssidentifier', []],
// Verify that passing double underscores as a filter is processed.
array('_cssidentifier', '__cssidentifier', array('__' => '_')),
);
['_cssidentifier', '__cssidentifier', ['__' => '_']],
];
}
/**
@ -119,18 +119,18 @@ class HtmlTest extends UnitTestCase {
*/
public function providerTestHtmlGetUniqueId() {
$id = 'abcdefghijklmnopqrstuvwxyz-0123456789';
return array(
return [
// Verify that letters, digits, and hyphens are not stripped from the ID.
array($id, $id),
[$id, $id],
// Verify that invalid characters are stripped from the ID.
array('invalididentifier', 'invalid,./:@\\^`{Üidentifier'),
['invalididentifier', 'invalid,./:@\\^`{Üidentifier'],
// Verify Drupal coding standards are enforced.
array('id-name-1', 'ID NAME_[1]'),
['id-name-1', 'ID NAME_[1]'],
// Verify that a repeated ID is made unique.
array('test-unique-id', 'test-unique-id', TRUE),
array('test-unique-id--2', 'test-unique-id'),
array('test-unique-id--3', 'test-unique-id'),
);
['test-unique-id', 'test-unique-id', TRUE],
['test-unique-id--2', 'test-unique-id'],
['test-unique-id--3', 'test-unique-id'],
];
}
/**
@ -168,13 +168,13 @@ class HtmlTest extends UnitTestCase {
* Test data.
*/
public function providerTestHtmlGetUniqueIdWithAjaxIds() {
return array(
array('test-unique-id1--', 'test-unique-id1'),
return [
['test-unique-id1--', 'test-unique-id1'],
// Note, we truncate two hyphens at the end.
// @see \Drupal\Component\Utility\Html::getId()
array('test-unique-id1---', 'test-unique-id1--'),
array('test-unique-id2--', 'test-unique-id2'),
);
['test-unique-id1---', 'test-unique-id1--'],
['test-unique-id2--', 'test-unique-id2'],
];
}
/**
@ -202,17 +202,17 @@ class HtmlTest extends UnitTestCase {
*/
public function providerTestHtmlGetId() {
$id = 'abcdefghijklmnopqrstuvwxyz-0123456789';
return array(
return [
// Verify that letters, digits, and hyphens are not stripped from the ID.
array($id, $id),
[$id, $id],
// Verify that invalid characters are stripped from the ID.
array('invalididentifier', 'invalid,./:@\\^`{Üidentifier'),
['invalididentifier', 'invalid,./:@\\^`{Üidentifier'],
// Verify Drupal coding standards are enforced.
array('id-name-1', 'ID NAME_[1]'),
['id-name-1', 'ID NAME_[1]'],
// Verify that a repeated ID is made unique.
array('test-unique-id', 'test-unique-id'),
array('test-unique-id', 'test-unique-id'),
);
['test-unique-id', 'test-unique-id'],
['test-unique-id', 'test-unique-id'],
];
}
/**
@ -231,29 +231,29 @@ class HtmlTest extends UnitTestCase {
* @see testDecodeEntities()
*/
public function providerDecodeEntities() {
return array(
array('Drupal', 'Drupal'),
array('<script>', '<script>'),
array('&lt;script&gt;', '<script>'),
array('&#60;script&#62;', '<script>'),
array('&amp;lt;script&amp;gt;', '&lt;script&gt;'),
array('"', '"'),
array('&#34;', '"'),
array('&amp;#34;', '&#34;'),
array('&quot;', '"'),
array('&amp;quot;', '&quot;'),
array("'", "'"),
array('&#39;', "'"),
array('&amp;#39;', '&#39;'),
array('©', '©'),
array('&copy;', '©'),
array('&#169;', '©'),
array('→', '→'),
array('&#8594;', '→'),
array('➼', '➼'),
array('&#10172;', '➼'),
array('&euro;', '€'),
);
return [
['Drupal', 'Drupal'],
['<script>', '<script>'],
['&lt;script&gt;', '<script>'],
['&#60;script&#62;', '<script>'],
['&amp;lt;script&amp;gt;', '&lt;script&gt;'],
['"', '"'],
['&#34;', '"'],
['&amp;#34;', '&#34;'],
['&quot;', '"'],
['&amp;quot;', '&quot;'],
["'", "'"],
['&#39;', "'"],
['&amp;#39;', '&#39;'],
['©', '©'],
['&copy;', '©'],
['&#169;', '©'],
['→', '→'],
['&#8594;', '→'],
['➼', '➼'],
['&#10172;', '➼'],
['&euro;', '€'],
];
}
/**
@ -272,21 +272,21 @@ class HtmlTest extends UnitTestCase {
* @see testEscape()
*/
public function providerEscape() {
return array(
array('Drupal', 'Drupal'),
array('&lt;script&gt;', '<script>'),
array('&amp;lt;script&amp;gt;', '&lt;script&gt;'),
array('&amp;#34;', '&#34;'),
array('&quot;', '"'),
array('&amp;quot;', '&quot;'),
array('&#039;', "'"),
array('&amp;#039;', '&#039;'),
array('©', '©'),
array('→', '→'),
array('➼', '➼'),
array('€', '€'),
array('Drup<75>al', "Drup\x80al"),
);
return [
['Drupal', 'Drupal'],
['&lt;script&gt;', '<script>'],
['&amp;lt;script&amp;gt;', '&lt;script&gt;'],
['&amp;#34;', '&#34;'],
['&quot;', '"'],
['&amp;quot;', '&quot;'],
['&#039;', "'"],
['&amp;#039;', '&#039;'],
['©', '©'],
['→', '→'],
['➼', '➼'],
['€', '€'],
['Drup<75>al', "Drup\x80al"],
];
}
/**
@ -332,9 +332,9 @@ class HtmlTest extends UnitTestCase {
/**
* @covers ::transformRootRelativeUrlsToAbsolute
* @dataProvider providerTestTransformRootRelativeUrlsToAbsoluteAssertion
* @expectedException \AssertionError
*/
public function testTransformRootRelativeUrlsToAbsoluteAssertion($scheme_and_host) {
$this->setExpectedException(\AssertionError::class);
Html::transformRootRelativeUrlsToAbsolute('', $scheme_and_host);
}

View file

@ -44,113 +44,113 @@ class ImageTest extends UnitTestCase {
*/
public function providerTestScaleDimensions() {
// Define input / output datasets to test different branch conditions.
$tests = array();
$tests = [];
// Test branch conditions:
// - No height.
// - Upscale, don't need to upscale.
$tests[] = array(
'input' => array(
'dimensions' => array(
$tests[] = [
'input' => [
'dimensions' => [
'width' => 1000,
'height' => 2000,
),
],
'width' => 200,
'height' => NULL,
'upscale' => TRUE,
),
'output' => array(
'dimensions' => array(
],
'output' => [
'dimensions' => [
'width' => 200,
'height' => 400,
),
],
'return_value' => TRUE,
),
);
],
];
// Test branch conditions:
// - No width.
// - Don't upscale, don't need to upscale.
$tests[] = array(
'input' => array(
'dimensions' => array(
$tests[] = [
'input' => [
'dimensions' => [
'width' => 1000,
'height' => 800,
),
],
'width' => NULL,
'height' => 140,
'upscale' => FALSE,
),
'output' => array(
'dimensions' => array(
],
'output' => [
'dimensions' => [
'width' => 175,
'height' => 140,
),
],
'return_value' => TRUE,
),
);
],
];
// Test branch conditions:
// - Source aspect ratio greater than target.
// - Upscale, need to upscale.
$tests[] = array(
'input' => array(
'dimensions' => array(
$tests[] = [
'input' => [
'dimensions' => [
'width' => 8,
'height' => 20,
),
],
'width' => 200,
'height' => 140,
'upscale' => TRUE,
),
'output' => array(
'dimensions' => array(
],
'output' => [
'dimensions' => [
'width' => 56,
'height' => 140,
),
],
'return_value' => TRUE,
),
);
],
];
// Test branch condition: target aspect ratio greater than source.
$tests[] = array(
'input' => array(
'dimensions' => array(
$tests[] = [
'input' => [
'dimensions' => [
'width' => 2000,
'height' => 800,
),
],
'width' => 200,
'height' => 140,
'upscale' => FALSE,
),
'output' => array(
'dimensions' => array(
],
'output' => [
'dimensions' => [
'width' => 200,
'height' => 80,
),
],
'return_value' => TRUE,
),
);
],
];
// Test branch condition: don't upscale, need to upscale.
$tests[] = array(
'input' => array(
'dimensions' => array(
$tests[] = [
'input' => [
'dimensions' => [
'width' => 100,
'height' => 50,
),
],
'width' => 200,
'height' => 140,
'upscale' => FALSE,
),
'output' => array(
'dimensions' => array(
],
'output' => [
'dimensions' => [
'width' => 100,
'height' => 50,
),
],
'return_value' => FALSE,
),
);
],
];
return $tests;
}

View file

@ -32,12 +32,12 @@ class NestedArrayTest extends UnitTestCase {
parent::setUp();
// Create a form structure with a nested element.
$this->form['details']['element'] = array(
$this->form['details']['element'] = [
'#value' => 'Nested element',
);
];
// Set up parent array.
$this->parents = array('details', 'element');
$this->parents = ['details', 'element'];
}
/**
@ -76,10 +76,10 @@ class NestedArrayTest extends UnitTestCase {
* @covers ::setValue
*/
public function testSetValue() {
$new_value = array(
$new_value = [
'#value' => 'New value',
'#required' => TRUE,
);
];
// Verify setting the value of a nested element.
NestedArray::setValue($this->form, $this->parents, $new_value);
@ -93,11 +93,11 @@ class NestedArrayTest extends UnitTestCase {
* @covers ::setValue
*/
public function testSetValueForce() {
$new_value = array(
$new_value = [
'one',
);
];
$this->form['details']['non-array-parent'] = 'string';
$parents = array('details', 'non-array-parent', 'child');
$parents = ['details', 'non-array-parent', 'child'];
NestedArray::setValue($this->form, $parents, $new_value, TRUE);
$this->assertSame($new_value, $this->form['details']['non-array-parent']['child'], 'The nested element was not forced to the new value.');
}
@ -144,23 +144,23 @@ class NestedArrayTest extends UnitTestCase {
* @covers ::mergeDeepArray
*/
public function testMergeDeepArray() {
$link_options_1 = array(
$link_options_1 = [
'fragment' => 'x',
'attributes' => array('title' => 'X', 'class' => array('a', 'b')),
'attributes' => ['title' => 'X', 'class' => ['a', 'b']],
'language' => 'en',
);
$link_options_2 = array(
];
$link_options_2 = [
'fragment' => 'y',
'attributes' => array('title' => 'Y', 'class' => array('c', 'd')),
'attributes' => ['title' => 'Y', 'class' => ['c', 'd']],
'absolute' => TRUE,
);
$expected = array(
];
$expected = [
'fragment' => 'y',
'attributes' => array('title' => 'Y', 'class' => array('a', 'b', 'c', 'd')),
'attributes' => ['title' => 'Y', 'class' => ['a', 'b', 'c', 'd']],
'language' => 'en',
'absolute' => TRUE,
);
$this->assertSame($expected, NestedArray::mergeDeepArray(array($link_options_1, $link_options_2)), 'NestedArray::mergeDeepArray() returned a properly merged array.');
];
$this->assertSame($expected, NestedArray::mergeDeepArray([$link_options_1, $link_options_2]), 'NestedArray::mergeDeepArray() returned a properly merged array.');
// Test wrapper function, NestedArray::mergeDeep().
$this->assertSame($expected, NestedArray::mergeDeep($link_options_1, $link_options_2), 'NestedArray::mergeDeep() returned a properly merged array.');
}
@ -171,18 +171,18 @@ class NestedArrayTest extends UnitTestCase {
* @covers ::mergeDeepArray
*/
public function testMergeImplicitKeys() {
$a = array(
'subkey' => array('X', 'Y'),
);
$b = array(
'subkey' => array('X'),
);
$a = [
'subkey' => ['X', 'Y'],
];
$b = [
'subkey' => ['X'],
];
// Drupal core behavior.
$expected = array(
'subkey' => array('X', 'Y', 'X'),
);
$actual = NestedArray::mergeDeepArray(array($a, $b));
$expected = [
'subkey' => ['X', 'Y', 'X'],
];
$actual = NestedArray::mergeDeepArray([$a, $b]);
$this->assertSame($expected, $actual, 'drupal_array_merge_deep() creates new numeric keys in the implicit sequence.');
}
@ -192,29 +192,29 @@ class NestedArrayTest extends UnitTestCase {
* @covers ::mergeDeepArray
*/
public function testMergeExplicitKeys() {
$a = array(
'subkey' => array(
$a = [
'subkey' => [
0 => 'A',
1 => 'B',
),
);
$b = array(
'subkey' => array(
],
];
$b = [
'subkey' => [
0 => 'C',
1 => 'D',
),
);
],
];
// Drupal core behavior.
$expected = array(
'subkey' => array(
$expected = [
'subkey' => [
0 => 'A',
1 => 'B',
2 => 'C',
3 => 'D',
),
);
$actual = NestedArray::mergeDeepArray(array($a, $b));
],
];
$actual = NestedArray::mergeDeepArray([$a, $b]);
$this->assertSame($expected, $actual, 'drupal_array_merge_deep() creates new numeric keys in the explicit sequence.');
}
@ -228,29 +228,29 @@ class NestedArrayTest extends UnitTestCase {
* @covers ::mergeDeepArray
*/
public function testMergeOutOfSequenceKeys() {
$a = array(
'subkey' => array(
$a = [
'subkey' => [
10 => 'A',
30 => 'B',
),
);
$b = array(
'subkey' => array(
],
];
$b = [
'subkey' => [
20 => 'C',
0 => 'D',
),
);
],
];
// Drupal core behavior.
$expected = array(
'subkey' => array(
$expected = [
'subkey' => [
0 => 'A',
1 => 'B',
2 => 'C',
3 => 'D',
),
);
$actual = NestedArray::mergeDeepArray(array($a, $b));
],
];
$actual = NestedArray::mergeDeepArray([$a, $b]);
$this->assertSame($expected, $actual, 'drupal_array_merge_deep() ignores numeric key order when merging.');
}

View file

@ -60,36 +60,36 @@ class NumberTest extends UnitTestCase {
* @see \Drupal\Tests\Component\Utility\Number::testValidStep
*/
public static function providerTestValidStep() {
return array(
return [
// Value and step equal.
array(10.3, 10.3, TRUE),
[10.3, 10.3, TRUE],
// Valid integer steps.
array(42, 21, TRUE),
array(42, 3, TRUE),
[42, 21, TRUE],
[42, 3, TRUE],
// Valid float steps.
array(42, 10.5, TRUE),
array(1, 1 / 3, TRUE),
array(-100, 100 / 7, TRUE),
array(1000, -10, TRUE),
[42, 10.5, TRUE],
[1, 1 / 3, TRUE],
[-100, 100 / 7, TRUE],
[1000, -10, TRUE],
// Valid and very small float steps.
array(1000.12345, 1e-10, TRUE),
array(3.9999999999999, 1e-13, TRUE),
[1000.12345, 1e-10, TRUE],
[3.9999999999999, 1e-13, TRUE],
// Invalid integer steps.
array(100, 30, FALSE),
array(-10, 4, FALSE),
[100, 30, FALSE],
[-10, 4, FALSE],
// Invalid float steps.
array(6, 5 / 7, FALSE),
array(10.3, 10.25, FALSE),
[6, 5 / 7, FALSE],
[10.3, 10.25, FALSE],
// Step mismatches very close to being valid.
array(70 + 9e-7, 10 + 9e-7, FALSE),
array(1936.5, 3e-8, FALSE),
);
[70 + 9e-7, 10 + 9e-7, FALSE],
[1936.5, 3e-8, FALSE],
];
}
/**
@ -98,22 +98,22 @@ class NumberTest extends UnitTestCase {
* @see \Drupal\Test\Component\Utility\NumberTest::testValidStepOffset()
*/
public static function providerTestValidStepOffset() {
return array(
return [
// Try obvious fits.
array(11.3, 10.3, 1, TRUE),
array(100, 10, 50, TRUE),
array(-100, 90 / 7, -10, TRUE),
array(2 / 7 + 5 / 9, 1 / 7, 5 / 9, TRUE),
[11.3, 10.3, 1, TRUE],
[100, 10, 50, TRUE],
[-100, 90 / 7, -10, TRUE],
[2 / 7 + 5 / 9, 1 / 7, 5 / 9, TRUE],
// Ensure a small offset is still invalid.
array(10.3, 10.3, 0.0001, FALSE),
array(1 / 5, 1 / 7, 1 / 11, FALSE),
[10.3, 10.3, 0.0001, FALSE],
[1 / 5, 1 / 7, 1 / 11, FALSE],
// Try negative values and offsets.
array(1000, 10, -5, FALSE),
array(-10, 4, 0, FALSE),
array(-10, 4, -4, FALSE),
);
[1000, 10, -5, FALSE],
[-10, 4, 0, FALSE],
[-10, 4, -4, FALSE],
];
}
/**
@ -144,15 +144,15 @@ class NumberTest extends UnitTestCase {
* - The alphadecimal value.
*/
public function providerTestConversions() {
return array(
array(0, '00'),
array(1, '01'),
array(10, '0a'),
array(20, '0k'),
array(35, '0z'),
array(36, '110'),
array(100, '12s'),
);
return [
[0, '00'],
[1, '01'],
[10, '0a'],
[20, '0k'],
[35, '0z'],
[36, '110'],
[100, '12s'],
];
}
}

View file

@ -29,7 +29,7 @@ class RandomTest extends UnitTestCase {
* @covers ::string
*/
public function testRandomStringUniqueness() {
$strings = array();
$strings = [];
$random = new Random();
for ($i = 0; $i <= 50; $i++) {
$str = $random->string(1, TRUE);
@ -44,7 +44,7 @@ class RandomTest extends UnitTestCase {
* @covers ::name
*/
public function testRandomNamesUniqueness() {
$names = array();
$names = [];
$random = new Random();
for ($i = 0; $i <= 10; $i++) {
$str = $random->name(1, TRUE);
@ -57,12 +57,12 @@ class RandomTest extends UnitTestCase {
* Tests infinite loop prevention whilst generating random names.
*
* @covers ::name
* @expectedException \RuntimeException
*/
public function testRandomNameException() {
// There are fewer than 100 possibilities so an exception should occur to
// prevent infinite loops.
$random = new Random();
$this->setExpectedException(\RuntimeException::class);
for ($i = 0; $i <= 100; $i++) {
$str = $random->name(1, TRUE);
$names[$str] = TRUE;
@ -73,12 +73,12 @@ class RandomTest extends UnitTestCase {
* Tests infinite loop prevention whilst generating random strings.
*
* @covers ::string
* @expectedException \RuntimeException
*/
public function testRandomStringException() {
// There are fewer than 100 possibilities so an exception should occur to
// prevent infinite loops.
$random = new Random();
$this->setExpectedException(\RuntimeException::class);
for ($i = 0; $i <= 100; $i++) {
$str = $random->string(1, TRUE);
$names[$str] = TRUE;
@ -138,7 +138,7 @@ class RandomTest extends UnitTestCase {
public function testRandomStringValidator() {
$random = new Random();
$this->firstStringGenerated = '';
$str = $random->string(1, TRUE, array($this, '_RandomStringValidate'));
$str = $random->string(1, TRUE, [$this, '_RandomStringValidate']);
$this->assertNotEquals($this->firstStringGenerated, $str);
}

View file

@ -15,10 +15,9 @@ class RectangleTest extends UnitTestCase {
* Tests wrong rectangle width.
*
* @covers ::rotate
*
* @expectedException \InvalidArgumentException
*/
public function testWrongWidth() {
$this->setExpectedException(\InvalidArgumentException::class);
$rect = new Rectangle(-40, 20);
}
@ -26,10 +25,9 @@ class RectangleTest extends UnitTestCase {
* Tests wrong rectangle height.
*
* @covers ::rotate
*
* @expectedException \InvalidArgumentException
*/
public function testWrongHeight() {
$this->setExpectedException(\InvalidArgumentException::class);
$rect = new Rectangle(40, 0);
}

View file

@ -56,7 +56,7 @@ class SafeMarkupTest extends UnitTestCase {
* @param string $message
* The message to provide as output for the test.
*/
function testCheckPlain($text, $expected, $message) {
public function testCheckPlain($text, $expected, $message) {
$result = SafeMarkup::checkPlain($text);
$this->assertTrue($result instanceof HtmlEscapedText);
$this->assertEquals($expected, $result, $message);
@ -77,7 +77,7 @@ class SafeMarkupTest extends UnitTestCase {
* @param string $message
* The message to provide as output for the test.
*/
function testHtmlEscapedText($text, $expected, $message) {
public function testHtmlEscapedText($text, $expected, $message) {
$result = new HtmlEscapedText($text);
$this->assertEquals($expected, $result, $message);
}
@ -87,17 +87,17 @@ class SafeMarkupTest extends UnitTestCase {
*
* @see testCheckPlain()
*/
function providerCheckPlain() {
public function providerCheckPlain() {
// Checks that invalid multi-byte sequences are escaped.
$tests[] = array("Foo\xC0barbaz", 'Foo<6F>barbaz', 'Escapes invalid sequence "Foo\xC0barbaz"');
$tests[] = array("\xc2\"", '<27>&quot;', 'Escapes invalid sequence "\xc2\""');
$tests[] = array("Fooÿñ", "Fooÿñ", 'Does not escape valid sequence "Fooÿñ"');
$tests[] = ["Foo\xC0barbaz", 'Foo<6F>barbaz', 'Escapes invalid sequence "Foo\xC0barbaz"'];
$tests[] = ["\xc2\"", '<27>&quot;', 'Escapes invalid sequence "\xc2\""'];
$tests[] = ["Fooÿñ", "Fooÿñ", 'Does not escape valid sequence "Fooÿñ"'];
// Checks that special characters are escaped.
$tests[] = array(SafeMarkupTestMarkup::create("<script>"), '&lt;script&gt;', 'Escapes &lt;script&gt; even inside an object that implements MarkupInterface.');
$tests[] = array("<script>", '&lt;script&gt;', 'Escapes &lt;script&gt;');
$tests[] = array('<>&"\'', '&lt;&gt;&amp;&quot;&#039;', 'Escapes reserved HTML characters.');
$tests[] = array(SafeMarkupTestMarkup::create('<>&"\''), '&lt;&gt;&amp;&quot;&#039;', 'Escapes reserved HTML characters even inside an object that implements MarkupInterface.');
$tests[] = [SafeMarkupTestMarkup::create("<script>"), '&lt;script&gt;', 'Escapes &lt;script&gt; even inside an object that implements MarkupInterface.'];
$tests[] = ["<script>", '&lt;script&gt;', 'Escapes &lt;script&gt;'];
$tests[] = ['<>&"\'', '&lt;&gt;&amp;&quot;&#039;', 'Escapes reserved HTML characters.'];
$tests[] = [SafeMarkupTestMarkup::create('<>&"\''), '&lt;&gt;&amp;&quot;&#039;', 'Escapes reserved HTML characters even inside an object that implements MarkupInterface.'];
return $tests;
}
@ -136,12 +136,12 @@ class SafeMarkupTest extends UnitTestCase {
*
* @see testFormat()
*/
function providerFormat() {
$tests[] = array('Simple text', array(), 'Simple text', 'SafeMarkup::format leaves simple text alone.', TRUE);
$tests[] = array('Escaped text: @value', array('@value' => '<script>'), 'Escaped text: &lt;script&gt;', 'SafeMarkup::format replaces and escapes string.', TRUE);
$tests[] = array('Escaped text: @value', array('@value' => SafeMarkupTestMarkup::create('<span>Safe HTML</span>')), 'Escaped text: <span>Safe HTML</span>', 'SafeMarkup::format does not escape an already safe string.', TRUE);
$tests[] = array('Placeholder text: %value', array('%value' => '<script>'), 'Placeholder text: <em class="placeholder">&lt;script&gt;</em>', 'SafeMarkup::format replaces, escapes and themes string.', TRUE);
$tests[] = array('Placeholder text: %value', array('%value' => SafeMarkupTestMarkup::create('<span>Safe HTML</span>')), 'Placeholder text: <em class="placeholder"><span>Safe HTML</span></em>', 'SafeMarkup::format does not escape an already safe string themed as a placeholder.', TRUE);
public function providerFormat() {
$tests[] = ['Simple text', [], 'Simple text', 'SafeMarkup::format leaves simple text alone.', TRUE];
$tests[] = ['Escaped text: @value', ['@value' => '<script>'], 'Escaped text: &lt;script&gt;', 'SafeMarkup::format replaces and escapes string.', TRUE];
$tests[] = ['Escaped text: @value', ['@value' => SafeMarkupTestMarkup::create('<span>Safe HTML</span>')], 'Escaped text: <span>Safe HTML</span>', 'SafeMarkup::format does not escape an already safe string.', TRUE];
$tests[] = ['Placeholder text: %value', ['%value' => '<script>'], 'Placeholder text: <em class="placeholder">&lt;script&gt;</em>', 'SafeMarkup::format replaces, escapes and themes string.', TRUE];
$tests[] = ['Placeholder text: %value', ['%value' => SafeMarkupTestMarkup::create('<span>Safe HTML</span>')], 'Placeholder text: <em class="placeholder"><span>Safe HTML</span></em>', 'SafeMarkup::format does not escape an already safe string themed as a placeholder.', TRUE];
$tests['javascript-protocol-url'] = ['Simple text <a href=":url">giraffe</a>', [':url' => 'javascript://example.com?foo&bar'], 'Simple text <a href="//example.com?foo&amp;bar">giraffe</a>', 'Support for filtering bad protocols', TRUE];
$tests['external-url'] = ['Simple text <a href=":url">giraffe</a>', [':url' => 'http://example.com?foo&bar'], 'Simple text <a href="http://example.com?foo&amp;bar">giraffe</a>', 'Support for filtering bad protocols', TRUE];

View file

@ -43,49 +43,49 @@ class SortArrayTest extends UnitTestCase {
* @see \Drupal\Tests\Component\Utility\SortArrayTest::testSortByWeightElement()
*/
public function providerSortByWeightElement() {
$tests = array();
$tests = [];
// Weights set and equal.
$tests[] = array(
array('weight' => 1),
array('weight' => 1),
$tests[] = [
['weight' => 1],
['weight' => 1],
0
);
];
// Weights set and $a is less (lighter) than $b.
$tests[] = array(
array('weight' => 1),
array('weight' => 2),
$tests[] = [
['weight' => 1],
['weight' => 2],
-1
);
];
// Weights set and $a is greater (heavier) than $b.
$tests[] = array(
array('weight' => 2),
array('weight' => 1),
$tests[] = [
['weight' => 2],
['weight' => 1],
1
);
];
// Weights not set.
$tests[] = array(
array(),
array(),
$tests[] = [
[],
[],
0
);
];
// Weights for $b not set.
$tests[] = array(
array('weight' => 1),
array(),
$tests[] = [
['weight' => 1],
[],
1
);
];
// Weights for $a not set.
$tests[] = array(
array(),
array('weight' => 1),
$tests[] = [
[],
['weight' => 1],
-1
);
];
return $tests;
}
@ -119,49 +119,49 @@ class SortArrayTest extends UnitTestCase {
* @see \Drupal\Tests\Component\Utility\SortArrayTest::testSortByWeightProperty()
*/
public function providerSortByWeightProperty() {
$tests = array();
$tests = [];
// Weights set and equal.
$tests[] = array(
array('#weight' => 1),
array('#weight' => 1),
$tests[] = [
['#weight' => 1],
['#weight' => 1],
0
);
];
// Weights set and $a is less (lighter) than $b.
$tests[] = array(
array('#weight' => 1),
array('#weight' => 2),
$tests[] = [
['#weight' => 1],
['#weight' => 2],
-1
);
];
// Weights set and $a is greater (heavier) than $b.
$tests[] = array(
array('#weight' => 2),
array('#weight' => 1),
$tests[] = [
['#weight' => 2],
['#weight' => 1],
1
);
];
// Weights not set.
$tests[] = array(
array(),
array(),
$tests[] = [
[],
[],
0
);
];
// Weights for $b not set.
$tests[] = array(
array('#weight' => 1),
array(),
$tests[] = [
['#weight' => 1],
[],
1
);
];
// Weights for $a not set.
$tests[] = array(
array(),
array('#weight' => 1),
$tests[] = [
[],
['#weight' => 1],
-1
);
];
return $tests;
}
@ -195,42 +195,42 @@ class SortArrayTest extends UnitTestCase {
* @see \Drupal\Tests\Component\Utility\SortArrayTest::testSortByTitleElement()
*/
public function providerSortByTitleElement() {
$tests = array();
$tests = [];
// Titles set and equal.
$tests[] = array(
array('title' => 'test'),
array('title' => 'test'),
$tests[] = [
['title' => 'test'],
['title' => 'test'],
0
);
];
// Title $a not set.
$tests[] = array(
array(),
array('title' => 'test'),
$tests[] = [
[],
['title' => 'test'],
-4
);
];
// Title $b not set.
$tests[] = array(
array('title' => 'test'),
array(),
$tests[] = [
['title' => 'test'],
[],
4
);
];
// Titles set but not equal.
$tests[] = array(
array('title' => 'test'),
array('title' => 'testing'),
$tests[] = [
['title' => 'test'],
['title' => 'testing'],
-1
);
];
// Titles set but not equal.
$tests[] = array(
array('title' => 'testing'),
array('title' => 'test'),
$tests[] = [
['title' => 'testing'],
['title' => 'test'],
1
);
];
return $tests;
}
@ -264,42 +264,42 @@ class SortArrayTest extends UnitTestCase {
* @see \Drupal\Tests\Component\Utility\SortArrayTest::testSortByTitleProperty()
*/
public function providerSortByTitleProperty() {
$tests = array();
$tests = [];
// Titles set and equal.
$tests[] = array(
array('#title' => 'test'),
array('#title' => 'test'),
$tests[] = [
['#title' => 'test'],
['#title' => 'test'],
0
);
];
// Title $a not set.
$tests[] = array(
array(),
array('#title' => 'test'),
$tests[] = [
[],
['#title' => 'test'],
-4
);
];
// Title $b not set.
$tests[] = array(
array('#title' => 'test'),
array(),
$tests[] = [
['#title' => 'test'],
[],
4
);
];
// Titles set but not equal.
$tests[] = array(
array('#title' => 'test'),
array('#title' => 'testing'),
$tests[] = [
['#title' => 'test'],
['#title' => 'testing'],
-1
);
];
// Titles set but not equal.
$tests[] = array(
array('#title' => 'testing'),
array('#title' => 'test'),
$tests[] = [
['#title' => 'testing'],
['#title' => 'test'],
1
);
];
return $tests;
}

View file

@ -51,15 +51,15 @@ class UnicodeTest extends UnitTestCase {
* - (optional) Boolean indicating invalid status. Defaults to FALSE.
*/
public function providerTestStatus() {
return array(
array(Unicode::STATUS_SINGLEBYTE, Unicode::STATUS_SINGLEBYTE),
array(rand(10, 100), Unicode::STATUS_SINGLEBYTE, TRUE),
array(rand(10, 100), Unicode::STATUS_SINGLEBYTE, TRUE),
array(Unicode::STATUS_MULTIBYTE, Unicode::STATUS_MULTIBYTE),
array(rand(10, 100), Unicode::STATUS_MULTIBYTE, TRUE),
array(Unicode::STATUS_ERROR, Unicode::STATUS_ERROR),
array(Unicode::STATUS_MULTIBYTE, Unicode::STATUS_MULTIBYTE),
);
return [
[Unicode::STATUS_SINGLEBYTE, Unicode::STATUS_SINGLEBYTE],
[rand(10, 100), Unicode::STATUS_SINGLEBYTE, TRUE],
[rand(10, 100), Unicode::STATUS_SINGLEBYTE, TRUE],
[Unicode::STATUS_MULTIBYTE, Unicode::STATUS_MULTIBYTE],
[rand(10, 100), Unicode::STATUS_MULTIBYTE, TRUE],
[Unicode::STATUS_ERROR, Unicode::STATUS_ERROR],
[Unicode::STATUS_MULTIBYTE, Unicode::STATUS_MULTIBYTE],
];
}
/**
@ -83,11 +83,11 @@ class UnicodeTest extends UnitTestCase {
* An array containing a string and its encoded value.
*/
public function providerTestMimeHeader() {
return array(
array('tést.txt', '=?UTF-8?B?dMOpc3QudHh0?='),
return [
['tést.txt', '=?UTF-8?B?dMOpc3QudHh0?='],
// Simple ASCII characters.
array('ASCII', 'ASCII'),
);
['ASCII', 'ASCII'],
];
}
/**
@ -113,17 +113,17 @@ class UnicodeTest extends UnitTestCase {
* be processed as multibyte.
*/
public function providerStrtolower() {
$cases = array(
array('tHe QUIcK bRoWn', 'the quick brown'),
array('FrançAIS is ÜBER-åwesome', 'français is über-åwesome'),
);
$cases = [
['tHe QUIcK bRoWn', 'the quick brown'],
['FrançAIS is ÜBER-åwesome', 'français is über-åwesome'],
];
foreach ($cases as $case) {
// Test the same string both in multibyte and singlebyte conditions.
array_push($case, TRUE);
$cases[] = $case;
}
// Add a multibyte string.
$cases[] = array('ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', 'αβγδεζηθικλμνξοσὠ', TRUE);
$cases[] = ['ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', 'αβγδεζηθικλμνξοσὠ', TRUE];
return $cases;
}
@ -150,17 +150,17 @@ class UnicodeTest extends UnitTestCase {
* be processed as multibyte.
*/
public function providerStrtoupper() {
$cases = array(
array('tHe QUIcK bRoWn', 'THE QUICK BROWN'),
array('FrançAIS is ÜBER-åwesome', 'FRANÇAIS IS ÜBER-ÅWESOME'),
);
$cases = [
['tHe QUIcK bRoWn', 'THE QUICK BROWN'],
['FrançAIS is ÜBER-åwesome', 'FRANÇAIS IS ÜBER-ÅWESOME'],
];
foreach ($cases as $case) {
// Test the same string both in multibyte and singlebyte conditions.
array_push($case, TRUE);
$cases[] = $case;
}
// Add a multibyte string.
$cases[] = array('αβγδεζηθικλμνξοσὠ', 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', TRUE);
$cases[] = ['αβγδεζηθικλμνξοσὠ', 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', TRUE];
return $cases;
}
@ -183,14 +183,14 @@ class UnicodeTest extends UnitTestCase {
* An array containing a string and its uppercase first version.
*/
public function providerUcfirst() {
return array(
array('tHe QUIcK bRoWn', 'THe QUIcK bRoWn'),
array('françAIS', 'FrançAIS'),
array('über', 'Über'),
array('åwesome', 'Åwesome'),
return [
['tHe QUIcK bRoWn', 'THe QUIcK bRoWn'],
['françAIS', 'FrançAIS'],
['über', 'Über'],
['åwesome', 'Åwesome'],
// A multibyte string.
array('σion', 'Σion'),
);
['σion', 'Σion'],
];
}
/**
@ -215,14 +215,14 @@ class UnicodeTest extends UnitTestCase {
* be processed as multibyte.
*/
public function providerLcfirst() {
return array(
array('tHe QUIcK bRoWn', 'tHe QUIcK bRoWn'),
array('FrançAIS is ÜBER-åwesome', 'françAIS is ÜBER-åwesome'),
array('Über', 'über'),
array('Åwesome', 'åwesome'),
return [
['tHe QUIcK bRoWn', 'tHe QUIcK bRoWn'],
['FrançAIS is ÜBER-åwesome', 'françAIS is ÜBER-åwesome'],
['Über', 'über'],
['Åwesome', 'åwesome'],
// Add a multibyte string.
array('ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', 'αΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', TRUE),
);
['ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', 'αΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ', TRUE],
];
}
/**
@ -247,16 +247,16 @@ class UnicodeTest extends UnitTestCase {
* be processed as multibyte.
*/
public function providerUcwords() {
return array(
array('tHe QUIcK bRoWn', 'THe QUIcK BRoWn'),
array('françAIS', 'FrançAIS'),
array('über', 'Über'),
array('åwesome', 'Åwesome'),
return [
['tHe QUIcK bRoWn', 'THe QUIcK BRoWn'],
['françAIS', 'FrançAIS'],
['über', 'Über'],
['åwesome', 'Åwesome'],
// Make sure we don't mangle extra spaces.
array('frànçAIS is über-åwesome', 'FrànçAIS Is Über-Åwesome'),
['frànçAIS is über-åwesome', 'FrànçAIS Is Über-Åwesome'],
// Add a multibyte string.
array('σion', 'Σion', TRUE),
);
['σion', 'Σion', TRUE],
];
}
/**
@ -283,11 +283,11 @@ class UnicodeTest extends UnitTestCase {
* An array containing a string and its length.
*/
public function providerStrlen() {
return array(
array('tHe QUIcK bRoWn', 15),
array('ÜBER-åwesome', 12),
array('以呂波耳・ほへとち。リヌルヲ。', 15),
);
return [
['tHe QUIcK bRoWn', 15],
['ÜBER-åwesome', 12],
['以呂波耳・ほへとち。リヌルヲ。', 15],
];
}
/**
@ -318,33 +318,33 @@ class UnicodeTest extends UnitTestCase {
* - The expected string result.
*/
public function providerSubstr() {
return array(
array('frànçAIS is über-åwesome', 0, NULL, 'frànçAIS is über-åwesome'),
array('frànçAIS is über-åwesome', 0, 0, ''),
array('frànçAIS is über-åwesome', 0, 1, 'f'),
array('frànçAIS is über-åwesome', 0, 8, 'frànçAIS'),
array('frànçAIS is über-åwesome', 0, 23, 'frànçAIS is über-åwesom'),
array('frànçAIS is über-åwesome', 0, 24, 'frànçAIS is über-åwesome'),
array('frànçAIS is über-åwesome', 0, 25, 'frànçAIS is über-åwesome'),
array('frànçAIS is über-åwesome', 0, 100, 'frànçAIS is über-åwesome'),
array('frànçAIS is über-åwesome', 4, 4, 'çAIS'),
array('frànçAIS is über-åwesome', 1, 0, ''),
array('frànçAIS is über-åwesome', 100, 0, ''),
array('frànçAIS is über-åwesome', -4, 2, 'so'),
array('frànçAIS is über-åwesome', -4, 3, 'som'),
array('frànçAIS is über-åwesome', -4, 4, 'some'),
array('frànçAIS is über-åwesome', -4, 5, 'some'),
array('frànçAIS is über-åwesome', -7, 10, 'åwesome'),
array('frànçAIS is über-åwesome', 5, -10, 'AIS is üb'),
array('frànçAIS is über-åwesome', 0, -10, 'frànçAIS is üb'),
array('frànçAIS is über-åwesome', 0, -1, 'frànçAIS is über-åwesom'),
array('frànçAIS is über-åwesome', -7, -2, 'åweso'),
array('frànçAIS is über-åwesome', -7, -6, 'å'),
array('frànçAIS is über-åwesome', -7, -7, ''),
array('frànçAIS is über-åwesome', -7, -8, ''),
array('...', 0, 2, '..'),
array('以呂波耳・ほへとち。リヌルヲ。', 1, 3, '呂波耳'),
);
return [
['frànçAIS is über-åwesome', 0, NULL, 'frànçAIS is über-åwesome'],
['frànçAIS is über-åwesome', 0, 0, ''],
['frànçAIS is über-åwesome', 0, 1, 'f'],
['frànçAIS is über-åwesome', 0, 8, 'frànçAIS'],
['frànçAIS is über-åwesome', 0, 23, 'frànçAIS is über-åwesom'],
['frànçAIS is über-åwesome', 0, 24, 'frànçAIS is über-åwesome'],
['frànçAIS is über-åwesome', 0, 25, 'frànçAIS is über-åwesome'],
['frànçAIS is über-åwesome', 0, 100, 'frànçAIS is über-åwesome'],
['frànçAIS is über-åwesome', 4, 4, 'çAIS'],
['frànçAIS is über-åwesome', 1, 0, ''],
['frànçAIS is über-åwesome', 100, 0, ''],
['frànçAIS is über-åwesome', -4, 2, 'so'],
['frànçAIS is über-åwesome', -4, 3, 'som'],
['frànçAIS is über-åwesome', -4, 4, 'some'],
['frànçAIS is über-åwesome', -4, 5, 'some'],
['frànçAIS is über-åwesome', -7, 10, 'åwesome'],
['frànçAIS is über-åwesome', 5, -10, 'AIS is üb'],
['frànçAIS is über-åwesome', 0, -10, 'frànçAIS is üb'],
['frànçAIS is über-åwesome', 0, -1, 'frànçAIS is über-åwesom'],
['frànçAIS is über-åwesome', -7, -2, 'åweso'],
['frànçAIS is über-åwesome', -7, -6, 'å'],
['frànçAIS is über-åwesome', -7, -7, ''],
['frànçAIS is über-åwesome', -7, -8, ''],
['...', 0, 2, '..'],
['以呂波耳・ほへとち。リヌルヲ。', 1, 3, '呂波耳'],
];
}
/**
@ -371,52 +371,52 @@ class UnicodeTest extends UnitTestCase {
* - (optional) Boolean for the $add_ellipsis flag. Defaults to FALSE.
*/
public function providerTruncate() {
return array(
array('frànçAIS is über-åwesome', 24, 'frànçAIS is über-åwesome'),
array('frànçAIS is über-åwesome', 23, 'frànçAIS is über-åwesom'),
array('frànçAIS is über-åwesome', 17, 'frànçAIS is über-'),
array('以呂波耳・ほへとち。リヌルヲ。', 6, '以呂波耳・ほ'),
array('frànçAIS is über-åwesome', 24, 'frànçAIS is über-åwesome', FALSE, TRUE),
array('frànçAIS is über-åwesome', 23, 'frànçAIS is über-åweso…', FALSE, TRUE),
array('frànçAIS is über-åwesome', 17, 'frànçAIS is über…', FALSE, TRUE),
array('123', 1, '…', TRUE, TRUE),
array('123', 2, '1…', TRUE, TRUE),
array('123', 3, '123', TRUE, TRUE),
array('1234', 3, '12…', TRUE, TRUE),
array('1234567890', 10, '1234567890', TRUE, TRUE),
array('12345678901', 10, '123456789…', TRUE, TRUE),
array('12345678901', 11, '12345678901', TRUE, TRUE),
array('123456789012', 11, '1234567890…', TRUE, TRUE),
array('12345 7890', 10, '12345 7890', TRUE, TRUE),
array('12345 7890', 9, '12345…', TRUE, TRUE),
array('123 567 90', 10, '123 567 90', TRUE, TRUE),
array('123 567 901', 10, '123 567…', TRUE, TRUE),
array('Stop. Hammertime.', 17, 'Stop. Hammertime.', TRUE, TRUE),
array('Stop. Hammertime.', 16, 'Stop…', TRUE, TRUE),
array('frànçAIS is über-åwesome', 24, 'frànçAIS is über-åwesome', TRUE, TRUE),
array('frànçAIS is über-åwesome', 23, 'frànçAIS is über…', TRUE, TRUE),
array('frànçAIS is über-åwesome', 17, 'frànçAIS is über…', TRUE, TRUE),
array('¿Dónde está el niño?', 20, '¿Dónde está el niño?', TRUE, TRUE),
array('¿Dónde está el niño?', 19, '¿Dónde está el…', TRUE, TRUE),
array('¿Dónde está el niño?', 13, '¿Dónde está…', TRUE, TRUE),
array('¿Dónde está el niño?', 10, '¿Dónde…', TRUE, TRUE),
array('Help! Help! Help!', 17, 'Help! Help! Help!', TRUE, TRUE),
array('Help! Help! Help!', 16, 'Help! Help!…', TRUE, TRUE),
array('Help! Help! Help!', 15, 'Help! Help!…', TRUE, TRUE),
array('Help! Help! Help!', 14, 'Help! Help!…', TRUE, TRUE),
array('Help! Help! Help!', 13, 'Help! Help!…', TRUE, TRUE),
array('Help! Help! Help!', 12, 'Help! Help!…', TRUE, TRUE),
array('Help! Help! Help!', 11, 'Help! Help…', TRUE, TRUE),
array('Help! Help! Help!', 10, 'Help!…', TRUE, TRUE),
array('Help! Help! Help!', 9, 'Help!…', TRUE, TRUE),
array('Help! Help! Help!', 8, 'Help!…', TRUE, TRUE),
array('Help! Help! Help!', 7, 'Help!…', TRUE, TRUE),
array('Help! Help! Help!', 6, 'Help!…', TRUE, TRUE),
array('Help! Help! Help!', 5, 'Help…', TRUE, TRUE),
array('Help! Help! Help!', 4, 'Hel…', TRUE, TRUE),
array('Help! Help! Help!', 3, 'He…', TRUE, TRUE),
array('Help! Help! Help!', 2, 'H…', TRUE, TRUE),
);
return [
['frànçAIS is über-åwesome', 24, 'frànçAIS is über-åwesome'],
['frànçAIS is über-åwesome', 23, 'frànçAIS is über-åwesom'],
['frànçAIS is über-åwesome', 17, 'frànçAIS is über-'],
['以呂波耳・ほへとち。リヌルヲ。', 6, '以呂波耳・ほ'],
['frànçAIS is über-åwesome', 24, 'frànçAIS is über-åwesome', FALSE, TRUE],
['frànçAIS is über-åwesome', 23, 'frànçAIS is über-åweso…', FALSE, TRUE],
['frànçAIS is über-åwesome', 17, 'frànçAIS is über…', FALSE, TRUE],
['123', 1, '…', TRUE, TRUE],
['123', 2, '1…', TRUE, TRUE],
['123', 3, '123', TRUE, TRUE],
['1234', 3, '12…', TRUE, TRUE],
['1234567890', 10, '1234567890', TRUE, TRUE],
['12345678901', 10, '123456789…', TRUE, TRUE],
['12345678901', 11, '12345678901', TRUE, TRUE],
['123456789012', 11, '1234567890…', TRUE, TRUE],
['12345 7890', 10, '12345 7890', TRUE, TRUE],
['12345 7890', 9, '12345…', TRUE, TRUE],
['123 567 90', 10, '123 567 90', TRUE, TRUE],
['123 567 901', 10, '123 567…', TRUE, TRUE],
['Stop. Hammertime.', 17, 'Stop. Hammertime.', TRUE, TRUE],
['Stop. Hammertime.', 16, 'Stop…', TRUE, TRUE],
['frànçAIS is über-åwesome', 24, 'frànçAIS is über-åwesome', TRUE, TRUE],
['frànçAIS is über-åwesome', 23, 'frànçAIS is über…', TRUE, TRUE],
['frànçAIS is über-åwesome', 17, 'frànçAIS is über…', TRUE, TRUE],
['¿Dónde está el niño?', 20, '¿Dónde está el niño?', TRUE, TRUE],
['¿Dónde está el niño?', 19, '¿Dónde está el…', TRUE, TRUE],
['¿Dónde está el niño?', 13, '¿Dónde está…', TRUE, TRUE],
['¿Dónde está el niño?', 10, '¿Dónde…', TRUE, TRUE],
['Help! Help! Help!', 17, 'Help! Help! Help!', TRUE, TRUE],
['Help! Help! Help!', 16, 'Help! Help!…', TRUE, TRUE],
['Help! Help! Help!', 15, 'Help! Help!…', TRUE, TRUE],
['Help! Help! Help!', 14, 'Help! Help!…', TRUE, TRUE],
['Help! Help! Help!', 13, 'Help! Help!…', TRUE, TRUE],
['Help! Help! Help!', 12, 'Help! Help!…', TRUE, TRUE],
['Help! Help! Help!', 11, 'Help! Help…', TRUE, TRUE],
['Help! Help! Help!', 10, 'Help!…', TRUE, TRUE],
['Help! Help! Help!', 9, 'Help!…', TRUE, TRUE],
['Help! Help! Help!', 8, 'Help!…', TRUE, TRUE],
['Help! Help! Help!', 7, 'Help!…', TRUE, TRUE],
['Help! Help! Help!', 6, 'Help!…', TRUE, TRUE],
['Help! Help! Help!', 5, 'Help…', TRUE, TRUE],
['Help! Help! Help!', 4, 'Hel…', TRUE, TRUE],
['Help! Help! Help!', 3, 'He…', TRUE, TRUE],
['Help! Help! Help!', 2, 'H…', TRUE, TRUE],
];
}
/**
@ -444,14 +444,14 @@ class UnicodeTest extends UnitTestCase {
* self::testTruncateBytes().
*/
public function providerTestTruncateBytes() {
return array(
return [
// String shorter than max length.
array('Short string', 42, 'Short string'),
['Short string', 42, 'Short string'],
// Simple string longer than max length.
array('Longer string than previous.', 10, 'Longer str'),
['Longer string than previous.', 10, 'Longer str'],
// Unicode.
array('以呂波耳・ほへとち。リヌルヲ。', 10, '以呂波'),
);
['以呂波耳・ほへとち。リヌルヲ。', 10, '以呂波'],
];
}
/**
@ -481,16 +481,16 @@ class UnicodeTest extends UnitTestCase {
* self::testValidateUtf8().
*/
public function providerTestValidateUtf8() {
return array(
return [
// Empty string.
array('', TRUE, 'An empty string did not validate.'),
['', TRUE, 'An empty string did not validate.'],
// Simple text string.
array('Simple text.', TRUE, 'A simple ASCII text string did not validate.'),
['Simple text.', TRUE, 'A simple ASCII text string did not validate.'],
// Invalid UTF-8, overlong 5 byte encoding.
array(chr(0xF8) . chr(0x80) . chr(0x80) . chr(0x80) . chr(0x80), FALSE, 'Invalid UTF-8 was validated.'),
[chr(0xF8) . chr(0x80) . chr(0x80) . chr(0x80) . chr(0x80), FALSE, 'Invalid UTF-8 was validated.'],
// High code-point without trailing characters.
array(chr(0xD0) . chr(0x01), FALSE, 'Invalid UTF-8 was validated.'),
);
[chr(0xD0) . chr(0x01), FALSE, 'Invalid UTF-8 was validated.'],
];
}
/**
@ -518,11 +518,11 @@ class UnicodeTest extends UnitTestCase {
* self::testConvertUtf8(). }
*/
public function providerTestConvertToUtf8() {
return array(
array(chr(0x97), 'Windows-1252', '—'),
array(chr(0x99), 'Windows-1252', '™'),
array(chr(0x80), 'Windows-1252', '€'),
);
return [
[chr(0x97), 'Windows-1252', '—'],
[chr(0x99), 'Windows-1252', '™'],
[chr(0x80), 'Windows-1252', '€'],
];
}
/**
@ -553,18 +553,18 @@ class UnicodeTest extends UnitTestCase {
* - The expected integer/FALSE result.
*/
public function providerStrpos() {
return array(
array('frànçAIS is über-åwesome', 'frànçAIS is über-åwesome', 0, 0),
array('frànçAIS is über-åwesome', 'rànçAIS is über-åwesome', 0, 1),
array('frànçAIS is über-åwesome', 'not in string', 0, FALSE),
array('frànçAIS is über-åwesome', 'r', 0, 1),
array('frànçAIS is über-åwesome', 'nçAIS', 0, 3),
array('frànçAIS is über-åwesome', 'nçAIS', 2, 3),
array('frànçAIS is über-åwesome', 'nçAIS', 3, 3),
array('以呂波耳・ほへとち。リヌルヲ。', '波耳', 0, 2),
array('以呂波耳・ほへとち。リヌルヲ。', '波耳', 1, 2),
array('以呂波耳・ほへとち。リヌルヲ。', '波耳', 2, 2),
);
return [
['frànçAIS is über-åwesome', 'frànçAIS is über-åwesome', 0, 0],
['frànçAIS is über-åwesome', 'rànçAIS is über-åwesome', 0, 1],
['frànçAIS is über-åwesome', 'not in string', 0, FALSE],
['frànçAIS is über-åwesome', 'r', 0, 1],
['frànçAIS is über-åwesome', 'nçAIS', 0, 3],
['frànçAIS is über-åwesome', 'nçAIS', 2, 3],
['frànçAIS is über-åwesome', 'nçAIS', 3, 3],
['以呂波耳・ほへとち。リヌルヲ。', '波耳', 0, 2],
['以呂波耳・ほへとち。リヌルヲ。', '波耳', 1, 2],
['以呂波耳・ほへとち。リヌルヲ。', '波耳', 2, 2],
];
}
}

View file

@ -18,13 +18,13 @@ class UrlHelperTest extends UnitTestCase {
* @return array
*/
public function providerTestBuildQuery() {
return array(
array(array('a' => ' &#//+%20@۞'), 'a=%20%26%23//%2B%2520%40%DB%9E', 'Value was properly encoded.'),
array(array(' &#//+%20@۞' => 'a'), '%20%26%23%2F%2F%2B%2520%40%DB%9E=a', 'Key was properly encoded.'),
array(array('a' => '1', 'b' => '2', 'c' => '3'), 'a=1&b=2&c=3', 'Multiple values were properly concatenated.'),
array(array('a' => array('b' => '2', 'c' => '3'), 'd' => 'foo'), 'a[b]=2&a[c]=3&d=foo', 'Nested array was properly encoded.'),
array(array('foo' => NULL), 'foo', 'Simple parameters are properly added.'),
);
return [
[['a' => ' &#//+%20@۞'], 'a=%20%26%23//%2B%2520%40%DB%9E', 'Value was properly encoded.'],
[[' &#//+%20@۞' => 'a'], '%20%26%23%2F%2F%2B%2520%40%DB%9E=a', 'Key was properly encoded.'],
[['a' => '1', 'b' => '2', 'c' => '3'], 'a=1&b=2&c=3', 'Multiple values were properly concatenated.'],
[['a' => ['b' => '2', 'c' => '3'], 'd' => 'foo'], 'a[b]=2&a[c]=3&d=foo', 'Nested array was properly encoded.'],
[['foo' => NULL], 'foo', 'Simple parameters are properly added.'],
];
}
/**
@ -50,7 +50,7 @@ class UrlHelperTest extends UnitTestCase {
* @return array
*/
public function providerTestValidAbsoluteData() {
$urls = array(
$urls = [
'example.com',
'www.example.com',
'ex-ample.com',
@ -69,7 +69,7 @@ class UrlHelperTest extends UnitTestCase {
'example.org/~,$\'*;',
'caf%C3%A9.example.org',
'[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html',
);
];
return $this->dataEnhanceWithScheme($urls);
}
@ -97,11 +97,11 @@ class UrlHelperTest extends UnitTestCase {
* @return array
*/
public function providerTestInvalidAbsolute() {
$data = array(
$data = [
'',
'ex!ample.com',
'ex%ample.com',
);
];
return $this->dataEnhanceWithScheme($data);
}
@ -128,13 +128,13 @@ class UrlHelperTest extends UnitTestCase {
* @return array
*/
public function providerTestValidRelativeData() {
$data = array(
$data = [
'paren(the)sis',
'index.html#pagetop',
'index.php/node',
'index.php/node?param=false',
'login.php?do=login&style=%23#pagetop',
);
];
return $this->dataEnhanceWithPrefix($data);
}
@ -162,11 +162,11 @@ class UrlHelperTest extends UnitTestCase {
* @return array
*/
public function providerTestInvalidRelativeData() {
$data = array(
$data = [
'ex^mple',
'example<>',
'ex%ample',
);
];
return $this->dataEnhanceWithPrefix($data);
}
@ -212,20 +212,20 @@ class UrlHelperTest extends UnitTestCase {
* @return array
*/
public static function providerTestFilterQueryParameters() {
return array(
return [
// Test without an exclude filter.
array(
'query' => array('a' => array('b' => 'c')),
'exclude' => array(),
'expected' => array('a' => array('b' => 'c')),
),
[
'query' => ['a' => ['b' => 'c']],
'exclude' => [],
'expected' => ['a' => ['b' => 'c']],
],
// Exclude the 'b' element.
array(
'query' => array('a' => array('b' => 'c', 'd' => 'e')),
'exclude' => array('a[b]'),
'expected' => array('a' => array('d' => 'e')),
),
);
[
'query' => ['a' => ['b' => 'c', 'd' => 'e']],
'exclude' => ['a[b]'],
'expected' => ['a' => ['d' => 'e']],
],
];
}
/**
@ -250,52 +250,52 @@ class UrlHelperTest extends UnitTestCase {
* @return array
*/
public static function providerTestParse() {
return array(
array(
return [
[
'http://www.example.com/my/path',
array(
[
'path' => 'http://www.example.com/my/path',
'query' => array(),
'query' => [],
'fragment' => '',
),
),
array(
],
],
[
'http://www.example.com/my/path?destination=home#footer',
array(
[
'path' => 'http://www.example.com/my/path',
'query' => array(
'query' => [
'destination' => 'home',
),
],
'fragment' => 'footer',
),
),
array(
],
],
[
'http://',
array(
[
'path' => '',
'query' => array(),
'query' => [],
'fragment' => '',
),
),
array(
],
],
[
'https://',
array(
[
'path' => '',
'query' => array(),
'query' => [],
'fragment' => '',
),
),
array(
],
],
[
'/my/path?destination=home#footer',
array(
[
'path' => '/my/path',
'query' => array(
'query' => [
'destination' => 'home',
),
],
'fragment' => 'footer',
),
),
);
],
],
];
}
/**
@ -320,10 +320,10 @@ class UrlHelperTest extends UnitTestCase {
* @return array
*/
public static function providerTestEncodePath() {
return array(
array('unencoded path with spaces', 'unencoded%20path%20with%20spaces'),
array('slashes/should/be/preserved', 'slashes/should/be/preserved'),
);
return [
['unencoded path with spaces', 'unencoded%20path%20with%20spaces'],
['slashes/should/be/preserved', 'slashes/should/be/preserved'],
];
}
/**
@ -348,39 +348,39 @@ class UrlHelperTest extends UnitTestCase {
* @return array
*/
public static function providerTestIsExternal() {
return array(
array('/internal/path', FALSE),
array('https://example.com/external/path', TRUE),
array('javascript://fake-external-path', FALSE),
return [
['/internal/path', FALSE],
['https://example.com/external/path', TRUE],
['javascript://fake-external-path', FALSE],
// External URL without an explicit protocol.
array('//www.drupal.org/foo/bar?foo=bar&bar=baz&baz#foo', TRUE),
['//www.drupal.org/foo/bar?foo=bar&bar=baz&baz#foo', TRUE],
// Internal URL starting with a slash.
array('/www.drupal.org', FALSE),
['/www.drupal.org', FALSE],
// Simple external URLs.
array('http://example.com', TRUE),
array('https://example.com', TRUE),
array('http://drupal.org/foo/bar?foo=bar&bar=baz&baz#foo', TRUE),
array('//drupal.org', TRUE),
['http://example.com', TRUE],
['https://example.com', TRUE],
['http://drupal.org/foo/bar?foo=bar&bar=baz&baz#foo', TRUE],
['//drupal.org', TRUE],
// Some browsers ignore or strip leading control characters.
array("\x00//www.example.com", TRUE),
array("\x08//www.example.com", TRUE),
array("\x1F//www.example.com", TRUE),
array("\n//www.example.com", TRUE),
["\x00//www.example.com", TRUE],
["\x08//www.example.com", TRUE],
["\x1F//www.example.com", TRUE],
["\n//www.example.com", TRUE],
// JSON supports decoding directly from UTF-8 code points.
array(json_decode('"\u00AD"') . "//www.example.com", TRUE),
array(json_decode('"\u200E"') . "//www.example.com", TRUE),
array(json_decode('"\uE0020"') . "//www.example.com", TRUE),
array(json_decode('"\uE000"') . "//www.example.com", TRUE),
[json_decode('"\u00AD"') . "//www.example.com", TRUE],
[json_decode('"\u200E"') . "//www.example.com", TRUE],
[json_decode('"\uE0020"') . "//www.example.com", TRUE],
[json_decode('"\uE000"') . "//www.example.com", TRUE],
// Backslashes should be normalized to forward.
array('\\\\example.com', TRUE),
['\\\\example.com', TRUE],
// Local URLs.
array('node', FALSE),
array('/system/ajax', FALSE),
array('?q=foo:bar', FALSE),
array('node/edit:me', FALSE),
array('/drupal.org', FALSE),
array('<front>', FALSE),
);
['node', FALSE],
['/system/ajax', FALSE],
['?q=foo:bar', FALSE],
['node/edit:me', FALSE],
['/drupal.org', FALSE],
['<front>', FALSE],
];
}
/**
@ -411,15 +411,15 @@ class UrlHelperTest extends UnitTestCase {
* @return array
*/
public static function providerTestFilterBadProtocol() {
return array(
array('javascript://example.com?foo&bar', '//example.com?foo&amp;bar', array('http', 'https')),
return [
['javascript://example.com?foo&bar', '//example.com?foo&amp;bar', ['http', 'https']],
// Test custom protocols.
array('http://example.com?foo&bar', '//example.com?foo&amp;bar', array('https')),
['http://example.com?foo&bar', '//example.com?foo&amp;bar', ['https']],
// Valid protocol.
array('http://example.com?foo&bar', 'http://example.com?foo&amp;bar', array('https', 'http')),
['http://example.com?foo&bar', 'http://example.com?foo&amp;bar', ['https', 'http']],
// Colon not part of the URL scheme.
array('/test:8888?foo&bar', '/test:8888?foo&amp;bar', array('http')),
);
['/test:8888?foo&bar', '/test:8888?foo&amp;bar', ['http']],
];
}
/**
@ -448,15 +448,15 @@ class UrlHelperTest extends UnitTestCase {
* @return array
*/
public static function providerTestStripDangerousProtocols() {
return array(
array('javascript://example.com', '//example.com', array('http', 'https')),
return [
['javascript://example.com', '//example.com', ['http', 'https']],
// Test custom protocols.
array('http://example.com', '//example.com', array('https')),
['http://example.com', '//example.com', ['https']],
// Valid protocol.
array('http://example.com', 'http://example.com', array('https', 'http')),
['http://example.com', 'http://example.com', ['https', 'http']],
// Colon not part of the URL scheme.
array('/test:8888', '/test:8888', array('http')),
);
['/test:8888', '/test:8888', ['http']],
];
}
/**
@ -469,11 +469,11 @@ class UrlHelperTest extends UnitTestCase {
* A list of provider data with schemes.
*/
protected function dataEnhanceWithScheme(array $urls) {
$url_schemes = array('http', 'https', 'ftp');
$data = array();
$url_schemes = ['http', 'https', 'ftp'];
$data = [];
foreach ($url_schemes as $scheme) {
foreach ($urls as $url) {
$data[] = array($url, $scheme);
$data[] = [$url, $scheme];
}
}
return $data;
@ -489,11 +489,11 @@ class UrlHelperTest extends UnitTestCase {
* A list of provider data with prefixes.
*/
protected function dataEnhanceWithPrefix(array $urls) {
$prefixes = array('', '/');
$data = array();
$prefixes = ['', '/'];
$data = [];
foreach ($prefixes as $prefix) {
foreach ($urls as $url) {
$data[] = array($url, $prefix);
$data[] = [$url, $prefix];
}
}
return $data;
@ -523,31 +523,31 @@ class UrlHelperTest extends UnitTestCase {
* @see \Drupal\Tests\Component\Utility\UrlHelperTest::testExternalIsLocal()
*/
public function providerTestExternalIsLocal() {
return array(
return [
// Different mixes of trailing slash.
array('http://example.com', 'http://example.com', TRUE),
array('http://example.com/', 'http://example.com', TRUE),
array('http://example.com', 'http://example.com/', TRUE),
array('http://example.com/', 'http://example.com/', TRUE),
['http://example.com', 'http://example.com', TRUE],
['http://example.com/', 'http://example.com', TRUE],
['http://example.com', 'http://example.com/', TRUE],
['http://example.com/', 'http://example.com/', TRUE],
// Sub directory of site.
array('http://example.com/foo', 'http://example.com/', TRUE),
array('http://example.com/foo/bar', 'http://example.com/foo', TRUE),
array('http://example.com/foo/bar', 'http://example.com/foo/', TRUE),
['http://example.com/foo', 'http://example.com/', TRUE],
['http://example.com/foo/bar', 'http://example.com/foo', TRUE],
['http://example.com/foo/bar', 'http://example.com/foo/', TRUE],
// Different sub-domain.
array('http://example.com', 'http://www.example.com/', FALSE),
array('http://example.com/', 'http://www.example.com/', FALSE),
array('http://example.com/foo', 'http://www.example.com/', FALSE),
['http://example.com', 'http://www.example.com/', FALSE],
['http://example.com/', 'http://www.example.com/', FALSE],
['http://example.com/foo', 'http://www.example.com/', FALSE],
// Different TLD.
array('http://example.com', 'http://example.ca', FALSE),
array('http://example.com', 'http://example.ca/', FALSE),
array('http://example.com/', 'http://example.ca/', FALSE),
array('http://example.com/foo', 'http://example.ca', FALSE),
array('http://example.com/foo', 'http://example.ca/', FALSE),
['http://example.com', 'http://example.ca', FALSE],
['http://example.com', 'http://example.ca/', FALSE],
['http://example.com/', 'http://example.ca/', FALSE],
['http://example.com/foo', 'http://example.ca', FALSE],
['http://example.com/foo', 'http://example.ca/', FALSE],
// Different site path.
array('http://example.com/foo', 'http://example.com/bar', FALSE),
array('http://example.com', 'http://example.com/bar', FALSE),
array('http://example.com/bar', 'http://example.com/bar/', FALSE),
);
['http://example.com/foo', 'http://example.com/bar', FALSE],
['http://example.com', 'http://example.com/bar', FALSE],
['http://example.com/bar', 'http://example.com/bar/', FALSE],
];
}
/**
@ -560,9 +560,9 @@ class UrlHelperTest extends UnitTestCase {
*
* @covers ::externalIsLocal
* @dataProvider providerTestExternalIsLocalInvalid
* @expectedException \InvalidArgumentException
*/
public function testExternalIsLocalInvalid($url, $base_url) {
$this->setExpectedException(\InvalidArgumentException::class);
UrlHelper::externalIsLocal($url, $base_url);
}
@ -572,17 +572,17 @@ class UrlHelperTest extends UnitTestCase {
* @see \Drupal\Tests\Component\Utility\UrlHelperTest::testExternalIsLocalInvalid()
*/
public function providerTestExternalIsLocalInvalid() {
return array(
array('http://example.com/foo', ''),
array('http://example.com/foo', 'bar'),
array('http://example.com/foo', 'http://'),
return [
['http://example.com/foo', ''],
['http://example.com/foo', 'bar'],
['http://example.com/foo', 'http://'],
// Invalid destination urls.
array('', 'http://example.com/foo'),
array('bar', 'http://example.com/foo'),
array('/bar', 'http://example.com/foo'),
array('bar/', 'http://example.com/foo'),
array('http://', 'http://example.com/foo'),
);
['', 'http://example.com/foo'],
['bar', 'http://example.com/foo'],
['/bar', 'http://example.com/foo'],
['bar/', 'http://example.com/foo'],
['http://', 'http://example.com/foo'],
];
}
}

View file

@ -21,7 +21,7 @@ class UserAgentTest extends UnitTestCase {
* Language codes, ordered by priority.
*/
protected function getLanguages() {
return array(
return [
// In our test case, 'en' has priority over 'en-US'.
'en',
'en-US',
@ -39,7 +39,7 @@ class UserAgentTest extends UnitTestCase {
'zh-hans',
'zh-hant',
'zh-hant-tw',
);
];
}
/**
@ -49,7 +49,7 @@ class UserAgentTest extends UnitTestCase {
* Language mappings.
*/
protected function getMappings() {
return array(
return [
'no' => 'nb',
'pt' => 'pt-pt',
'zh' => 'zh-hans',
@ -60,7 +60,7 @@ class UserAgentTest extends UnitTestCase {
'zh-cn' => 'zh-hans',
'zh-sg' => 'zh-hans',
'zh-chs' => 'zh-hans',
);
];
}
/**
@ -82,86 +82,86 @@ class UserAgentTest extends UnitTestCase {
* - Expected best matching language code.
*/
public function providerTestGetBestMatchingLangcode() {
return array(
return [
// Equal qvalue for each language, choose the site preferred one.
array('en,en-US,fr-CA,fr,es-MX', 'en'),
array('en-US,en,fr-CA,fr,es-MX', 'en'),
array('fr,en', 'en'),
array('en,fr', 'en'),
array('en-US,fr', 'en-US'),
array('fr,en-US', 'en-US'),
array('fr,fr-CA', 'fr-CA'),
array('fr-CA,fr', 'fr-CA'),
array('fr', 'fr-CA'),
array('fr;q=1', 'fr-CA'),
array('fr,es-MX', 'fr-CA'),
array('fr,es', 'fr-CA'),
array('es,fr', 'fr-CA'),
array('es-MX,de', 'es-MX'),
array('de,es-MX', 'es-MX'),
['en,en-US,fr-CA,fr,es-MX', 'en'],
['en-US,en,fr-CA,fr,es-MX', 'en'],
['fr,en', 'en'],
['en,fr', 'en'],
['en-US,fr', 'en-US'],
['fr,en-US', 'en-US'],
['fr,fr-CA', 'fr-CA'],
['fr-CA,fr', 'fr-CA'],
['fr', 'fr-CA'],
['fr;q=1', 'fr-CA'],
['fr,es-MX', 'fr-CA'],
['fr,es', 'fr-CA'],
['es,fr', 'fr-CA'],
['es-MX,de', 'es-MX'],
['de,es-MX', 'es-MX'],
// Different cases and whitespace.
array('en', 'en'),
array('En', 'en'),
array('EN', 'en'),
array(' en', 'en'),
array('en ', 'en'),
array('en, fr', 'en'),
['en', 'en'],
['En', 'en'],
['EN', 'en'],
[' en', 'en'],
['en ', 'en'],
['en, fr', 'en'],
// A less specific language from the browser matches a more specific one
// from the website, and the other way around for compatibility with
// some versions of Internet Explorer.
array('es', 'es-MX'),
array('es-MX', 'es-MX'),
array('pt', 'pt'),
array('pt-PT', 'pt'),
array('pt-PT;q=0.5,pt-BR;q=1,en;q=0.7', 'en'),
array('pt-PT;q=1,pt-BR;q=0.5,en;q=0.7', 'en'),
array('pt-PT;q=0.4,pt-BR;q=0.1,en;q=0.7', 'en'),
array('pt-PT;q=0.1,pt-BR;q=0.4,en;q=0.7', 'en'),
['es', 'es-MX'],
['es-MX', 'es-MX'],
['pt', 'pt'],
['pt-PT', 'pt'],
['pt-PT;q=0.5,pt-BR;q=1,en;q=0.7', 'en'],
['pt-PT;q=1,pt-BR;q=0.5,en;q=0.7', 'en'],
['pt-PT;q=0.4,pt-BR;q=0.1,en;q=0.7', 'en'],
['pt-PT;q=0.1,pt-BR;q=0.4,en;q=0.7', 'en'],
// Language code with several dashes are valid. The less specific language
// from the browser matches the more specific one from the website.
array('eh-oh-laa-laa', 'eh-oh-laa-laa'),
array('eh-oh-laa', 'eh-oh-laa-laa'),
array('eh-oh', 'eh-oh-laa-laa'),
array('eh', 'eh-oh-laa-laa'),
['eh-oh-laa-laa', 'eh-oh-laa-laa'],
['eh-oh-laa', 'eh-oh-laa-laa'],
['eh-oh', 'eh-oh-laa-laa'],
['eh', 'eh-oh-laa-laa'],
// Different qvalues.
array('fr,en;q=0.5', 'fr-CA'),
array('fr,en;q=0.5,fr-CA;q=0.25', 'fr'),
['fr,en;q=0.5', 'fr-CA'],
['fr,en;q=0.5,fr-CA;q=0.25', 'fr'],
// Silly wildcards are also valid.
array('*,fr-CA;q=0.5', 'en'),
array('*,en;q=0.25', 'fr-CA'),
array('en,en-US;q=0.5,fr;q=0.25', 'en'),
array('en-US,en;q=0.5,fr;q=0.25', 'en-US'),
['*,fr-CA;q=0.5', 'en'],
['*,en;q=0.25', 'fr-CA'],
['en,en-US;q=0.5,fr;q=0.25', 'en'],
['en-US,en;q=0.5,fr;q=0.25', 'en-US'],
// Unresolvable cases.
array('', FALSE),
array('de,pl', FALSE),
array('iecRswK4eh', FALSE),
array($this->randomMachineName(10), FALSE),
['', FALSE],
['de,pl', FALSE],
['iecRswK4eh', FALSE],
[$this->randomMachineName(10), FALSE],
// Chinese langcodes.
array('zh-cn, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hans'),
array('zh-tw, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hant'),
array('zh-hant, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hant'),
array('zh-hans, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hans'),
['zh-cn, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hans'],
['zh-tw, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hant'],
['zh-hant, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hant'],
['zh-hans, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hans'],
// @todo: This is copied from RFC4647 but our regex skips the numbers so
// they where removed. Our code should be updated so private1-private2 is
// valid. http://tools.ietf.org/html/rfc4647#section-3.4
array('zh-hant-CN-x-private-private, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hant'),
array('zh-cn', 'zh-hans'),
array('zh-sg', 'zh-hans'),
array('zh-tw', 'zh-hant'),
array('zh-hk', 'zh-hant'),
array('zh-mo', 'zh-hant'),
array('zh-hans', 'zh-hans'),
array('zh-hant', 'zh-hant'),
array('zh-chs', 'zh-hans'),
array('zh-cht', 'zh-hant'),
);
['zh-hant-CN-x-private-private, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hant'],
['zh-cn', 'zh-hans'],
['zh-sg', 'zh-hans'],
['zh-tw', 'zh-hant'],
['zh-hk', 'zh-hant'],
['zh-mo', 'zh-hant'],
['zh-hans', 'zh-hans'],
['zh-hant', 'zh-hant'],
['zh-chs', 'zh-hans'],
['zh-cht', 'zh-hant'],
];
}
}

View file

@ -29,72 +29,72 @@ class VariableTest extends UnitTestCase {
* - The variable to export.
*/
public function providerTestExport() {
return array(
return [
// Array.
array(
[
'array()',
array(),
),
array(
[],
],
[
// non-associative.
"array(\n 1,\n 2,\n 3,\n 4,\n)",
array(1, 2, 3, 4),
),
array(
[1, 2, 3, 4],
],
[
// associative.
"array(\n 'a' => 1,\n)",
array('a' => 1),
),
['a' => 1],
],
// Bool.
array(
[
'TRUE',
TRUE,
),
array(
],
[
'FALSE',
FALSE,
),
],
// Strings.
array(
[
"'string'",
'string',
),
array(
],
[
'"\n\r\t"',
"\n\r\t",
),
array(
],
[
// 2 backslashes. \\
"'\\'",
'\\',
),
array(
],
[
// Double-quote "
"'\"'",
"\"",
),
array(
],
[
// Single-quote '
'"\'"',
"'",
),
array(
],
[
// Quotes with $ symbols.
'"\$settings[\'foo\']"',
'$settings[\'foo\']',
),
],
// Object.
array(
[
// A stdClass object.
'(object) array()',
new \stdClass(),
),
array(
],
[
// A not-stdClass object.
"Drupal\Tests\Component\Utility\StubVariableTestClass::__set_state(array(\n))",
new StubVariableTestClass(),
),
);
],
];
}
/**

View file

@ -28,7 +28,7 @@ class XssTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
$allowed_protocols = array(
$allowed_protocols = [
'http',
'https',
'ftp',
@ -41,7 +41,7 @@ class XssTest extends UnitTestCase {
'sftp',
'webcal',
'rtsp',
);
];
UrlHelper::setAllowedProtocols($allowed_protocols);
}
@ -86,30 +86,30 @@ class XssTest extends UnitTestCase {
* \Drupal\Component\Utility\Xss::filter().
*/
public function providerTestFilterXssNormalized() {
return array(
array(
return [
[
"Who&#039;s Online",
"who's online",
'HTML filter -- html entity number',
),
array(
],
[
"Who&amp;#039;s Online",
"who&#039;s online",
'HTML filter -- encoded html entity number',
),
array(
],
[
"Who&amp;amp;#039; Online",
"who&amp;#039; online",
'HTML filter -- double encoded html entity number',
),
],
// Custom elements with dashes in the tag name.
array(
[
"<test-element></test-element>",
"<test-element></test-element>",
'Custom element with dashes in tag name.',
array('test-element'),
),
);
['test-element'],
],
];
}
/**
@ -153,289 +153,289 @@ class XssTest extends UnitTestCase {
* \Drupal\Component\Utility\Xss::filter().
*/
public function providerTestFilterXssNotNormalized() {
$cases = array(
$cases = [
// Tag stripping, different ways to work around removal of HTML tags.
array(
[
'<script>alert(0)</script>',
'script',
'HTML tag stripping -- simple script without special characters.',
),
array(
],
[
'<script src="http://www.example.com" />',
'script',
'HTML tag stripping -- empty script with source.',
),
array(
],
[
'<ScRipt sRc=http://www.example.com/>',
'script',
'HTML tag stripping evasion -- varying case.',
),
array(
],
[
"<script\nsrc\n=\nhttp://www.example.com/\n>",
'script',
'HTML tag stripping evasion -- multiline tag.',
),
array(
],
[
'<script/a src=http://www.example.com/a.js></script>',
'script',
'HTML tag stripping evasion -- non whitespace character after tag name.',
),
array(
],
[
'<script/src=http://www.example.com/a.js></script>',
'script',
'HTML tag stripping evasion -- no space between tag and attribute.',
),
],
// Null between < and tag name works at least with IE6.
array(
[
"<\0scr\0ipt>alert(0)</script>",
'ipt',
'HTML tag stripping evasion -- breaking HTML with nulls.',
),
array(
],
[
"<scrscriptipt src=http://www.example.com/a.js>",
'script',
'HTML tag stripping evasion -- filter just removing "script".',
),
array(
],
[
'<<script>alert(0);//<</script>',
'script',
'HTML tag stripping evasion -- double opening brackets.',
),
array(
],
[
'<script src=http://www.example.com/a.js?<b>',
'script',
'HTML tag stripping evasion -- no closing tag.',
),
],
// DRUPAL-SA-2008-047: This doesn't seem exploitable, but the filter should
// work consistently.
array(
[
'<script>>',
'script',
'HTML tag stripping evasion -- double closing tag.',
),
array(
],
[
'<script src=//www.example.com/.a>',
'script',
'HTML tag stripping evasion -- no scheme or ending slash.',
),
array(
],
[
'<script src=http://www.example.com/.a',
'script',
'HTML tag stripping evasion -- no closing bracket.',
),
array(
],
[
'<script src=http://www.example.com/ <',
'script',
'HTML tag stripping evasion -- opening instead of closing bracket.',
),
array(
],
[
'<nosuchtag attribute="newScriptInjectionVector">',
'nosuchtag',
'HTML tag stripping evasion -- unknown tag.',
),
array(
],
[
'<t:set attributeName="innerHTML" to="&lt;script defer&gt;alert(0)&lt;/script&gt;">',
't:set',
'HTML tag stripping evasion -- colon in the tag name (namespaces\' tricks).',
),
array(
],
[
'<img """><script>alert(0)</script>',
'script',
'HTML tag stripping evasion -- a malformed image tag.',
array('img'),
),
array(
['img'],
],
[
'<blockquote><script>alert(0)</script></blockquote>',
'script',
'HTML tag stripping evasion -- script in a blockqoute.',
array('blockquote'),
),
array(
['blockquote'],
],
[
"<!--[if true]><script>alert(0)</script><![endif]-->",
'script',
'HTML tag stripping evasion -- script within a comment.',
),
],
// Dangerous attributes removal.
array(
[
'<p onmouseover="http://www.example.com/">',
'onmouseover',
'HTML filter attributes removal -- events, no evasion.',
array('p'),
),
array(
['p'],
],
[
'<li style="list-style-image: url(javascript:alert(0))">',
'style',
'HTML filter attributes removal -- style, no evasion.',
array('li'),
),
array(
['li'],
],
[
'<img onerror =alert(0)>',
'onerror',
'HTML filter attributes removal evasion -- spaces before equals sign.',
array('img'),
),
array(
['img'],
],
[
'<img onabort!#$%&()*~+-_.,:;?@[/|\]^`=alert(0)>',
'onabort',
'HTML filter attributes removal evasion -- non alphanumeric characters before equals sign.',
array('img'),
),
array(
['img'],
],
[
'<img oNmediAError=alert(0)>',
'onmediaerror',
'HTML filter attributes removal evasion -- varying case.',
array('img'),
),
['img'],
],
// Works at least with IE6.
array(
[
"<img o\0nfocus\0=alert(0)>",
'focus',
'HTML filter attributes removal evasion -- breaking with nulls.',
array('img'),
),
['img'],
],
// Only whitelisted scheme names allowed in attributes.
array(
[
'<img src="javascript:alert(0)">',
'javascript',
'HTML scheme clearing -- no evasion.',
array('img'),
),
array(
['img'],
],
[
'<img src=javascript:alert(0)>',
'javascript',
'HTML scheme clearing evasion -- no quotes.',
array('img'),
),
['img'],
],
// A bit like CVE-2006-0070.
array(
[
'<img src="javascript:confirm(0)">',
'javascript',
'HTML scheme clearing evasion -- no alert ;)',
array('img'),
),
array(
['img'],
],
[
'<img src=`javascript:alert(0)`>',
'javascript',
'HTML scheme clearing evasion -- grave accents.',
array('img'),
),
array(
['img'],
],
[
'<img dynsrc="javascript:alert(0)">',
'javascript',
'HTML scheme clearing -- rare attribute.',
array('img'),
),
array(
['img'],
],
[
'<table background="javascript:alert(0)">',
'javascript',
'HTML scheme clearing -- another tag.',
array('table'),
),
array(
['table'],
],
[
'<base href="javascript:alert(0);//">',
'javascript',
'HTML scheme clearing -- one more attribute and tag.',
array('base'),
),
array(
['base'],
],
[
'<img src="jaVaSCriPt:alert(0)">',
'javascript',
'HTML scheme clearing evasion -- varying case.',
array('img'),
),
array(
['img'],
],
[
'<img src=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#48;&#41;>',
'javascript',
'HTML scheme clearing evasion -- UTF-8 decimal encoding.',
array('img'),
),
array(
['img'],
],
[
'<img src=&#00000106&#0000097&#00000118&#0000097&#00000115&#0000099&#00000114&#00000105&#00000112&#00000116&#0000058&#0000097&#00000108&#00000101&#00000114&#00000116&#0000040&#0000048&#0000041>',
'javascript',
'HTML scheme clearing evasion -- long UTF-8 encoding.',
array('img'),
),
array(
['img'],
],
[
'<img src=&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x30&#x29>',
'javascript',
'HTML scheme clearing evasion -- UTF-8 hex encoding.',
array('img'),
),
array(
['img'],
],
[
"<img src=\"jav\tascript:alert(0)\">",
'script',
'HTML scheme clearing evasion -- an embedded tab.',
array('img'),
),
array(
['img'],
],
[
'<img src="jav&#x09;ascript:alert(0)">',
'script',
'HTML scheme clearing evasion -- an encoded, embedded tab.',
array('img'),
),
array(
['img'],
],
[
'<img src="jav&#x000000A;ascript:alert(0)">',
'script',
'HTML scheme clearing evasion -- an encoded, embedded newline.',
array('img'),
),
['img'],
],
// With &#xD; this test would fail, but the entity gets turned into
// &amp;#xD;, so it's OK.
array(
[
'<img src="jav&#x0D;ascript:alert(0)">',
'script',
'HTML scheme clearing evasion -- an encoded, embedded carriage return.',
array('img'),
),
array(
['img'],
],
[
"<img src=\"\n\n\nj\na\nva\ns\ncript:alert(0)\">",
'cript',
'HTML scheme clearing evasion -- broken into many lines.',
array('img'),
),
array(
['img'],
],
[
"<img src=\"jav\0a\0\0cript:alert(0)\">",
'cript',
'HTML scheme clearing evasion -- embedded nulls.',
array('img'),
),
array(
['img'],
],
[
'<img src="vbscript:msgbox(0)">',
'vbscript',
'HTML scheme clearing evasion -- another scheme.',
array('img'),
),
array(
['img'],
],
[
'<img src="nosuchscheme:notice(0)">',
'nosuchscheme',
'HTML scheme clearing evasion -- unknown scheme.',
array('img'),
),
['img'],
],
// Netscape 4.x javascript entities.
array(
[
'<br size="&{alert(0)}">',
'alert',
'Netscape 4.x javascript entities.',
array('br'),
),
['br'],
],
// DRUPAL-SA-2008-006: Invalid UTF-8, these only work as reflected XSS with
// Internet Explorer 6.
array(
[
"<p arg=\"\xe0\">\" style=\"background-image: url(javascript:alert(0));\"\xe0<p>",
'style',
'HTML filter -- invalid UTF-8.',
array('p'),
),
);
['p'],
],
];
// @fixme This dataset currently fails under 5.4 because of
// https://www.drupal.org/node/1210798. Restore after its fixed.
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
$cases[] = array(
$cases[] = [
'<img src=" &#14; javascript:alert(0)">',
'javascript',
'HTML scheme clearing evasion -- spaces and metacharacters before scheme.',
array('img'),
);
['img'],
];
}
return $cases;
}
@ -468,11 +468,11 @@ class XssTest extends UnitTestCase {
* - The assertion message.
*/
public function providerTestInvalidMultiByte() {
return array(
array("Foo\xC0barbaz", '', 'Xss::filter() accepted invalid sequence "Foo\xC0barbaz"'),
array("Fooÿñ", "Fooÿñ", 'Xss::filter() rejects valid sequence Fooÿñ"'),
array("\xc0aaa", '', 'HTML filter -- overlong UTF-8 sequences.'),
);
return [
["Foo\xC0barbaz", '', 'Xss::filter() accepted invalid sequence "Foo\xC0barbaz"'],
["Fooÿñ", "Fooÿñ", 'Xss::filter() rejects valid sequence Fooÿñ"'],
["\xc0aaa", '', 'HTML filter -- overlong UTF-8 sequences.'],
];
}
/**
@ -498,38 +498,38 @@ class XssTest extends UnitTestCase {
* Data provider for testFilterXssAdminNotNormalized().
*/
public function providerTestAttributes() {
return array(
array(
return [
[
'<img src="http://example.com/foo.jpg" title="Example: title" alt="Example: alt">',
'<img src="http://example.com/foo.jpg" title="Example: title" alt="Example: alt">',
'Image tag with alt and title attribute',
array('img')
),
array(
['img']
],
[
'<a href="https://www.drupal.org/" rel="dc:publisher">Drupal</a>',
'<a href="https://www.drupal.org/" rel="dc:publisher">Drupal</a>',
'Link tag with rel attribute',
array('a')
),
array(
['a']
],
[
'<span property="dc:subject">Drupal 8: The best release ever.</span>',
'<span property="dc:subject">Drupal 8: The best release ever.</span>',
'Span tag with property attribute',
array('span')
),
array(
['span']
],
[
'<img src="http://example.com/foo.jpg" data-caption="Drupal 8: The best release ever.">',
'<img src="http://example.com/foo.jpg" data-caption="Drupal 8: The best release ever.">',
'Image tag with data attribute',
array('img')
),
array(
['img']
],
[
'<a data-a2a-url="foo"></a>',
'<a data-a2a-url="foo"></a>',
'Link tag with numeric data attribute',
array('a')
),
);
['a']
],
];
}
/**
@ -568,11 +568,11 @@ class XssTest extends UnitTestCase {
* - The assertion message.
*/
public function providerTestFilterXssAdminNotNormalized() {
return array(
return [
// DRUPAL-SA-2008-044
array('<object />', 'object', 'Admin HTML filter -- should not allow object tag.'),
array('<script />', 'script', 'Admin HTML filter -- should not allow script tag.'),
);
['<object />', 'object', 'Admin HTML filter -- should not allow object tag.'],
['<script />', 'script', 'Admin HTML filter -- should not allow script tag.'],
];
}
/**

View file

@ -41,7 +41,7 @@ class UuidTest extends UnitTestCase {
*/
public function providerUuidInstances() {
$instances = array();
$instances = [];
$instances[][] = new Php();
// If valid PECL extensions exists add to list.
@ -83,15 +83,15 @@ class UuidTest extends UnitTestCase {
* - Failure message.
*/
public function providerTestValidation() {
return array(
return [
// These valid UUIDs.
array('6ba7b810-9dad-11d1-80b4-00c04fd430c8', TRUE, 'Basic FQDN UUID did not validate'),
array('00000000-0000-0000-0000-000000000000', TRUE, 'Minimum UUID did not validate'),
array('ffffffff-ffff-ffff-ffff-ffffffffffff', TRUE, 'Maximum UUID did not validate'),
['6ba7b810-9dad-11d1-80b4-00c04fd430c8', TRUE, 'Basic FQDN UUID did not validate'],
['00000000-0000-0000-0000-000000000000', TRUE, 'Minimum UUID did not validate'],
['ffffffff-ffff-ffff-ffff-ffffffffffff', TRUE, 'Maximum UUID did not validate'],
// These are invalid UUIDs.
array('0ab26e6b-f074-4e44-9da-601205fa0e976', FALSE, 'Invalid format was validated'),
array('0ab26e6b-f074-4e44-9daf-1205fa0e9761f', FALSE, 'Invalid length was validated'),
);
['0ab26e6b-f074-4e44-9da-601205fa0e976', FALSE, 'Invalid format was validated'],
['0ab26e6b-f074-4e44-9daf-1205fa0e9761f', FALSE, 'Invalid length was validated'],
];
}
}