File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ require_once dirname (__FILE__ ) . '/TinyTestCase.php ' ;
4+
5+ /**
6+ * Tests for version consistency across plugin files.
7+ */
8+ class TinyVersionTest extends Tiny_TestCase
9+ {
10+
11+ /**
12+ * Plugin root directory path.
13+ * @var string
14+ */
15+ private $ plugin_root ;
16+
17+ /**
18+ * Set up test environment.
19+ */
20+ public function set_up ()
21+ {
22+ parent ::set_up ();
23+ $ this ->plugin_root = dirname (dirname (__DIR__ ));
24+ }
25+
26+ /**
27+ * Test that the version in readme.txt matches the version in tiny-compress-images.php.
28+ */
29+ public function test_readme_version_matches_plugin_version ()
30+ {
31+ $ plugin_file = $ this ->plugin_root . '/tiny-compress-images.php ' ;
32+ $ readme_file = $ this ->plugin_root . '/readme.txt ' ;
33+
34+ $ plugin_version = $ this ->get_version ($ plugin_file , '/Version:\s*(.+)/ ' );
35+ $ readme_version = $ this ->get_version ($ readme_file , '/Stable tag:\s*(.+)/ ' );
36+
37+ $ this ->assertEquals (
38+ $ readme_version ,
39+ $ plugin_version ,
40+ sprintf (
41+ 'readme.txt has %s but tiny-compress-images.php has version %s ' ,
42+ $ readme_version ,
43+ $ plugin_version
44+ )
45+ );
46+ }
47+
48+
49+ /**
50+ * Extract version number from a plugin file.
51+ *
52+ * @param string $file_path Path to the file
53+ * @return string|null The version number or null if not found.
54+ */
55+ private function get_version ($ file_path , $ regex )
56+ {
57+ $ content = file_get_contents ($ file_path );
58+
59+ if (preg_match ($ regex , $ content , $ matches )) {
60+ return trim ($ matches [1 ]);
61+ }
62+
63+ return null ;
64+ }
65+ }
You can’t perform that action at this time.
0 commit comments