| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Sylius package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Paweł Jędrzejewski | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 spec\Sylius\Behat\Service\Resolver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Behat\Mink\Session; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use PhpSpec\ObjectBehavior; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Sylius\Behat\Page\SymfonyPageInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Sylius\Behat\Service\Resolver\CurrentPageResolver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Symfony\Component\Routing\Matcher\UrlMatcherInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @mixin CurrentPageResolver | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @author Łukasz Chruściel <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | class CurrentPageResolverSpec extends ObjectBehavior | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     function let(Session $session, UrlMatcherInterface $urlMatcher) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $this->beConstructedWith($session, $urlMatcher); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     function it_is_initializable() | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         $this->shouldHaveType('Sylius\Behat\Service\Resolver\CurrentPageResolver'); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     function it_implements_current_page_resolver_interface() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $this->shouldImplement(CurrentPageResolverInterface::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     function it_returns_current_page_based_on_matched_route( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         Session $session, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         SymfonyPageInterface $createPage, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         SymfonyPageInterface $updatePage, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         UrlMatcherInterface $urlMatcher | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $session->getCurrentUrl()->willReturn('https://sylius.com/resource/new'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $urlMatcher->match('/resource/new')->willReturn(['_route' => 'sylius_resource_create']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $createPage->getRouteName()->willReturn('sylius_resource_create'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $updatePage->getRouteName()->willReturn('sylius_resource_update'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->getCurrentPageWithForm([$createPage, $updatePage])->shouldReturn($createPage); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     function it_throws_an_exception_if_neither_create_nor_update_key_word_has_been_found( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         Session $session, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         SymfonyPageInterface $createPage, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         SymfonyPageInterface $updatePage, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         UrlMatcherInterface $urlMatcher | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $session->getCurrentUrl()->willReturn('https://sylius.com/resource/show'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $urlMatcher->match('/resource/show')->willReturn(['_route' => 'sylius_resource_show']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $createPage->getRouteName()->willReturn('sylius_resource_create'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $updatePage->getRouteName()->willReturn('sylius_resource_update'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $this->shouldThrow(\LogicException::class)->during('getCurrentPageWithForm', [[$createPage, $updatePage]]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 72 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |  |