diff options
| -rw-r--r-- | phpBB/phpbb/event/md_exporter.php | 89 | ||||
| -rw-r--r-- | phpBB/phpbb/event/php_exporter.php | 1 | ||||
| -rw-r--r-- | tests/event/fixtures/adm/style/acp_bbcodes.html | 0 | ||||
| -rw-r--r-- | tests/event/fixtures/normal_events.md.test | 20 | ||||
| -rw-r--r-- | tests/event/md_exporter_test.php | 97 | 
5 files changed, 200 insertions, 7 deletions
diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 05e898a157..e042d0a5d1 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -157,20 +157,64 @@ class md_exporter  			}  			list($file_details, $details) = explode("\n* Since: ", $details, 2); -			list($since, $description) = explode("\n* Purpose: ", $details, 2); + +			$changed_versions = array(); +			if (strpos($details, "\n* Changed: ") !== false) +			{ +				list($since, $details) = explode("\n* Changed: ", $details, 2); +				while (strpos($details, "\n* Changed: ") !== false) +				{ +					list($changed, $details) = explode("\n* Changed: ", $details, 2); +					$changed_versions[] = $changed; +				} +				list($changed, $description) = explode("\n* Purpose: ", $details, 2); +				$changed_versions[] = $changed; +			} +			else +			{ +				list($since, $description) = explode("\n* Purpose: ", $details, 2); +				$changed_versions = array(); +			}  			$files = $this->validate_file_list($file_details);  			$since = $this->validate_since($since); +			$changes = array(); +			foreach ($changed_versions as $changed) +			{ +				list($changed_version, $changed_description) = $this->validate_changed($changed); + +				if (isset($changes[$changed_version])) +				{ +					throw new \LogicException("Duplicate change information found for event '{$this->current_event}'"); +				} + +				$changes[$changed_version] = $changed_description; +			} +			$description = trim($description, "\n") . "\n";  			if (!$this->version_is_filtered($since))  			{ -				continue; +				$is_filtered = false; +				foreach ($changes as $version => $null) +				{ +					if ($this->version_is_filtered($version)) +					{ +						$is_filtered = true; +						break; +					} +				} + +				if (!$is_filtered) +				{ +					continue; +				}  			}  			$this->events[$event_name] = array(  				'event'			=> $this->current_event,  				'files'			=> $files,  				'since'			=> $since, +				'changed'		=> $changes,  				'description'	=> $description,  			);  		} @@ -182,6 +226,7 @@ class md_exporter  	 * The version to check  	 *  	 * @param string $version +	 * @return bool  	 */  	protected function version_is_filtered($version)  	{ @@ -269,7 +314,7 @@ class md_exporter  	*/  	public function validate_since($since)  	{ -		if (!preg_match('#^\d+\.\d+\.\d+(?:-(?:a|b|RC|pl)\d+)?$#', $since)) +		if (!$this->validate_version($since))  		{  			throw new \LogicException("Invalid since information found for event '{$this->current_event}'");  		} @@ -278,6 +323,44 @@ class md_exporter  	}  	/** +	* Validate "Changed" Information +	* +	* @param string $changed +	* @return string +	* @throws \LogicException +	*/ +	public function validate_changed($changed) +	{ +		if (strpos($changed, ' ') !== false) +		{ +			list($version, $description) = explode(' ', $changed, 2); +		} +		else +		{ +			$version = $changed; +			$description = ''; +		} + +		if (!$this->validate_version($version)) +		{ +			throw new \LogicException("Invalid changed information found for event '{$this->current_event}'"); +		} + +		return array($version, $description); +	} + +	/** +	* Validate "version" Information +	* +	* @param string $version +	* @return bool True if valid, false otherwise +	*/ +	public function validate_version($version) +	{ +		return preg_match('#^\d+\.\d+\.\d+(?:-(?:a|b|RC|pl)\d+)?$#', $version); +	} + +	/**  	* Validate the files list  	*  	* @param string $file_details diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 8cffa4620f..d2ab0595c0 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -293,6 +293,7 @@ class php_exporter  	 * The version to check  	 *  	 * @param string $version +	 * @return bool  	 */  	protected function version_is_filtered($version)  	{ diff --git a/tests/event/fixtures/adm/style/acp_bbcodes.html b/tests/event/fixtures/adm/style/acp_bbcodes.html new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/event/fixtures/adm/style/acp_bbcodes.html diff --git a/tests/event/fixtures/normal_events.md.test b/tests/event/fixtures/normal_events.md.test new file mode 100644 index 0000000000..47921c4e57 --- /dev/null +++ b/tests/event/fixtures/normal_events.md.test @@ -0,0 +1,20 @@ +acp_bbcodes_actions_append +=== +* Location: adm/style/acp_bbcodes.html +* Since: 3.1.0-a3 +* Changed: 3.1.0-a4 +* Purpose: desc1 + +acp_bbcodes_actions_prepend +=== +* Location: adm/style/acp_bbcodes.html +* Since: 3.1.0-a5 +* Purpose: desc2 + +acp_bbcodes_actions_prepend2 +=== +* Location: adm/style/acp_bbcodes.html +* Since: 3.1.0-a4 +* Changed: 3.1.0-a5 Moved up +* Changed: 3.1.0-a6 Moved down +* Purpose: desc2 diff --git a/tests/event/md_exporter_test.php b/tests/event/md_exporter_test.php index 28649e4f21..d28e3d611c 100644 --- a/tests/event/md_exporter_test.php +++ b/tests/event/md_exporter_test.php @@ -11,21 +11,110 @@  *  */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +  class phpbb_event_md_exporter_test extends phpbb_test_case  { -  	static public function crawl_eventsmd_data()  	{  		return array( +			array('normal_events.md.test', null, null, array( +				'acp_bbcodes_actions_append' => array( +					'event' => 'acp_bbcodes_actions_append', +					'files' => array( +						'prosilver' => array(), +						'subsilver2' => array(), +						'adm' => array('acp_bbcodes.html'), +					), +					'since' => '3.1.0-a3', +					'changed' => array( +						'3.1.0-a4' => '', +					), +					'description' => 'desc1' . "\n", +				), +				'acp_bbcodes_actions_prepend' => array( +					'event' => 'acp_bbcodes_actions_prepend', +					'files' => array( +						'prosilver' => array(), +						'subsilver2' => array(), +						'adm' => array('acp_bbcodes.html'), +					), +					'since' => '3.1.0-a5', +					'changed' => array(), +					'description' => 'desc2' . "\n", +				), +				'acp_bbcodes_actions_prepend2' => array( +					'event' => 'acp_bbcodes_actions_prepend2', +					'files' => array( +						'prosilver' => array(), +						'subsilver2' => array(), +						'adm' => array('acp_bbcodes.html'), +					), +					'since' => '3.1.0-a4', +					'changed' => array( +						'3.1.0-a5' => 'Moved up', +						'3.1.0-a6' => 'Moved down', +					), +					'description' => 'desc2' . "\n", +				), +			)), +			array('normal_events.md.test', '3.1.0-a5', '3.1.0-a5', array( +				'acp_bbcodes_actions_prepend' => array( +					'event' => 'acp_bbcodes_actions_prepend', +					'files' => array( +						'prosilver' => array(), +						'subsilver2' => array(), +						'adm' => array('acp_bbcodes.html'), +					), +					'since' => '3.1.0-a5', +					'changed' => array(), +					'description' => 'desc2' . "\n", +				), +				'acp_bbcodes_actions_prepend2' => array( +					'event' => 'acp_bbcodes_actions_prepend2', +					'files' => array( +						'prosilver' => array(), +						'subsilver2' => array(), +						'adm' => array('acp_bbcodes.html'), +					), +					'since' => '3.1.0-a4', +					'changed' => array( +						'3.1.0-a5' => 'Moved up', +						'3.1.0-a6' => 'Moved down', +					), +					'description' => 'desc2' . "\n", +				), +			)), +		); +	} + +	/** +	 * @dataProvider crawl_eventsmd_data +	 * +	 * @param string $file +	 * @param string $min_version +	 * @param string $max_version +	 * @param array $events +	 */ +	public function test_crawl_eventsmd($file, $min_version, $max_version, $events) +	{ +		$exporter = new \phpbb\event\md_exporter(dirname(__FILE__) . '/fixtures/', null, $min_version, $max_version); +		$this->assertSame(sizeof($events), $exporter->crawl_eventsmd($file, 'adm')); +		$this->assertEquals($events, $exporter->get_events()); +	} + +	static public function crawl_phpbb_eventsmd_data() +	{ +		return array(  			array('styles'),  			array('adm'),  		);  	}  	/** -	* @dataProvider crawl_eventsmd_data -	*/ -	public function test_crawl_eventsmd($filter) +	 * @dataProvider crawl_phpbb_eventsmd_data +	 */ +	public function test_crawl_phpbb_eventsmd($filter)  	{  		global $phpbb_root_path;  		$exporter = new \phpbb\event\md_exporter($phpbb_root_path);  | 
