| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Mysite\Test\Behaviour; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use SilverStripe\BehatExtension\Context\SilverStripeContext, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |     SilverStripe\BehatExtension\Context\BasicContext, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     SilverStripe\BehatExtension\Context\LoginContext, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     SilverStripe\BehatExtension\Context\FixtureContext, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     SilverStripe\Framework\Test\Behaviour\CmsFormsContext, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     SilverStripe\Framework\Test\Behaviour\CmsUiContext, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     SilverStripe\Cms\Test\Behaviour; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | // PHPUnit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | require_once 'PHPUnit/Autoload.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | require_once 'PHPUnit/Framework/Assert/Functions.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * Features context | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * Context automatically loaded by Behat. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * Uses subcontexts to extend functionality. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | class FeatureContext extends SilverStripeContext { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @var FixtureFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     protected $fixtureFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * Initializes context. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * Every scenario gets it's own context object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @param array $parameters context parameters (set them up through behat.yml) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public function __construct(array $parameters) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         parent::__construct($parameters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $this->useContext('BasicContext', new BasicContext($parameters)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $this->useContext('LoginContext', new LoginContext($parameters)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $this->useContext('CmsFormsContext', new CmsFormsContext($parameters)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $this->useContext('CmsUiContext', new CmsUiContext($parameters)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $fixtureContext = new FixtureContext($parameters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $fixtureContext->setFixtureFactory($this->getFixtureFactory()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->useContext('FixtureContext', $fixtureContext); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         // Use blueprints to set user name from identifier | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $factory = $fixtureContext->getFixtureFactory(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $blueprint = \Injector::inst()->create('FixtureBlueprint', 'Member'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $blueprint->addCallback('beforeCreate', function($identifier, &$data, &$fixtures) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             if(!isset($data['FirstName'])) $data['FirstName'] = $identifier; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $factory->define('Member', $blueprint); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         // Auto-publish pages | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         if (class_exists('SiteTree')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             foreach(\ClassInfo::subclassesFor('SiteTree') as $id => $class) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                 $blueprint = \Injector::inst()->create('FixtureBlueprint', $class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                 $blueprint->addCallback('afterCreate', function($obj, $identifier, &$data, &$fixtures) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                     $obj->publish('Stage', 'Live'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                 $factory->define($class, $blueprint); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     public function setMinkParameters(array $parameters) { | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |         parent::setMinkParameters($parameters); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |          | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |         if(isset($parameters['files_path'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |             $this->getSubcontext('FixtureContext')->setFilesPath($parameters['files_path']);     | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @return FixtureFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     public function getFixtureFactory() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         if(!$this->fixtureFactory) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             $this->fixtureFactory = \Injector::inst()->create('BehatFixtureFactory'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         return $this->fixtureFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     public function setFixtureFactory(FixtureFactory $factory) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $this->fixtureFactory = $factory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * "Shares" the database with web requests, see | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * {@link MeridianFakeManagerControllerExtension} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     public function getTestSessionState() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         return array_merge( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             parent::getTestSessionState(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                 'useFakeManager' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                 'importDatabasePath' => BASE_PATH .'/mysite/tests/fixtures/SS-sample.sql', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                 'requireDefaultRecords' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                 'fakeDatabasePath' => $this->getFakeDatabasePath(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     public function getFakeDatabasePath() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         return BASE_PATH . '/FakeDatabase.json'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     // Place your definition and hook methods here: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     //    /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     //     * @Given /^I have done something with "([^"]*)"$/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     //     */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     //    public function iHaveDoneSomethingWith($argument) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     //        $container = $this->kernel->getContainer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     //        $container->get('some_service')->doSomethingWith($argument); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     //    } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     // | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 121 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 122 |  |  |  | 
            
                        
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.