Skip to content

Commit

Permalink
add aliases for svg images
Browse files Browse the repository at this point in the history
  • Loading branch information
agiuliano committed Jul 1, 2014
1 parent 89a698a commit e32634b
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 195 deletions.
4 changes: 2 additions & 2 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pugx_badge:
- { name: 'total', label: 'Total Downloads', route: "pugx_badge_download" }
- { name: 'latest_unstable_version', label: 'Latest Unstable Version', route: "pugx_badge_version_latest", latest: 'unstable'}
- { name: 'license', label: 'License', route: "pugx_badge_license"}
- { name: 'monthly', label: 'Monthly Downloads', route: "pugx_badge_download_type_png", type: 'monthly'}
- { name: 'daily', label: 'Daily Downloads', route: "pugx_badge_download_type_png", type: 'daily'}
- { name: 'monthly', label: 'Monthly Downloads', route: "pugx_badge_download_type", type: 'monthly'}
- { name: 'daily', label: 'Daily Downloads', route: "pugx_badge_download_type", type: 'daily'}
- { name: 'version', label: 'Version', route: "pugx_badge_version" }


Expand Down
8 changes: 7 additions & 1 deletion app/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ pugx_badge_shieldio:
host: "img.shields.io"
requirements:
vendor: "[A-Za-z0-9_.-]+"
value: "[A-Za-z0-9_.-]+"
value: "[A-Za-z0-9_.-]+"

redirects:
resource: "@PUGXBadgeBundle/Resources/config/routing/routing_redirects.yml"

