| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Tests for the AddonBuilder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @package mysite | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @coversDefaultClass AddonBuilder | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 8 |  |  | class AddonBuilderTest extends SapphireTest | 
            
                                                                        
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  |      * @var AddonBuilder | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |     protected $builder; | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      * Get the test subject | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     public function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         parent::setUp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         // Partially mocked as we don't care about the PackagistService at this point | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $this->builder = $this->getMockBuilder('AddonBuilder') | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             ->setMethods(null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             ->getMock(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |      * Test that the GitHub-ness of an addon's repository can be correctly established | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      * @param string $repository | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      * @param bool   $expected | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      * @covers ::hasGitHubRepository | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      * @dataProvider hasGitHubProvider | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     public function testHasGitHubRepository($repository, $expected) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $addon = Addon::create(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $addon->Repository = $repository; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $result = $this->builder->hasGitHubRepository($addon); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->assertSame($expected, $result); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |      * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function hasGitHubProvider() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 'https://github.com/silverstripe/silverstripe-framework', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                 true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 'https://bitbucket.org/some/otherrepo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |      * Test that we can determine the differece between a relative-ish URI and one that isn't, so we know | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |      * when to insert the GitHub repository URL into the mix. | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |      * @param string $uri | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |      * @param bool   $expected | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |      * @covers ::isRelativeUri | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |      * @dataProvider uriProvider() | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     public function testIsRelativeUri($uri, $expected) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->assertSame($expected, $this->builder->isRelativeUri($uri)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |      * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     public function uriProvider() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             array('/add-ons/silverstripe/sapphire#-preview', false), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             array('#installation-with-composer', false), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             array('resources/example.png?raw=true', true), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             array('add-ons/silverstripe/sapphire#usage', true), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             array('//add-ons/silverstripe/sapphire#usage', false), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             array('https://silverstripe.mit-license.org/', false), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             array('http://silverstripe.mit-license.org/', false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |      * Ensure that a HTML readme can have its relative links rewritten according to the Addon is belongs to | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |      * @covers ::replaceRelativeLinks | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     public function testRewriteRelativeLinksAndImages() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $addon = Addon::create(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $addon->Repository = 'https://github.com/silverstripe/silverstripe-framework'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $input = <<<HTML | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | <h1>Heading</h1> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | <p><a href="relative">Relative</a> and <a href="//absolute.com">absolute</a>.</p> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | <p><img src="relative.png"><img src="https://www.whatever.com/image.png"></p> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | HTML; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $expected = <<<HTML | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | <h1>Heading</h1> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | <p><a href="https://github.com/silverstripe/silverstripe-framework/blob/master/relative">Relative</a> and <a href="//absolute.com">absolute</a>.</p> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | <p><img src="https://github.com/silverstripe/silverstripe-framework/raw/master/relative.png"><img src="https://www.whatever.com/image.png"></p> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | HTML; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $this->assertSame($expected, $this->builder->replaceRelativeLinks($addon, $input)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 120 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 121 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 122 |  |  |  | 
            
                        
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.