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\DoctrinePHPCRAdminBundle\Tests\Admin; |
13
|
|
|
|
14
|
|
|
use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; |
15
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\Admin\FieldDescription; |
16
|
|
|
|
17
|
|
|
class FieldDescriptionTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @dataProvider testDescribesSingleValuedAssociationProvider |
21
|
|
|
* |
22
|
|
|
* @param mixed $mappingType |
23
|
|
|
* @param bool $expected |
24
|
|
|
*/ |
25
|
|
|
public function testDescribesSingleValuedAssociation($mappingType, $expected) |
26
|
|
|
{ |
27
|
|
|
$fd = new FieldDescription(); |
28
|
|
|
$fd->setAssociationMapping(array( |
29
|
|
|
'fieldName' => 'foo', |
30
|
|
|
'type' => $mappingType, |
31
|
|
|
)); |
32
|
|
|
$this->assertSame($expected, $fd->describesSingleValuedAssociation()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testDescribesSingleValuedAssociationProvider() |
36
|
|
|
{ |
37
|
|
|
return array( |
38
|
|
|
'many to one' => array(ClassMetadata::MANY_TO_ONE, true), |
39
|
|
|
'parent' => array('parent', true), |
40
|
|
|
'child' => array('child', true), |
41
|
|
|
'many to many' => array(ClassMetadata::MANY_TO_MANY, false), |
42
|
|
|
'children' => array('children', false), |
43
|
|
|
'referrers' => array('referrers', false), |
44
|
|
|
'mixedreferrers' => array('mixedreferrers', false), |
45
|
|
|
'string' => array('string', false), |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @dataProvider testDescribesCollectionValuedAssociationProvider |
51
|
|
|
* |
52
|
|
|
* @param mixed $mappingType |
53
|
|
|
* @param bool $expected |
54
|
|
|
*/ |
55
|
|
|
public function testDescribesCollectionValuedAssociation($mappingType, $expected) |
56
|
|
|
{ |
57
|
|
|
$fd = new FieldDescription(); |
58
|
|
|
$fd->setAssociationMapping(array( |
59
|
|
|
'fieldName' => 'foo', |
60
|
|
|
'type' => $mappingType, |
61
|
|
|
)); |
62
|
|
|
$this->assertSame($expected, $fd->describesCollectionValuedAssociation()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testDescribesCollectionValuedAssociationProvider() |
66
|
|
|
{ |
67
|
|
|
return array( |
68
|
|
|
'many to one' => array(ClassMetadata::MANY_TO_ONE, false), |
69
|
|
|
'parent' => array('parent', false), |
70
|
|
|
'child' => array('child', false), |
71
|
|
|
'many to many' => array(ClassMetadata::MANY_TO_MANY, true), |
72
|
|
|
'children' => array('children', true), |
73
|
|
|
'referrers' => array('referrers', true), |
74
|
|
|
'mixedreferrers' => array('mixedreferrers', true), |
75
|
|
|
'string' => array('string', false), |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|