| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace CodeReview\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | class CodeReviewConfigTest extends \PHPUnit_Framework_TestCase { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | 	public function getLatestVersion($human_readable = false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | 		return $human_readable ? '11.22' : 2015062900; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 	public function pluginsGetter($type) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 		return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 			'injected_plugin', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 			'ugly_plugin' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	public function setUp() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 		$path = dirname(__FILE__) . '/test_files/fake_elgg/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 		require_once($path . 'engine/start.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		\code_review::initConfig(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 			'path' => $path, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 			'engine_path' => $path . 'engine/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 			'pluginspath' => $path . 'mod/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 			'plugins_getter' => array($this, 'pluginsGetter'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	public function testDefaultOptionsOnNoInput() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		$config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		$this->assertEquals(null, $config->getSubPath()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		$this->assertEquals('11.22', $config->getMaxVersion()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		$this->assertEquals(false, $config->isIncludeDisabledPluginsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		$this->assertEquals(true, $config->isSkipInactivePluginsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		$this->assertEquals(true, $config->isDeprecatedFunctionsTestEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		$this->assertEquals(true, $config->isPrivateFunctionsTestEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 		$this->assertEquals(false, $config->isFixProblemsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  | 	public function testDefaultOptionsOnPersingEmptyInput() { | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  | 		$config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  | 		$config->parseInput(array()); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  | 		$this->assertEquals('/', $config->getSubPath()); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | 		$this->assertEquals('11.22', $config->getMaxVersion()); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  | 		$this->assertEquals(false, $config->isIncludeDisabledPluginsEnabled()); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  | 		$this->assertEquals(true, $config->isSkipInactivePluginsEnabled()); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  | 		$this->assertEquals(true, $config->isDeprecatedFunctionsTestEnabled()); | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  | 		$this->assertEquals(true, $config->isPrivateFunctionsTestEnabled()); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  | 		$this->assertEquals(false, $config->isFixProblemsEnabled()); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	public function testDefaultOptionsOnPersingInput() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		$config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 		$config->parseInput(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			'subpath' => 'mod/fancy_plugin', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 			'version' => '10.22', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			'include_disabled_plugins' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 			'find_deprecated_functions' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 			'find_private_functions' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 			'fix_problems' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		$this->assertEquals('mod/fancy_plugin/', $config->getSubPath()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$this->assertEquals('10.22', $config->getMaxVersion()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		$this->assertEquals(false, $config->isIncludeDisabledPluginsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		$this->assertEquals(true, $config->isSkipInactivePluginsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		$this->assertEquals(true, $config->isDeprecatedFunctionsTestEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		$this->assertEquals(true, $config->isPrivateFunctionsTestEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		$this->assertEquals(false, $config->isFixProblemsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		$config->parseInput(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 			'subpath' => '//mod/fancy_plugin/../with/supprises\\not\\cool', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		$this->assertEquals('mod/fancy_plugin//with/supprises/not/cool/', $config->getSubPath()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	public function testDefaultOptionsSetOnConstructor() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		$config = new \CodeReview\Config(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 			'subpath' => 'mod/fancy_plugin', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			'subPath' => 'mod/proper_path', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 			'version' => '10.22', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 			'maxVersion' => '10.23', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 			'include_disabled_plugins' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 			'find_deprecated_functions' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 			'find_private_functions' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 			'fix_problems' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 		), array($this, 'getLatestVersion')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 		$this->assertEquals('mod/proper_path', $config->getSubPath()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		$this->assertEquals('10.23', $config->getMaxVersion()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		$this->assertEquals(false, $config->isIncludeDisabledPluginsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		$this->assertEquals(true, $config->isSkipInactivePluginsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		$this->assertEquals(true, $config->isDeprecatedFunctionsTestEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 		$this->assertEquals(true, $config->isPrivateFunctionsTestEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		$this->assertEquals(false, $config->isFixProblemsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		$config->parseInput(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 			'subpath' => '//mod/fancy_plugin/../with/supprises\\not\\cool', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 		$this->assertEquals('mod/fancy_plugin//with/supprises/not/cool/', $config->getSubPath()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 	public function testPresistenceOfOptions() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		$config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		$config->parseInput(array()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		$this->assertEquals('/', $config->getSubPath()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 		$this->assertEquals('11.22', $config->getMaxVersion()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 		$this->assertEquals(false, $config->isIncludeDisabledPluginsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		$this->assertEquals(true, $config->isSkipInactivePluginsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 		$this->assertEquals(true, $config->isDeprecatedFunctionsTestEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 		$this->assertEquals(true, $config->isPrivateFunctionsTestEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 		$this->assertEquals(false, $config->isFixProblemsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 		//change stuff | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 		$config->subPath = '//test/invalid/path'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 		$this->assertEquals('//test/invalid/path', $config->getSubPath()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 		$config->maxVersion = '10.24'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		$this->assertEquals('10.24', $config->getMaxVersion()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		$config->includeDisabledPlugins = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 		$this->assertEquals(true, $config->isIncludeDisabledPluginsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 		$this->assertEquals(false, $config->isSkipInactivePluginsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 		$config->includeDisabledPlugins = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		$this->assertEquals(false, $config->isIncludeDisabledPluginsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 		$this->assertEquals(true, $config->isSkipInactivePluginsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 		$config->findDeprecatedFunctions = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 		$this->assertEquals(true, $config->isDeprecatedFunctionsTestEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 		$config->findDeprecatedFunctions = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 		$this->assertEquals(false, $config->isDeprecatedFunctionsTestEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 		$config->findPrivateFunctions = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 		$this->assertEquals(true, $config->isPrivateFunctionsTestEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 		$config->findPrivateFunctions = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 		$this->assertEquals(false, $config->isPrivateFunctionsTestEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 		$config->fixProblems = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 		$this->assertEquals(true, $config->isFixProblemsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 		$config->fixProblems = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 		$this->assertEquals(false, $config->isFixProblemsEnabled()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 	public function testPluginsGetter() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 		$config = new \CodeReview\Config(array(), array($this, 'getLatestVersion')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 		$this->assertEquals(array('injected_plugin', 'ugly_plugin'), $config->getPluginIds($config::T_PLUGINS_ACTIVE)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 		$this->assertEquals(array('inactive_plugin'), $config->getPluginIds($config::T_PLUGINS_INACTIVE)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 		$this->assertEquals(array('inactive_plugin', 'ugly_plugin'), $config->getPluginIds($config::T_PLUGINS_ALL)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 152 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 153 |  |  |  | 
            
                        
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.