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\TranslationBundle\Tests\AdminExtension\Knplabs; |
13
|
|
|
|
14
|
|
|
use Sonata\AdminBundle\Admin\AdminInterface; |
15
|
|
|
use Sonata\TranslationBundle\Admin\Extension\Knplabs\TranslatableAdminExtension; |
16
|
|
|
use Sonata\TranslationBundle\Checker\TranslatableChecker; |
17
|
|
|
use Sonata\TranslationBundle\Tests\Fixtures\Model\Knplabs\TranslatableEntity; |
18
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @group translatable-knplabs |
22
|
|
|
*/ |
23
|
|
|
class TranslatableAdminExtensionTest extends WebTestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var AdminInterface |
27
|
|
|
*/ |
28
|
|
|
protected $admin; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var TranslatableEntity |
32
|
|
|
*/ |
33
|
|
|
protected $object; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var TranslatableAdminExtension |
37
|
|
|
*/ |
38
|
|
|
protected $extension; |
39
|
|
|
|
40
|
|
|
protected function setUp() |
41
|
|
|
{ |
42
|
|
|
$translatableChecker = new TranslatableChecker(); |
43
|
|
|
$translatableChecker->setSupportedInterfaces(array( |
44
|
|
|
'Sonata\TranslationBundle\Model\TranslatableInterface', |
45
|
|
|
)); |
46
|
|
|
$this->extension = new TranslatableAdminExtension($translatableChecker); |
47
|
|
|
|
48
|
|
|
$request = $this->prophesize('Symfony\Component\HttpFoundation\Request'); |
49
|
|
|
$request->get('tl')->willReturn('es'); |
50
|
|
|
|
51
|
|
|
$this->admin = $this->prophesize('Sonata\AdminBundle\Admin\AdminInterface'); |
52
|
|
|
$this->admin->getRequest()->willReturn($request->reveal()); |
53
|
|
|
$this->admin->hasRequest()->willReturn(true); |
54
|
|
|
|
55
|
|
|
$this->object = new TranslatableEntity(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testSetLocaleForTranslatableObject() |
59
|
|
|
{ |
60
|
|
|
$this->extension->alterNewInstance($this->admin->reveal(), $this->object); |
|
|
|
|
61
|
|
|
|
62
|
|
|
$this->assertEquals('es', $this->object->getLocale()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testAlterObjectForTranslatableObject() |
66
|
|
|
{ |
67
|
|
|
$this->extension->alterObject($this->admin->reveal(), $this->object); |
|
|
|
|
68
|
|
|
|
69
|
|
|
$this->assertEquals('es', $this->object->getLocale()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
View Code Duplication |
public function testPreUpdate() |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$object = $this->prophesize('Sonata\TranslationBundle\Tests\Fixtures\Model\Knplabs\TranslatableEntity'); |
75
|
|
|
$object->mergeNewTranslations()->shouldBeCalled(); |
76
|
|
|
|
77
|
|
|
$this->extension->preUpdate($this->admin->reveal(), $object->reveal()); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
View Code Duplication |
public function testPrePersist() |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
$object = $this->prophesize('Sonata\TranslationBundle\Tests\Fixtures\Model\Knplabs\TranslatableEntity'); |
83
|
|
|
$object->mergeNewTranslations()->shouldBeCalled(); |
84
|
|
|
|
85
|
|
|
$this->extension->prePersist($this->admin->reveal(), $object->reveal()); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.