|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
4
|
|
|
*/ |
|
5
|
|
|
namespace eZ\Publish\Core\Helper\Tests\FieldsGroups; |
|
6
|
|
|
|
|
7
|
|
|
use eZ\Bundle\EzPublishCoreBundle\ApiLoader\RepositoryConfigurationProvider; |
|
8
|
|
|
use eZ\Publish\Core\Helper\FieldsGroups\SettingsFieldsGroupsListFactory; |
|
9
|
|
|
use PHPUnit_Framework_TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class SettingsFieldsGroupsListFactoryTest extends PHPUnit_Framework_TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
private $repositoryConfigMock; |
|
14
|
|
|
|
|
15
|
|
|
private $translatorMock; |
|
16
|
|
|
|
|
17
|
|
|
public function testBuild() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->getRepositoryConfigMock() |
|
20
|
|
|
->expects($this->once()) |
|
21
|
|
|
->method('getRepositoryConfig') |
|
22
|
|
|
->willReturn(['fields_groups' => ['list' => ['group_a', 'group_b'], 'default' => 'group_a']]); |
|
23
|
|
|
|
|
24
|
|
|
$this->getTranslatorMock() |
|
25
|
|
|
->expects($this->any()) |
|
26
|
|
|
->method('trans') |
|
27
|
|
|
->will($this->returnArgument(0)); |
|
28
|
|
|
|
|
29
|
|
|
$factory = new SettingsFieldsGroupsListFactory($this->getRepositoryConfigMock()); |
|
|
|
|
|
|
30
|
|
|
$list = $factory->build($this->getTranslatorMock()); |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
self::assertEquals(['group_a' => 'group_a', 'group_b' => 'group_b'], $list->getGroups()); |
|
33
|
|
|
self::assertEquals('group_a', $list->getDefaultGroup()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Bundle\EzPublishCoreBundle\ApiLoader\RepositoryConfigurationProvider |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function getRepositoryConfigMock() |
|
40
|
|
|
{ |
|
41
|
|
|
if (!isset($this->repositoryConfigMock)) { |
|
42
|
|
|
$this->repositoryConfigMock = $this |
|
43
|
|
|
->getMockBuilder('eZ\Bundle\EzPublishCoreBundle\ApiLoader\RepositoryConfigurationProvider') |
|
44
|
|
|
->disableOriginalConstructor() |
|
45
|
|
|
->getMock(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $this->repositoryConfigMock; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\Translation\TranslatorInterface |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function getTranslatorMock() |
|
55
|
|
|
{ |
|
56
|
|
|
if (!isset($this->translatorMock)) { |
|
57
|
|
|
$this->translatorMock = $this->getMock('Symfony\Component\Translation\TranslatorInterface'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $this->translatorMock; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.