|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Unit\AutoRoute; |
| 4 | + |
| 5 | +use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\BaseTestCase; |
| 6 | +use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\UrlContextCollection; |
| 7 | + |
| 8 | +class UrlContextCollectionTest extends BaseTestCase |
| 9 | +{ |
| 10 | + protected $urlContextCollection; |
| 11 | + |
| 12 | + public function setUp() |
| 13 | + { |
| 14 | + parent::setUp(); |
| 15 | + $this->subjectObject = new \stdClass; |
| 16 | + |
| 17 | + for ($i = 1; $i <= 3; $i++) { |
| 18 | + $this->{'autoRoute' . $i} = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRouteInterface'); |
| 19 | + $this->{'urlContext' . $i} = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\UrlContext'); |
| 20 | + $this->{'urlContext' . $i}->getAutoRoute()->willReturn($this->{'autoRoute' . $i}); |
| 21 | + } |
| 22 | + |
| 23 | + $this->urlContextCollection = new UrlContextCollection($this->subjectObject); |
| 24 | + } |
| 25 | + |
| 26 | + public function testGetSubjectObject() |
| 27 | + { |
| 28 | + $this->assertEquals($this->subjectObject, $this->urlContextCollection->getSubjectObject()); |
| 29 | + } |
| 30 | + |
| 31 | + public function testCreateUrlContext() |
| 32 | + { |
| 33 | + $res = $this->urlContextCollection->createUrlContext('fr'); |
| 34 | + $this->assertInstanceOf('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\UrlContext', $res); |
| 35 | + $this->assertEquals('fr', $res->getLocale()); |
| 36 | + } |
| 37 | + |
| 38 | + public function provideContainsAutoRoute() |
| 39 | + { |
| 40 | + return array( |
| 41 | + array( |
| 42 | + array('urlContext1', 'urlContext2', 'urlContext3'), |
| 43 | + 'autoRoute1', |
| 44 | + true |
| 45 | + ), |
| 46 | + array( |
| 47 | + array('urlContext2', 'urlContext3'), |
| 48 | + 'autoRoute1', |
| 49 | + false |
| 50 | + ), |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + |
| 55 | + /** |
| 56 | + * @dataProvider provideContainsAutoRoute |
| 57 | + */ |
| 58 | + public function testContainsAutoRoute($urlContextNames, $targetName, $expected) |
| 59 | + { |
| 60 | + foreach ($urlContextNames as $urlContextName) { |
| 61 | + $this->urlContextCollection->addUrlContext($this->$urlContextName->reveal()); |
| 62 | + } |
| 63 | + |
| 64 | + $res = $this->urlContextCollection->containsAutoRoute($this->$targetName->reveal()); |
| 65 | + |
| 66 | + $this->assertEquals($expected, $res); |
| 67 | + } |
| 68 | +} |
0 commit comments