1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\MediaBundle\Tests\Provider; |
13
|
|
|
|
14
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
15
|
|
|
use Sonata\MediaBundle\Provider\MediaProviderInterface; |
16
|
|
|
use Symfony\Component\Form\FormBuilder; |
17
|
|
|
use Symfony\Component\Form\FormTypeInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Virgile Vivier <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
abstract class AbstractProviderTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var FormBuilder |
26
|
|
|
*/ |
27
|
|
|
protected $formBuilder; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var FormMapper |
31
|
|
|
*/ |
32
|
|
|
protected $formMapper; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var FormTypeInterface |
36
|
|
|
*/ |
37
|
|
|
protected $formType; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var MediaProviderInterface |
41
|
|
|
*/ |
42
|
|
|
protected $provider; |
43
|
|
|
|
44
|
|
|
public function setUp() |
45
|
|
|
{ |
46
|
|
|
// NEXT_MAJOR: Hack for php 5.3 only, remove it when requirement of PHP is >= 5.4 |
47
|
|
|
$that = $this; |
48
|
|
|
|
49
|
|
|
$this->formMapper = $this->getMockBuilder('Sonata\AdminBundle\Form\FormMapper')->disableOriginalConstructor()->getMock(); |
50
|
|
|
$this->formMapper |
51
|
|
|
->expects($this->any()) |
52
|
|
|
->method('add') |
53
|
|
|
->will($this->returnCallback(function ($name, $type = null) use ($that) { |
54
|
|
|
// NEXT_MAJOR: Remove this "if" (when requirement of Symfony is >= 2.8) |
55
|
|
|
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) { |
56
|
|
|
if (null !== $type) { |
57
|
|
|
$isFQCN = class_exists($type); |
58
|
|
|
if (!$isFQCN && method_exists('Symfony\Component\Form\AbstractType', 'getName')) { |
59
|
|
|
// 2.8 |
60
|
|
|
@trigger_error( |
|
|
|
|
61
|
|
|
sprintf( |
62
|
|
|
'Accessing type "%s" by its string name is deprecated since version 2.8 and will be removed in 3.0.' |
63
|
|
|
.' Use the fully-qualified type class name instead.', |
64
|
|
|
$type |
65
|
|
|
), |
66
|
|
|
E_USER_DEPRECATED) |
67
|
|
|
; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$that->assertTrue($isFQCN, sprintf('Unable to ensure %s is a FQCN', $type)); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
})); |
74
|
|
|
|
75
|
|
|
$this->formBuilder = $this->getMockBuilder('Symfony\Component\Form\FormBuilder')->disableOriginalConstructor()->getMock(); |
76
|
|
|
$this->formBuilder |
77
|
|
|
->expects($this->any()) |
78
|
|
|
->method('add') |
79
|
|
|
->will($this->returnCallback(function ($name, $type = null) use ($that) { |
80
|
|
|
// NEXT_MAJOR: Remove this "if" (when requirement of Symfony is >= 2.8) |
81
|
|
|
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) { |
82
|
|
|
if (null !== $type) { |
83
|
|
|
$isFQCN = class_exists($type); |
84
|
|
|
if (!$isFQCN && method_exists('Symfony\Component\Form\AbstractType', 'getName')) { |
85
|
|
|
// 2.8 |
86
|
|
|
@trigger_error( |
|
|
|
|
87
|
|
|
sprintf( |
88
|
|
|
'Accessing type "%s" by its string name is deprecated since version 2.8 and will be removed in 3.0.' |
89
|
|
|
.' Use the fully-qualified type class name instead.', |
90
|
|
|
$type |
91
|
|
|
), |
92
|
|
|
E_USER_DEPRECATED) |
93
|
|
|
; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$that->assertTrue($isFQCN, sprintf('Unable to ensure %s is a FQCN', $type)); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
})); |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
$this->formBuilder->expects($this->any())->method('getOption')->willReturn('api'); |
103
|
|
|
|
104
|
|
|
$this->provider = $this->getProvider(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get the provider which have to be tested. |
109
|
|
|
*/ |
110
|
|
|
abstract public function getProvider(); |
111
|
|
|
|
112
|
|
|
public function testBuildEditForm() |
113
|
|
|
{ |
114
|
|
|
$this->provider->buildEditForm($this->formMapper); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testBuildCreateForm() |
118
|
|
|
{ |
119
|
|
|
$this->provider->buildCreateForm($this->formMapper); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function testBuildMediaType() |
123
|
|
|
{ |
124
|
|
|
$this->provider->buildMediaType($this->formBuilder); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: