diff --git a/docs/url-generators.md b/docs/url-generators.md index 7987117..bddf08a 100644 --- a/docs/url-generators.md +++ b/docs/url-generators.md @@ -6,6 +6,7 @@ URL generators are used to generate URLs for the packages listed in a diff: - `GitLabGenerator`: Generates URLs for GitLab repositories. Supports custom domains. - `BitbucketGenerator`: Generates URLs for Bitbucket repositories. - `DrupalGenerator`: Generates URLs for Drupal packages. +- `WordPress`: Generates URLs for WordPress plugins and themes (via [WordPress Packagist](https://wpackagist.org/)). They are chosen automatically based on the package URL or other conditions specified in `supportsPackage()` method. diff --git a/src/Url/GeneratorContainer.php b/src/Url/GeneratorContainer.php index 0d204c0..c5b610e 100644 --- a/src/Url/GeneratorContainer.php +++ b/src/Url/GeneratorContainer.php @@ -21,6 +21,7 @@ public function __construct(array $gitlabDomains = array()) new GithubGenerator(), new BitBucketGenerator(), new GitlabGenerator(), + new WordPressGenerator(), ); foreach ($gitlabDomains as $domain) { diff --git a/src/Url/WordPressGenerator.php b/src/Url/WordPressGenerator.php new file mode 100644 index 0000000..8fc1691 --- /dev/null +++ b/src/Url/WordPressGenerator.php @@ -0,0 +1,48 @@ +getName()); + } + + /** + * {@inheritdoc} + */ + public function getCompareUrl(PackageInterface $initialPackage, PackageInterface $targetPackage) + { + return null; + } + + /** + * {@inheritdoc} + */ + public function getReleaseUrl(PackageInterface $package) + { + return null; + } + + /** + * {@inheritdoc} + */ + public function getProjectUrl(PackageInterface $package) + { + preg_match('#wpackagist-(plugin|theme)/(.+)#', $package->getName(), $matches); + + if (empty($matches)) { + return null; + } + + list (, $type, $slug) = $matches; + + return sprintf('https://wordpress.org/%ss/%s', $type, $slug); + } +} diff --git a/tests/Url/WordPressGeneratorTest.php b/tests/Url/WordPressGeneratorTest.php new file mode 100644 index 0000000..5d31f06 --- /dev/null +++ b/tests/Url/WordPressGeneratorTest.php @@ -0,0 +1,70 @@ +getGenerator(); + + $this->assertFalse($generator->supportsPackage($this->getPackage('acme/package', '3.12.1'))); + $this->assertTrue($generator->supportsPackage($this->getPackage('wpackagist-plugin/my-plugin', '3.12.1'))); + $this->assertTrue($generator->supportsPackage($this->getPackage('wpackagist-theme/my-theme', '3.12.1'))); + $this->assertFalse($generator->supportsPackage($this->getPackage('acme-wpackagist-theme/my-theme', '3.12.1'))); + } + + public function releaseUrlProvider() + { + return array( + 'plugin' => array( + $this->getPackageWithSource('wpackagist-plugin/jetpack', '13.1', 'https://plugins.svn.wordpress.org/jetpack/', '13.1'), + null, + ), + 'theme' => array( + $this->getPackageWithSource('wpackagist-theme/twentytwenty', '1.7', 'https://themes.svn.wordpress.org/twentytwenty/', '1.7'), + null, + ), + ); + } + + public function projectUrlProvider() + { + return array( + 'plugin' => array( + $this->getPackageWithSource('wpackagist-plugin/jetpack', '13.1', 'https://plugins.svn.wordpress.org/jetpack/', '13.1'), + 'https://wordpress.org/plugins/jetpack', + ), + 'theme' => array( + $this->getPackageWithSource('wpackagist-theme/twentytwenty', '1.7', 'https://themes.svn.wordpress.org/twentytwenty/', '1.7'), + 'https://wordpress.org/themes/twentytwenty', + ), + ); + } + + public function compareUrlProvider() + { + return array( + 'plugin' => array( + $this->getPackageWithSource('wpackagist-plugin/jetpack', '13.1', 'https://plugins.svn.wordpress.org/jetpack/', '13.1'), + $this->getPackageWithSource('wpackagist-plugin/jetpack', '13.2', 'https://plugins.svn.wordpress.org/jetpack/', '13.2'), + null, + ), + 'theme' => array( + $this->getPackageWithSource('wpackagist-theme/twentytwenty', '1.7', 'https://themes.svn.wordpress.org/twentytwenty/', '1.7'), + $this->getPackageWithSource('wpackagist-theme/twentytwenty', '1.8', 'https://themes.svn.wordpress.org/twentytwenty/', '1.8'), + null, + ), + ); + } + + /** + * {@inheritdoc} + */ + protected function getGenerator() + { + return new WordPressGenerator(); + } +}