Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
315
Merge Requests
315
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
a167eca3
Commit
a167eca3
authored
May 20, 2014
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2223423
by Xano, tim.plunkett: Stop extending \Drupal\Core\Entity\Entity in unit tests.
parent
ed8dfae0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
69 deletions
+35
-69
core/modules/views/tests/Drupal/views/Tests/Plugin/argument_validator/EntityTest.php
...upal/views/Tests/Plugin/argument_validator/EntityTest.php
+2
-8
core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
+33
-61
No files found.
core/modules/views/tests/Drupal/views/Tests/Plugin/argument_validator/EntityTest.php
View file @
a167eca3
...
...
@@ -64,10 +64,7 @@ protected function setUp() {
$this
->
entityManager
=
$this
->
getMock
(
'Drupal\Core\Entity\EntityManagerInterface'
);
$mock_entity
=
$this
->
getMockBuilder
(
'Drupal\Core\Entity\Entity'
)
->
disableOriginalConstructor
()
->
setMethods
(
array
(
'bundle'
,
'access'
))
->
getMock
();
$mock_entity
=
$this
->
getMockForAbstractClass
(
'Drupal\Core\Entity\Entity'
,
array
(),
''
,
FALSE
,
TRUE
,
TRUE
,
array
(
'bundle'
,
'access'
));
$mock_entity
->
expects
(
$this
->
any
())
->
method
(
'bundle'
)
->
will
(
$this
->
returnValue
(
'test_bundle'
));
...
...
@@ -79,10 +76,7 @@ protected function setUp() {
array
(
'test_op_3'
,
NULL
,
TRUE
),
)));
$mock_entity_bundle_2
=
$this
->
getMockBuilder
(
'Drupal\Core\Entity\Entity'
)
->
disableOriginalConstructor
()
->
setMethods
(
array
(
'bundle'
,
'access'
))
->
getMock
();
$mock_entity_bundle_2
=
$this
->
getMockForAbstractClass
(
'Drupal\Core\Entity\Entity'
,
array
(),
''
,
FALSE
,
TRUE
,
TRUE
,
array
(
'bundle'
,
'access'
));
$mock_entity_bundle_2
->
expects
(
$this
->
any
())
->
method
(
'bundle'
)
->
will
(
$this
->
returnValue
(
'test_bundle_2'
));
...
...
core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
View file @
a167eca3
...
...
@@ -7,9 +7,7 @@
namespace
Drupal\Tests\Core\Entity
;
use
Drupal\Core\Config\Entity\ConfigEntityBase
;
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
use
Drupal\Core\Entity\Entity
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Tests\UnitTestCase
;
...
...
@@ -70,7 +68,7 @@ protected function setUp() {
*/
public
function
testUrlInfo
(
$entity_class
,
$link_template
,
$expected
)
{
/** @var $entity \Drupal\Core\Entity\EntityInterface */
$entity
=
new
$entity_class
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
);
$entity
=
$this
->
getMockForAbstractClass
(
$entity_class
,
array
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
)
);
$uri
=
$this
->
getTestUrlInfo
(
$entity
,
$link_template
);
$this
->
assertSame
(
$expected
,
$uri
->
getRouteName
());
...
...
@@ -82,10 +80,10 @@ public function testUrlInfo($entity_class, $link_template, $expected) {
*/
public
function
providerTestUrlInfo
()
{
return
array
(
array
(
'Drupal\
Tests\Core\Entity\Test
Entity'
,
'edit-form'
,
'test_entity_type.edit'
),
array
(
'Drupal\
Tests\Core\Entity\TestConfigEntity
'
,
'edit-form'
,
'test_entity_type.edit'
),
array
(
'Drupal\
Core\Entity\
Entity'
,
'edit-form'
,
'test_entity_type.edit'
),
array
(
'Drupal\
Core\Config\Entity\ConfigEntityBase
'
,
'edit-form'
,
'test_entity_type.edit'
),
// Test that overriding the default $rel parameter works.
array
(
'Drupal\
Tests\Core\Entity\TestConfigEntity
'
,
FALSE
,
'test_entity_type.edit'
),
array
(
'Drupal\
Core\Config\Entity\ConfigEntityBase
'
,
FALSE
,
'test_entity_type.edit'
),
);
}
...
...
@@ -101,7 +99,7 @@ public function providerTestUrlInfo() {
*/
public
function
testUrlInfoForInvalidLinkTemplate
(
$entity_class
,
$link_template
)
{
/** @var $entity \Drupal\Core\Entity\EntityInterface */
$entity
=
new
$entity_class
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
);
$entity
=
$this
->
getMockForAbstractClass
(
$entity_class
,
array
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
)
);
$uri
=
$this
->
getTestUrlInfo
(
$entity
,
$link_template
);
$this
->
assertEmpty
(
$uri
);
...
...
@@ -112,9 +110,9 @@ public function testUrlInfoForInvalidLinkTemplate($entity_class, $link_template)
*/
public
function
providerTestUrlInfoForInvalidLinkTemplate
()
{
return
array
(
array
(
'Drupal\
Tests\Core\Entity\Test
Entity'
,
'canonical'
),
array
(
'Drupal\
Tests\Core\Entity\Test
Entity'
,
FALSE
),
array
(
'Drupal\
Tests\Core\Entity\TestConfigEntity
'
,
'canonical'
),
array
(
'Drupal\
Core\Entity\
Entity'
,
'canonical'
),
array
(
'Drupal\
Core\Entity\
Entity'
,
FALSE
),
array
(
'Drupal\
Core\Config\Entity\ConfigEntityBase
'
,
'canonical'
),
);
}
...
...
@@ -164,7 +162,7 @@ protected function getTestUrlInfo(EntityInterface $entity, $link_template) {
* @expectedException \Drupal\Core\Entity\EntityMalformedException
*/
public
function
testUrlInfoForNewEntity
()
{
$entity
=
new
TestEntity
(
array
(),
'test_entity_type'
);
$entity
=
$this
->
getMockForAbstractClass
(
'Drupal\Core\Entity\Entity'
,
array
(
array
(),
'test_entity_type'
)
);
$entity
->
urlInfo
();
}
...
...
@@ -187,13 +185,13 @@ public function testUrl() {
->
with
(
'test_entity_type'
)
->
will
(
$this
->
returnValue
(
$entity_type
));
$invalid_entity
=
new
TestEntity
(
array
(),
'test_entity_type'
);
$invalid_entity
=
$this
->
getMockForAbstractClass
(
'Drupal\Core\Entity\Entity'
,
array
(
array
(),
'test_entity_type'
)
);
$this
->
assertSame
(
''
,
$invalid_entity
->
url
());
$no_link_entity
=
new
TestEntity
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
);
$no_link_entity
=
$this
->
getMockForAbstractClass
(
'Drupal\Core\Entity\Entity'
,
array
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
)
);
$this
->
assertSame
(
''
,
$no_link_entity
->
url
(
'banana'
));
$valid_entity
=
new
TestEntity
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
);
$valid_entity
=
$this
->
getMockForAbstractClass
(
'Drupal\Core\Entity\Entity'
,
array
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
)
);
$this
->
urlGenerator
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'generateFromRoute'
)
->
will
(
$this
->
returnValueMap
(
array
(
...
...
@@ -245,7 +243,10 @@ public function testUrlForAdminForm() {
))
->
will
(
$this
->
returnValue
(
'entity/test_entity_type/test_entity_bundle/test_entity_id'
));
$entity
=
new
TestEntityWithBundle
(
array
(
'id'
=>
'test_entity_id'
,
'bundle'
=>
'test_entity_bundle'
),
'test_entity_type'
);
$entity
=
$this
->
getMockForAbstractClass
(
'Drupal\Core\Entity\Entity'
,
array
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
),
''
,
TRUE
,
TRUE
,
TRUE
,
array
(
'bundle'
));
$entity
->
expects
(
$this
->
any
())
->
method
(
'bundle'
)
->
will
(
$this
->
returnValue
(
'test_entity_bundle'
));
$this
->
assertSame
(
'entity/test_entity_type/test_entity_bundle/test_entity_id'
,
$entity
->
url
(
'admin-form'
));
}
...
...
@@ -269,7 +270,7 @@ public function testGetSystemPath() {
->
with
(
'test_entity_type'
)
->
will
(
$this
->
returnValue
(
$entity_type
));
$no_link_entity
=
new
TestEntity
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
);
$no_link_entity
=
$this
->
getMockForAbstractClass
(
'Drupal\Core\Entity\Entity'
,
array
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
)
);
$this
->
assertSame
(
''
,
$no_link_entity
->
getSystemPath
(
'banana'
));
$this
->
urlGenerator
->
expects
(
$this
->
once
())
...
...
@@ -277,7 +278,7 @@ public function testGetSystemPath() {
->
with
(
'test_entity_type.view'
,
array
(
'test_entity_type'
=>
'test_entity_id'
))
->
will
(
$this
->
returnValue
(
'entity/test_entity_type/test_entity_id'
));
$valid_entity
=
new
TestEntity
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
);
$valid_entity
=
$this
->
getMockForAbstractClass
(
'Drupal\Core\Entity\Entity'
,
array
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
)
);
$this
->
assertSame
(
'entity/test_entity_type/test_entity_id'
,
$valid_entity
->
getSystemPath
());
}
...
...
@@ -290,21 +291,30 @@ public function testGetSystemPath() {
*
* @dataProvider providerTestLinkTemplates
*/
public
function
testLinkTemplates
(
$
entity_clas
s
,
$expected
)
{
public
function
testLinkTemplates
(
$
override_template
s
,
$expected
)
{
$entity_type
=
$this
->
getMock
(
'Drupal\Core\Entity\EntityTypeInterface'
);
$entity_type
->
expects
(
$this
->
exactly
(
2
))
$entity_type
->
expects
(
$this
->
any
(
))
->
method
(
'getLinkTemplates'
)
->
will
(
$this
->
returnValue
(
array
(
'canonical'
=>
'test_entity_type.view'
,
)));
$this
->
entityManager
->
expects
(
$this
->
exactly
(
2
))
->
expects
(
$this
->
any
(
))
->
method
(
'getDefinition'
)
->
with
(
'test_entity_type'
)
->
will
(
$this
->
returnValue
(
$entity_type
));
$entity
=
new
$entity_class
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
);
$entity
=
$this
->
getMockForAbstractClass
(
'Drupal\Core\Entity\Entity'
,
array
(
array
(
'id'
=>
'test_entity_id'
),
'test_entity_type'
),
''
,
TRUE
,
TRUE
,
TRUE
,
array
(
'linkTemplates'
));
$entity
->
expects
(
$this
->
any
())
->
method
(
'linkTemplates'
)
->
will
(
$this
->
returnCallback
(
function
()
use
(
$entity_type
,
$override_templates
)
{
$templates
=
$entity_type
->
getLinkTemplates
();
if
(
$override_templates
)
{
$templates
[
'bananas'
]
=
'test_entity_type.bananas'
;
}
return
$templates
;
}));
$this
->
assertSame
(
$expected
[
'canonical'
],
$entity
->
hasLinkTemplate
(
'canonical'
));
$this
->
assertSame
(
$expected
[
'bananas'
],
$entity
->
hasLinkTemplate
(
'bananas'
));
}
...
...
@@ -314,11 +324,11 @@ public function testLinkTemplates($entity_class, $expected) {
*/
public
function
providerTestLinkTemplates
()
{
return
array
(
array
(
'Drupal\Tests\Core\Entity\TestEntity'
,
array
(
array
(
FALSE
,
array
(
'canonical'
=>
TRUE
,
'bananas'
=>
FALSE
,
)),
array
(
'Drupal\Tests\Core\Entity\TestEntityWithTemplates'
,
array
(
array
(
TRUE
,
array
(
'canonical'
=>
TRUE
,
'bananas'
=>
TRUE
,
)),
...
...
@@ -326,41 +336,3 @@ public function providerTestLinkTemplates() {
}
}
class
TestConfigEntity
extends
ConfigEntityBase
{
}
class
TestEntity
extends
Entity
{
}
class
TestEntityWithTemplates
extends
TestEntity
{
/**
* {@inheritdoc}
*/
protected
function
linkTemplates
()
{
$templates
=
parent
::
linkTemplates
();
$templates
[
'bananas'
]
=
'test_entity_type.bananas'
;
return
$templates
;
}
}
class
TestEntityWithBundle
extends
TestEntity
{
/**
* The entity bundle.
*
* @var string
*/
protected
$bundle
;
/**
* {@inheritdoc}
*/
public
function
bundle
()
{
return
$this
->
bundle
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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