|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dtc\GridBundle\Tests\Manager; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
|
6
|
|
|
use Dtc\GridBundle\Manager\GridSourceManager; |
|
7
|
|
|
use Dtc\GridBundle\Tests\Grid\Source\TestGridSource; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Container; |
|
10
|
|
|
|
|
11
|
|
|
class GridSourceManagerTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testConstruct() |
|
14
|
|
|
{ |
|
15
|
|
|
$container = new Container(); |
|
16
|
|
|
$container->setParameter('dtc_grid.custom_managers', []); |
|
17
|
|
|
$gridSourceManager = new GridSourceManager(new AnnotationReader(), '/tmp', true); |
|
18
|
|
|
self::assertNotNull($gridSourceManager->all()); |
|
19
|
|
|
self::assertInternalType('array', $gridSourceManager->all()); |
|
20
|
|
|
self::assertEmpty($gridSourceManager->all()); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testAdd() |
|
24
|
|
|
{ |
|
25
|
|
|
$container = new Container(); |
|
26
|
|
|
$container->setParameter('dtc_grid.custom_managers', []); |
|
27
|
|
|
$gridSourceManager = new GridSourceManager(new AnnotationReader(), '/tmp', true); |
|
28
|
|
|
$gridSource = new TestGridSource(); |
|
29
|
|
|
$gridSourceManager->add('test_grid_source', $gridSource); |
|
30
|
|
|
self::assertSame($gridSource, $gridSourceManager->get('test_grid_source')); |
|
31
|
|
|
try { |
|
32
|
|
|
$gridSourceManager->get('test_grirce'); |
|
33
|
|
|
$this->fail('should not get a gridsource here'); |
|
34
|
|
|
} catch (\Exception $exception) { |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testGetNegativeCase() |
|
39
|
|
|
{ |
|
40
|
|
|
$container = new Container(); |
|
41
|
|
|
$container->setParameter('dtc_grid.custom_managers', []); |
|
42
|
|
|
$gridSourceManager = new GridSourceManager(new AnnotationReader(), '/tmp', true); |
|
43
|
|
|
$gridSource = new TestGridSource(); |
|
44
|
|
|
try { |
|
45
|
|
|
$gridSourceManager->get('test_grirce'); |
|
46
|
|
|
$this->fail('should not get a gridsource here'); |
|
47
|
|
|
} catch (\Exception $exception) { |
|
48
|
|
|
} |
|
49
|
|
|
$gridSourceManager->add('test_grid_source', $gridSource); |
|
50
|
|
|
try { |
|
51
|
|
|
$gridSourceManager->get('test_grirce'); |
|
52
|
|
|
$this->fail('should not get a gridsource here'); |
|
53
|
|
|
} catch (\Exception $exception) { |
|
54
|
|
|
} |
|
55
|
|
|
try { |
|
56
|
|
|
$gridSourceManager->get(''); |
|
57
|
|
|
$this->fail('should not get a gridsource here'); |
|
58
|
|
|
} catch (\Exception $exception) { |
|
59
|
|
|
} |
|
60
|
|
|
try { |
|
61
|
|
|
$gridSourceManager->get(null); |
|
62
|
|
|
$this->fail('should not get a gridsource here'); |
|
63
|
|
|
} catch (\Exception $exception) { |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|