aliases:
resource: "@PUGXBadgeBundle/Resources/config/routing/routing_aliases.yml"
1 change: 1 addition & 0 deletions src/PUGX/BadgeBundle/Controller/BadgeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @author Giulio De Donato <[email protected]>
* @author Leonardo Proietti <[email protected]>
* @author Simone Fumagalli <[email protected]>
* @author Andrea Giuliano <[email protected]>
*/
class BadgeController extends Controller
{
Expand Down
138 changes: 0 additions & 138 deletions src/PUGX/BadgeBundle/Controller/PngBadgeController.php

This file was deleted.

45 changes: 45 additions & 0 deletions src/PUGX/BadgeBundle/Resources/config/routing/routing_aliases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
download_svg_alias:
path: /{repository}/downloads.svg
defaults:
_controller: PUGXBadgeBundle:Badge:downloads
type: "total"
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
methods: [GET]

download_type_svg_alias:
path: /{repository}/d/{type}.svg
defaults:
_controller: PUGXBadgeBundle:Badge:downloads
type: "total"
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
type: "total|daily|monthly"
methods: [GET]

badge_version_svg_alias:
path: /{repository}/version.svg
defaults:
_controller: PUGXBadgeBundle:Badge:version
latest: "stable"
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
methods: [GET]

version_latest_svg_alias:
path: /{repository}/v/{latest}.svg
defaults:
_controller: PUGXBadgeBundle:Badge:version
latest: "stable"
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
latest: "stable|unstable"
methods: [GET]

badge_license_svg_alias:
path: /{repository}/license.svg
defaults:
_controller: PUGXBadgeBundle:Badge:license
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
methods: [GET]
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
download_png_redirect:
path: /{repository}/downloads.png
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: pugx_badge_download
permanent: true
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
methods: [GET]

download_type_png_redirect:
path: /{repository}/d/{type}.png
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: pugx_badge_download_type
permanent: true
type: "total"
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
type: "total|daily|monthly"
methods: [GET]

badge_version_png_redirect:
path: /{repository}/version.png
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: pugx_badge_version
permanent: true
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
methods: [GET]

version_latest_png_redirect:
path: /{repository}/v/{latest}.png
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: pugx_badge_version_latest
permanent: true
latest: "stable"
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
type: "stable|unstable"
methods: [GET]

badge_license_png_redirect:
path: /{repository}/license.png
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: pugx_badge_license
permanent: true
requirements:
repository: "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
methods: [GET]
52 changes: 0 additions & 52 deletions src/PUGX/BadgeBundle/Tests/Controller/PngBadgeControllerTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ public function setUp()

public function testAllAction()
{
$expectedData = '{"clip_all":{"markdown":"[![Latest Stable Version](http:\/\/localhost\/pugx\/badge-poser\/v\/stable)](https:\/\/packagist.org\/packages\/pugx\/badge-poser) [![Total Downloads](http:\/\/localhost\/pugx\/badge-poser\/downloads)](https:\/\/packagist.org\/packages\/pugx\/badge-poser) [![Latest Unstable Version](http:\/\/localhost\/pugx\/badge-poser\/v\/unstable)](https:\/\/packagist.org\/packages\/pugx\/badge-poser) [![License](http:\/\/localhost\/pugx\/badge-poser\/license)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)"},"latest_stable_version":{"markdown":"[![Latest Stable Version](http:\/\/localhost\/pugx\/badge-poser\/v\/stable)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/v\/stable"},"total":{"markdown":"[![Total Downloads](http:\/\/localhost\/pugx\/badge-poser\/downloads)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/downloads"},"latest_unstable_version":{"markdown":"[![Latest Unstable Version](http:\/\/localhost\/pugx\/badge-poser\/v\/unstable)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/v\/unstable"},"license":{"markdown":"[![License](http:\/\/localhost\/pugx\/badge-poser\/license)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/license"},"monthly":{"markdown":"[![Monthly Downloads](http:\/\/localhost\/pugx\/badge-poser\/d\/monthly.png)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/d\/monthly.png"},"daily":{"markdown":"[![Daily Downloads](http:\/\/localhost\/pugx\/badge-poser\/d\/daily.png)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/d\/daily.png"},"version":{"markdown":"[![Version](http:\/\/localhost\/pugx\/badge-poser\/version)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/version"},"repository":{"html":"pugx\/badge-poser"}}';
$expectedData = '{"clip_all":{"markdown":"[![Latest Stable Version](http:\/\/localhost\/pugx\/badge-poser\/v\/stable)](https:\/\/packagist.org\/packages\/pugx\/badge-poser) [![Total Downloads](http:\/\/localhost\/pugx\/badge-poser\/downloads)](https:\/\/packagist.org\/packages\/pugx\/badge-poser) [![Latest Unstable Version](http:\/\/localhost\/pugx\/badge-poser\/v\/unstable)](https:\/\/packagist.org\/packages\/pugx\/badge-poser) [![License](http:\/\/localhost\/pugx\/badge-poser\/license)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)"},"latest_stable_version":{"markdown":"[![Latest Stable Version](http:\/\/localhost\/pugx\/badge-poser\/v\/stable)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/v\/stable"},"total":{"markdown":"[![Total Downloads](http:\/\/localhost\/pugx\/badge-poser\/downloads)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/downloads"},"latest_unstable_version":{"markdown":"[![Latest Unstable Version](http:\/\/localhost\/pugx\/badge-poser\/v\/unstable)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/v\/unstable"},"license":{"markdown":"[![License](http:\/\/localhost\/pugx\/badge-poser\/license)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/license"},"monthly":{"markdown":"[![Monthly Downloads](http:\/\/localhost\/pugx\/badge-poser\/d\/monthly)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/d\/monthly"},"daily":{"markdown":"[![Daily Downloads](http:\/\/localhost\/pugx\/badge-poser\/d\/daily)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/d\/daily"},"version":{"markdown":"[![Version](http:\/\/localhost\/pugx\/badge-poser\/version)](https:\/\/packagist.org\/packages\/pugx\/badge-poser)","img":"http:\/\/localhost\/pugx\/badge-poser\/version"},"repository":{"html":"pugx\/badge-poser"}}';

$client = static::createClient();
static::$kernel->getContainer()->set('packagist_client', $this->packagistClient);
$client->request('GET','/snippet/all/?repository=pugx/badge-poser');
$this->assertTrue($client->getResponse()->isSuccessful());
// echo $client->getResponse()->getContent();die;
$this->assertEquals($expectedData, $client->getResponse()->getContent());
}

Expand Down
40 changes: 40 additions & 0 deletions src/PUGX/BadgeBundle/Tests/RedirectsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the badge-poser package.
*
* (c) PUGX <http://pugx.github.io/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PUGX\BadgeBundle\Tests;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class RedirectsTest extends WebTestCase
{
/**
* @dataProvider getUrlToVerify
*/
public function testOldPageShouldRedirectToNewOnes($oldUrl, $newUrl)
{
$client = static::createClient();
$client->request('GET', $oldUrl);
$this->assertTrue($client->getResponse()->isRedirect($newUrl));
$this->assertEquals(301, $client->getResponse()->getStatusCode());
}

public function getUrlToVerify()
{
return array(
array('/pugx/badge-poser/downloads.png', 'http://localhost/pugx/badge-poser/downloads'),
array('/pugx/badge-poser/d/total.png', 'http://localhost/pugx/badge-poser/d/total'),
array('/pugx/badge-poser/version.png', 'http://localhost/pugx/badge-poser/version'),
array('/pugx/badge-poser/v/unstable.png', 'http://localhost/pugx/badge-poser/v/unstable'),
array('/pugx/badge-poser/license.png', 'http://localhost/pugx/badge-poser/license'),
array('/pugx/microsoft-lover/d/total.png', 'http://localhost/pugx/microsoft-lover/d/total'),
);
}
}

0 comments on commit e32634b

Please sign in to comment.