Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* @file
* Contains \Drupal\config_translation\Tests\ConfigEntityMapperTest.
*/
namespace Drupal\config_translation\Tests;
use Drupal\config_translation\ConfigEntityMapper;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\Routing\Route;
/**
* Tests ConfigEntityMapper.
*
* @group Drupal
* @group Config_translation
*/
class ConfigEntityMapperTest extends UnitTestCase {
/**
* The configuration entity mapper to test.
*
* @var \Drupal\config_translation\ConfigEntityMapper
*/
protected $configEntityMapper;
/**
* The entity manager used for testing.
*
* @var \Drupal\Core\Config\TypedConfigManager|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
/**
* The entity instance used for testing.
*
* @var \Drupal\Core\Config\TypedConfigManager|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entity;
/**
* The route provider used for testing.
*
* @var \Drupal\Core\Routing\RouteProviderInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $routeProvider;
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Configuration entity mapper',
'description' => 'Tests the functionality provided by the configuration entity mapper.',
'group' => 'Configuration Translation',
);
}
public function setUp() {
$this->entityManager = $this->getMockBuilder('Drupal\Core\Entity\EntityManager')
->disableOriginalConstructor()
->getMock();
$this->entity = $this->getMock('Drupal\Core\Entity\EntityInterface');
$this->routeProvider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
$this->routeProvider
->expects($this->once())
->method('getRouteByName')
->with('language.edit')
->will($this->returnValue(new Route('/admin/config/regional/language/edit/{language_entity}')));
$definition = array(
'class' => '\Drupal\config_translation\ConfigEntityMapper',
'base_route_name' => 'language.edit',
'title' => '!label language',
'names' => array(),
'entity_type' => 'language_entity',
'route_name' => 'config_translation.item.overview.language.edit',
);
$locale_config_manager = $this->getMockBuilder('Drupal\locale\LocaleConfigManager')
->disableOriginalConstructor()
->getMock();
$this->configEntityMapper = new ConfigEntityMapper(
'language_entity',
$definition,
$this->getConfigFactoryStub(),
$locale_config_manager,
$this->getMock('Drupal\config_translation\ConfigMapperManagerInterface'),
$this->routeProvider,
$this->getStringTranslationStub(),
$this->entityManager
);
}
/**
* Tests ConfigEntityMapper::setEntity().
*/
public function testSetEntity() {
$this->entity
->expects($this->once())
->method('id')
->with()
->will($this->returnValue('entity_id'));
$this->entityManager
->expects($this->once())
->method('getDefinition')
->with('language_entity')
->will($this->returnValue(array('config_prefix' => 'config_prefix')));
$result = $this->configEntityMapper->setEntity($this->entity);
$this->assertTrue($result);
// Make sure setEntity() returns FALSE when called a second time.
$result = $this->configEntityMapper->setEntity($this->entity);
$this->assertFalse($result);
}
/**
* Tests ConfigEntityMapper::getOverviewRouteParameters().
*/
public function testGetOverviewRouteParameters() {
$this->configEntityMapper->setEntity($this->entity);
$this->entity
->expects($this->once())
->method('id')
->with()
->will($this->returnValue('entity_id'));
$result = $this->configEntityMapper->getOverviewRouteParameters();
$this->assertSame(array('language_entity' => 'entity_id'), $result);
}
/**
* Tests ConfigEntityMapper::getType().
*/
public function testGetType() {
$result = $this->configEntityMapper->getType();
$this->assertSame('language_entity', $result);
}
/**
* Tests ConfigEntityMapper::getTypeName().
*/
public function testGetTypeName() {
$this->entityManager
->expects($this->once())
->method('getDefinition')
->with('language_entity')
->will($this->returnValue(array('label' => 'test')));
$result = $this->configEntityMapper->getTypeName();
$this->assertSame('test', $result);
}
/**
* Tests ConfigEntityMapper::getTypeLabel().
*/
public function testGetTypeLabel() {
$this->entityManager
->expects($this->once())
->method('getDefinition')
->with('language_entity')
->will($this->returnValue(array('label' => 'test')));
$result = $this->configEntityMapper->getTypeLabel();
$this->assertSame('test', $result);
}
/**
* Tests ConfigEntityMapper::getOperations().
*/
public function testGetOperations() {
$result = $this->configEntityMapper->getOperations();
$expected = array(
'list' => array(
'title' => 'List',
'href' => 'admin/config/regional/config-translation/language_entity',
)
);
$this->assertSame($expected, $result);
}
}