Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
5dc22c73
Commit
5dc22c73
authored
Jun 11, 2014
by
Nathaniel Catchpole
Browse files
Issue
#2278705
by Xano: Make all tests compatible with PHPUnit 4.
parent
302329be
Changes
4
Hide whitespace changes
Inline
Side-by-side
core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php
View file @
5dc22c73
...
...
@@ -461,11 +461,6 @@ public function testCheckNamedRouteWithUpcastedValues() {
$subrequest
=
Request
::
create
(
'/test-route-1/example'
);
$class
=
$this
->
getMockClass
(
'Symfony\Component\HttpFoundation\Request'
,
array
(
'create'
));
$class
::
staticExpects
(
$this
->
any
())
->
method
(
'create'
)
->
with
(
'/test-route-1/example'
)
->
will
(
$this
->
returnValue
(
$subrequest
));
$this
->
accessManager
=
new
AccessManager
(
$this
->
routeProvider
,
$this
->
urlGenerator
,
$this
->
paramConverter
,
$this
->
argumentsResolver
);
$this
->
accessManager
->
setContainer
(
$this
->
container
);
...
...
@@ -520,11 +515,6 @@ public function testCheckNamedRouteWithDefaultValue() {
->
will
(
$this
->
returnValue
(
array
(
'value'
=>
'upcasted_value'
)));
$subrequest
=
Request
::
create
(
'/test-route-1/example'
);
$class
=
$this
->
getMockClass
(
'Symfony\Component\HttpFoundation\Request'
,
array
(
'create'
));
$class
::
staticExpects
(
$this
->
any
())
->
method
(
'create'
)
->
with
(
'/test-route-1/example'
)
->
will
(
$this
->
returnValue
(
$subrequest
));
$this
->
accessManager
=
new
AccessManager
(
$this
->
routeProvider
,
$this
->
urlGenerator
,
$this
->
paramConverter
,
$this
->
argumentsResolver
);
$this
->
accessManager
->
setContainer
(
$this
->
container
);
...
...
core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
View file @
5dc22c73
...
...
@@ -9,6 +9,7 @@
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
use
Drupal\Core\Field\FieldDefinition
;
use
Drupal\Core\Field\FieldItemBase
;
use
Drupal\Tests\UnitTestCase
;
use
Drupal\Core\Language\Language
;
...
...
@@ -217,10 +218,7 @@ public function testIsNewRevision() {
->
getMock
();
$field_item
=
$this
->
getMockBuilder
(
'\Drupal\Core\Field\FieldItemBase'
)
->
disableOriginalConstructor
()
->
getMock
();
$field_item
->
staticExpects
(
$this
->
once
())
->
method
(
'mainPropertyName'
)
->
will
(
$this
->
returnValue
(
'value'
));
->
getMockForAbstractClass
();
$this
->
typedDataManager
->
expects
(
$this
->
any
())
->
method
(
'getPropertyInstance'
)
...
...
core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php
View file @
5dc22c73
...
...
@@ -11,6 +11,7 @@
use
Drupal\Component\Plugin\Exception\PluginNotFoundException
;
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
use
Drupal\Core\DependencyInjection\ContainerInjectionInterface
;
use
Drupal\Core\Entity\ContentEntityBase
;
use
Drupal\Core\Entity\ContentEntityInterface
;
use
Drupal\Core\Entity\EntityControllerBase
;
use
Drupal\Core\Entity\EntityControllerInterface
;
...
...
@@ -739,9 +740,11 @@ public function testGetFieldDefinitionsProvider() {
* @return \Drupal\Core\Field\FieldDefinition|\PHPUnit_Framework_MockObject_MockObject
* A field definition object.
*/
protected
function
setUpEntityWithFieldDefinition
(
$custom_invoke_all
=
FALSE
,
$field_definition_id
=
'id'
,
$base_field_definition_calls
=
1
)
{
protected
function
setUpEntityWithFieldDefinition
(
$custom_invoke_all
=
FALSE
,
$field_definition_id
=
'id'
)
{
$entity_type
=
$this
->
getMock
(
'Drupal\Core\Entity\EntityTypeInterface'
);
$entity
=
$this
->
getMock
(
'Drupal\Tests\Core\Entity\TestContentEntityInterface'
);
$entity
=
$this
->
getMockBuilder
(
'Drupal\Tests\Core\Entity\EntityManagerTestEntity'
)
->
disableOriginalConstructor
()
->
getMockForAbstractClass
();
$entity_class
=
get_class
(
$entity
);
$entity_type
->
expects
(
$this
->
any
())
...
...
@@ -757,14 +760,10 @@ protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $f
$field_definition
=
$this
->
getMockBuilder
(
'Drupal\Core\Field\FieldDefinition'
)
->
disableOriginalConstructor
()
->
getMock
();
$entity_class
::
staticExpects
(
$this
->
exactly
(
$base_field_definition_calls
))
->
method
(
'baseFieldDefinitions'
)
->
will
(
$this
->
returnValue
(
array
(
$field_definition_id
=>
$field_definition
,
)));
$entity_class
::
staticExpects
(
$this
->
any
())
->
method
(
'bundleFieldDefinitions'
)
->
will
(
$this
->
returnValue
(
array
()));
$entity_class
::
$baseFieldDefinitions
=
array
(
$field_definition_id
=>
$field_definition
,
);
$entity_class
::
$bundleFieldDefinitions
=
array
();
$this
->
moduleHandler
=
$this
->
getMock
(
'Drupal\Core\Extension\ModuleHandlerInterface'
);
$this
->
moduleHandler
->
expects
(
$this
->
any
())
...
...
@@ -1053,7 +1052,9 @@ function testgetExtraFields() {
public
function
testGetFieldMap
()
{
// Set up a content entity type.
$entity_type
=
$this
->
getMock
(
'Drupal\Core\Entity\ContentEntityTypeInterface'
);
$entity
=
$this
->
getMock
(
'Drupal\Tests\Core\Entity\TestContentEntityInterface'
);
$entity
=
$this
->
getMockBuilder
(
'Drupal\Tests\Core\Entity\EntityManagerTestEntity'
)
->
disableOriginalConstructor
()
->
getMockForAbstractClass
();
$entity_class
=
get_class
(
$entity
);
$entity_type
->
expects
(
$this
->
any
())
->
method
(
'getClass'
)
...
...
@@ -1061,6 +1062,9 @@ public function testGetFieldMap() {
$entity_type
->
expects
(
$this
->
any
())
->
method
(
'getKeys'
)
->
will
(
$this
->
returnValue
(
array
()));
$entity_type
->
expects
(
$this
->
any
())
->
method
(
'id'
)
->
will
(
$this
->
returnValue
(
'test_entity_type'
));
$entity_type
->
expects
(
$this
->
any
())
->
method
(
'isSubclassOf'
)
->
with
(
'\Drupal\Core\Entity\ContentEntityInterface'
)
...
...
@@ -1100,9 +1104,7 @@ public function testGetFieldMap() {
$base_field_definitions
=
array
(
'id'
=>
$id_definition
,
);
$entity_class
::
staticExpects
(
$this
->
once
())
->
method
(
'baseFieldDefinitions'
)
->
will
(
$this
->
returnValue
(
$base_field_definitions
));
$entity_class
::
$baseFieldDefinitions
=
$base_field_definitions
;
// Set up a by bundle field definition that only exists on one bundle.
$bundle_definition
=
$this
->
getMockBuilder
(
'Drupal\Core\Field\FieldDefinition'
)
...
...
@@ -1111,24 +1113,14 @@ public function testGetFieldMap() {
$bundle_definition
->
expects
(
$this
->
once
())
->
method
(
'getType'
)
->
will
(
$this
->
returnValue
(
'string'
));
$entity_class
::
staticExpects
(
$this
->
any
())
->
method
(
'bundleFieldDefinitions'
)
->
will
(
$this
->
returnValueMap
(
array
(
array
(
$entity_type
,
'first_bundle'
,
$base_field_definitions
,
array
(),
),
array
(
$entity_type
,
'second_bundle'
,
$base_field_definitions
,
array
(
'by_bundle'
=>
$bundle_definition
,
),
$entity_class
::
$bundleFieldDefinitions
=
array
(
'test_entity_type'
=>
array
(
'first_bundle'
=>
array
(),
'second_bundle'
=>
array
(
'by_bundle'
=>
$bundle_definition
,
),
)));
),
);
// Set up a non-content entity type.
$non_content_entity_type
=
$this
->
getMock
(
'Drupal\Core\Entity\EntityTypeInterface'
);
...
...
@@ -1196,6 +1188,43 @@ protected function getTestControllerClass() {
}
/*
* Provides a content entity with dummy static method implementations.
*/
abstract
class
EntityManagerTestEntity
implements
\
Iterator
,
ContentEntityInterface
{
/**
* The base field definitions.
*
* @var \Drupal\Core\Field\FieldDefinitionInterface[]
*/
public
static
$baseFieldDefinitions
=
array
();
/**
* The bundle field definitions.
*
* @var array[]
* Keys are entity type IDs, values are arrays of which the keys are bundle
* names and the values are field definitions.
*/
public
static
$bundleFieldDefinitions
=
array
();
/**
* {@inheritdoc}
*/
public
static
function
baseFieldDefinitions
(
EntityTypeInterface
$entity_type
)
{
return
static
::
$baseFieldDefinitions
;
}
/**
* {@inheritdoc}
*/
public
static
function
bundleFieldDefinitions
(
EntityTypeInterface
$entity_type
,
$bundle
,
array
$base_field_definitions
)
{
return
isset
(
static
::
$bundleFieldDefinitions
[
$entity_type
->
id
()][
$bundle
])
?
static
::
$bundleFieldDefinitions
[
$entity_type
->
id
()][
$bundle
]
:
array
();
}
}
/**
* Provides a testable version of ContentEntityInterface.
*
...
...
core/tests/Drupal/Tests/Core/EventSubscriber/ReverseProxySubscriberUnitTest.php
View file @
5dc22c73
...
...
@@ -10,6 +10,7 @@
use
Drupal\Core\EventSubscriber\ReverseProxySubscriber
;
use
Drupal\Core\Site\Settings
;
use
Drupal\Tests\UnitTestCase
;
use
Symfony\Component\HttpFoundation\Request
;
/**
* Tests the ReverseProxySubscriber.
...
...
@@ -78,16 +79,12 @@ public function testReverseProxyEnabled() {
*/
protected
function
trustedHeadersAreSet
(
Settings
$settings
)
{
$subscriber
=
new
ReverseProxySubscriber
(
$settings
);
$request
=
$this
->
getMock
(
'Symfony\Component\HttpFoundation\Request'
,
array
(
'setTrustedHeaderName'
,
'setTrustedProxies'
));
$request
->
staticExpects
(
$this
->
at
(
0
))
->
method
(
'setTrustedHeaderName'
)
->
with
(
$this
->
equalTo
(
$request
::
HEADER_CLIENT_IP
),
$this
->
equalTo
(
$settings
->
get
(
'reverse_proxy_header'
)));
$request
->
staticExpects
(
$this
->
at
(
1
))
->
method
(
'setTrustedProxies'
)
->
with
(
$this
->
equalTo
(
$settings
->
get
(
'reverse_proxy_addresses'
)));
$request
=
new
Request
();
$event
=
$this
->
getMockedEvent
(
$request
);
$subscriber
->
onKernelRequestReverseProxyCheck
(
$event
);
$this
->
assertSame
(
$settings
->
get
(
'reverse_proxy_header'
),
$request
->
getTrustedHeaderName
(
$request
::
HEADER_CLIENT_IP
));
$this
->
assertSame
(
$settings
->
get
(
'reverse_proxy_addresses'
),
$request
->
getTrustedProxies
());
}
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment