| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace SilverStripe\Widgets\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 5 |  |  | use SilverStripe\Dev\FunctionalTest; | 
            
                                                                        
                            
            
                                    
            
            
                | 6 |  |  | use SilverStripe\Widgets\Model\Widget; | 
            
                                                                        
                            
            
                                    
            
            
                | 7 |  |  | use SilverStripe\Dev\TestOnly; | 
            
                                                                        
                            
            
                                    
            
            
                | 8 |  |  | use SilverStripe\Forms\TextField; | 
            
                                                                        
                            
            
                                    
            
            
                | 9 |  |  | use SilverStripe\Forms\FieldList; | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  | use SilverStripe\Forms\FormAction; | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | use SilverStripe\Forms\Form; | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | use SilverStripe\Widgets\Controllers\WidgetController; | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | use SilverStripe\Widgets\Tests\WidgetControllerTest\TestPage; | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | use SilverStripe\Widgets\Tests\WidgetControllerTest\TestWidget; | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  | /** | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |  * @package widgets | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |  * @subpackage tests | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | class WidgetControllerTest extends FunctionalTest | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     protected static $fixture_file = 'WidgetControllerTest.yml'; | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     protected $extraDataObjects = array( | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         TestPage::class, | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         TestWidget::class, | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     ); | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public function testWidgetFormRendering() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $page = $this->objFromFixture(TestPage::class, 'page1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $page->copyVersionToStage('Stage', 'Live'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $widget = $this->objFromFixture(TestWidget::class, 'widget1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $response = $this->get($page->URLSegment); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $formAction = sprintf('%s/widget/%d/Form', $page->URLSegment, $widget->ID); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $this->assertContains( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             $formAction, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             $response->getBody(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             "Widget forms are rendered through WidgetArea templates" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     public function testWidgetFormSubmission() | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         $page = $this->objFromFixture(TestPage::class, 'page1'); | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         $page->copyVersionToStage('Stage', 'Live'); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         $widget = $this->objFromFixture(TestWidget::class, 'widget1'); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         $response = $this->get($page->URLSegment); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $response = $this->submitForm('Form_Form', null, array('TestValue' => 'Updated')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $this->assertContains( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             'TestValue: Updated', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             $response->getBody(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             "Form values are submitted to correct widget form" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $this->assertContains( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             sprintf('Widget ID: %d', $widget->ID), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             $response->getBody(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             "Widget form acts on correct widget, as identified in the URL" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 67 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |  | 
            
                        
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.