Skip to content

Commit

Permalink
Merge pull request #33 from rabol/master
Browse files Browse the repository at this point in the history
Implemented Pinterest
  • Loading branch information
jorenvh authored May 19, 2019
2 parents 908abca + 0715527 commit 2f0902f
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 17 deletions.
5 changes: 4 additions & 1 deletion config/laravel-share.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
'whatsapp' => [
'uri' => 'https://wa.me/?text=',
'extra' => ['mini' => 'true']
],
],
'pinterest' => [
'uri' => 'http://pinterest.com/pin/create/button/?url='
],
],

/*
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/en/laravel-share-fa4.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
'gplus' => '<li><a href=":url" class="social-button :class" id=":id"><span class="fa fa-google-plus"></span></a></li>',
'linkedin' => '<li><a href=":url" class="social-button :class" id=":id"><span class="fa fa-linkedin"></span></a></li>',
'whatsapp' => '<li><a target="_blank" href=":url" class="social-button :class" id=":id"><span class="fa fa-whatsapp"></span></a></li>',
'pinterest' => '<li><a href=":url" class="social-button :class" id=":id"><span class="fa fa-pinterest"></span></a></li>',
];

2 changes: 1 addition & 1 deletion resources/lang/en/laravel-share-fa5.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
'gplus' => '<li><a href=":url" class="social-button :class" id=":id"><span class="fab fa-google-plus-g"></span></a></li>',
'linkedin' => '<li><a href=":url" class="social-button :class" id=":id"><span class="fab fa-linkedin"></span></a></li>',
'whatsapp' => '<li><a target="_blank" href=":url" class="social-button :class" id=":id"><span class="fab fa-whatsapp"></span></a></li>',
'pinterest' => '<li><a href=":url" class="social-button :class" id=":id"><span class="fab fa-pinterest"></span></a></li>',
];

14 changes: 14 additions & 0 deletions src/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,20 @@ public function linkedin($summary = '')
return $this;
}

/**
* Pinterest share link
*
* @return $this
*/
public function pinterest()
{
$url = config('laravel-share.services.pinterest.uri') . $this->url;

$this->buildLink('pinterest', $url);

return $this;
}

/**
* Build a single link
*
Expand Down
38 changes: 24 additions & 14 deletions tests/CombinedShareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ public function it_can_generate_generate_multiple_share_links_at_once()
->twitter()
->linkedin()
->googlePlus()
->whatsapp();

->whatsapp()
->pinterest();
/*
$expected = '<div id="social-links"><ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=https://codeswitch.be" class="social-button " id=""><span class="fa fa-facebook-official"></span></a></li><li><a href="https://twitter.com/intent/tweet?text=My+share+title&url=https://codeswitch.be" class="social-button " id=""><span class="fa fa-twitter"></span></a></li><li><a href="http://www.linkedin.com/shareArticle?mini=true&url=https://codeswitch.be&title=My+share+title&summary=" class="social-button " id=""><span class="fa fa-linkedin"></span></a></li><li><a href="https://plus.google.com/share?url=https://codeswitch.be" class="social-button " id=""><span class="fa fa-google-plus"></span></a></li><li><a target="_blank" href="https://wa.me/?text=https://codeswitch.be" class="social-button " id=""><span class="fa fa-whatsapp"></span></a></li></ul></div>';

*/
$expected = '<div id="social-links"><ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=https://codeswitch.be" class="social-button " id=""><span class="fa fa-facebook-official"></span></a></li><li><a href="https://twitter.com/intent/tweet?text=My+share+title&url=https://codeswitch.be" class="social-button " id=""><span class="fa fa-twitter"></span></a></li><li><a href="http://www.linkedin.com/shareArticle?mini=true&url=https://codeswitch.be&title=My+share+title&summary=" class="social-button " id=""><span class="fa fa-linkedin"></span></a></li><li><a href="https://plus.google.com/share?url=https://codeswitch.be" class="social-button " id=""><span class="fa fa-google-plus"></span></a></li><li><a target="_blank" href="https://wa.me/?text=https://codeswitch.be" class="social-button " id=""><span class="fa fa-whatsapp"></span></a></li><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button " id=""><span class="fa fa-pinterest"></span></a></li></ul></div>';
$this->assertEquals($expected, $result);
}

Expand All @@ -34,10 +36,10 @@ public function it_can_generate_generate_multiple_share_links_at_once_with_fa5()
->twitter()
->linkedin()
->googlePlus()
->whatsapp();

$expected = '<div id="social-links"><ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=https://codeswitch.be" class="social-button " id=""><span class="fab fa-facebook-square"></span></a></li><li><a href="https://twitter.com/intent/tweet?text=My+share+title&url=https://codeswitch.be" class="social-button " id=""><span class="fab fa-twitter"></span></a></li><li><a href="http://www.linkedin.com/shareArticle?mini=true&url=https://codeswitch.be&title=My+share+title&summary=" class="social-button " id=""><span class="fab fa-linkedin"></span></a></li><li><a href="https://plus.google.com/share?url=https://codeswitch.be" class="social-button " id=""><span class="fab fa-google-plus-g"></span></a></li><li><a target="_blank" href="https://wa.me/?text=https://codeswitch.be" class="social-button " id=""><span class="fab fa-whatsapp"></span></a></li></ul></div>';
->whatsapp()
->pinterest();

$expected ='<div id="social-links"><ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=https://codeswitch.be" class="social-button " id=""><span class="fab fa-facebook-square"></span></a></li><li><a href="https://twitter.com/intent/tweet?text=My+share+title&url=https://codeswitch.be" class="social-button " id=""><span class="fab fa-twitter"></span></a></li><li><a href="http://www.linkedin.com/shareArticle?mini=true&url=https://codeswitch.be&title=My+share+title&summary=" class="social-button " id=""><span class="fab fa-linkedin"></span></a></li><li><a href="https://plus.google.com/share?url=https://codeswitch.be" class="social-button " id=""><span class="fab fa-google-plus-g"></span></a></li><li><a target="_blank" href="https://wa.me/?text=https://codeswitch.be" class="social-button " id=""><span class="fab fa-whatsapp"></span></a></li><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button " id=""><span class="fab fa-pinterest"></span></a></li></ul></div>';
$this->assertEquals($expected, $result);
}

Expand All @@ -51,8 +53,10 @@ public function it_can_generate_multiple_share_links_at_once_and_multiple_times_
->twitter()
->linkedin()
->googlePlus()
->whatsapp();
$expected = '<div id="social-links"><ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=https://codeswitch.be" class="social-button " id=""><span class="fa fa-facebook-official"></span></a></li><li><a href="https://twitter.com/intent/tweet?text=My+share+title&url=https://codeswitch.be" class="social-button " id=""><span class="fa fa-twitter"></span></a></li><li><a href="http://www.linkedin.com/shareArticle?mini=true&url=https://codeswitch.be&title=My+share+title&summary=" class="social-button " id=""><span class="fa fa-linkedin"></span></a></li><li><a href="https://plus.google.com/share?url=https://codeswitch.be" class="social-button " id=""><span class="fa fa-google-plus"></span></a></li><li><a target="_blank" href="https://wa.me/?text=https://codeswitch.be" class="social-button " id=""><span class="fa fa-whatsapp"></span></a></li></ul></div>';
->whatsapp()
->pinterest();

$expected = '<div id="social-links"><ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=https://codeswitch.be" class="social-button " id=""><span class="fa fa-facebook-official"></span></a></li><li><a href="https://twitter.com/intent/tweet?text=My+share+title&url=https://codeswitch.be" class="social-button " id=""><span class="fa fa-twitter"></span></a></li><li><a href="http://www.linkedin.com/shareArticle?mini=true&url=https://codeswitch.be&title=My+share+title&summary=" class="social-button " id=""><span class="fa fa-linkedin"></span></a></li><li><a href="https://plus.google.com/share?url=https://codeswitch.be" class="social-button " id=""><span class="fa fa-google-plus"></span></a></li><li><a target="_blank" href="https://wa.me/?text=https://codeswitch.be" class="social-button " id=""><span class="fa fa-whatsapp"></span></a></li><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button " id=""><span class="fa fa-pinterest"></span></a></li></ul></div>';

$this->assertEquals($expected, $result);

Expand All @@ -76,8 +80,10 @@ public function it_can_generate_multiple_share_links_at_once_and_multiple_times_
->twitter()
->linkedin()
->googlePlus()
->whatsapp();
$expected = '<div id="social-links"><ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=https://codeswitch.be" class="social-button " id=""><span class="fab fa-facebook-square"></span></a></li><li><a href="https://twitter.com/intent/tweet?text=My+share+title&url=https://codeswitch.be" class="social-button " id=""><span class="fab fa-twitter"></span></a></li><li><a href="http://www.linkedin.com/shareArticle?mini=true&url=https://codeswitch.be&title=My+share+title&summary=" class="social-button " id=""><span class="fab fa-linkedin"></span></a></li><li><a href="https://plus.google.com/share?url=https://codeswitch.be" class="social-button " id=""><span class="fab fa-google-plus-g"></span></a></li><li><a target="_blank" href="https://wa.me/?text=https://codeswitch.be" class="social-button " id=""><span class="fab fa-whatsapp"></span></a></li></ul></div>';
->whatsapp()
->pinterest();

$expected = '<div id="social-links"><ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=https://codeswitch.be" class="social-button " id=""><span class="fab fa-facebook-square"></span></a></li><li><a href="https://twitter.com/intent/tweet?text=My+share+title&url=https://codeswitch.be" class="social-button " id=""><span class="fab fa-twitter"></span></a></li><li><a href="http://www.linkedin.com/shareArticle?mini=true&url=https://codeswitch.be&title=My+share+title&summary=" class="social-button " id=""><span class="fab fa-linkedin"></span></a></li><li><a href="https://plus.google.com/share?url=https://codeswitch.be" class="social-button " id=""><span class="fab fa-google-plus-g"></span></a></li><li><a target="_blank" href="https://wa.me/?text=https://codeswitch.be" class="social-button " id=""><span class="fab fa-whatsapp"></span></a></li><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button " id=""><span class="fab fa-pinterest"></span></a></li></ul></div>';

$this->assertEquals($expected, $result);

Expand All @@ -98,9 +104,10 @@ public function it_can_generate_generate_multiple_share_links_at_once_with_extra
$result = ShareFacade::page('https://codeswitch.be', 'My share title', ['class' => 'my-class', 'id' => 'my-id'], '<ul>', '</ul>')
->facebook()
->twitter()
->whatsapp();
->whatsapp()
->pinterest();

$expected = '<ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fa fa-facebook-official"></span></a></li><li><a href="https://twitter.com/intent/tweet?text=My+share+title&url=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fa fa-twitter"></span></a></li><li><a target="_blank" href="https://wa.me/?text=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fa fa-whatsapp"></span></a></li></ul>';
$expected = '<ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fa fa-facebook-official"></span></a></li><li><a href="https://twitter.com/intent/tweet?text=My+share+title&url=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fa fa-twitter"></span></a></li><li><a target="_blank" href="https://wa.me/?text=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fa fa-whatsapp"></span></a></li><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fa fa-pinterest"></span></a></li></ul>';

$this->assertEquals($expected, $result);
}
Expand All @@ -114,10 +121,13 @@ public function it_can_generate_generate_multiple_share_links_at_once_with_extra
$result = ShareFacade::page('https://codeswitch.be', 'My share title', ['class' => 'my-class', 'id' => 'my-id'], '<ul>', '</ul>')
->facebook()
->twitter()
->whatsapp();
->whatsapp()
->pinterest();

$expected = '<ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fab fa-facebook-square"></span></a></li><li><a href="https://twitter.com/intent/tweet?text=My+share+title&url=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fab fa-twitter"></span></a></li><li><a target="_blank" href="https://wa.me/?text=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fab fa-whatsapp"></span></a></li></ul>';

$expected = '<ul><li><a href="https://www.facebook.com/sharer/sharer.php?u=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fab fa-facebook-square"></span></a></li><li><a href="https://twitter.com/intent/tweet?text=My+share+title&url=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fab fa-twitter"></span></a></li><li><a target="_blank" href="https://wa.me/?text=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fab fa-whatsapp"></span></a></li><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fab fa-pinterest"></span></a></li></ul>';

$this->assertEquals($expected, $result);
}
}
}
131 changes: 131 additions & 0 deletions tests/PinterestShareTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

namespace Jorenvh\Share\Test;

use Jorenvh\Share\ShareFacade;

class PinterestShareTest extends TestCase
{
/**
* @test
*/
public function it_can_generate_a_pinterest_share_link()
{
$result = ShareFacade::page('https://codeswitch.be')->pinterest();
$expected = '<div id="social-links"><ul><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button " id=""><span class="fa fa-pinterest"></span></a></li></ul></div>';

$this->assertEquals($expected, $result);
}

/**
* @test
*/
public function it_can_generate_a_pinterest_share_link_with_fa5()
{
config(['laravel-share.fontAwesomeVersion' => 5]);
$result = ShareFacade::page('https://codeswitch.be')->pinterest();
$expected = '<div id="social-links"><ul><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button " id=""><span class="fab fa-pinterest"></span></a></li></ul></div>';

$this->assertEquals($expected, $result);
}

/**
* @test
*/
public function it_can_generate_a_pinterest_share_link_with_a_custom_class()
{
$result = ShareFacade::page('https://codeswitch.be', null, ['class' => 'my-class'])
->pinterest();
$expected = '<div id="social-links"><ul><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button my-class" id=""><span class="fa fa-pinterest"></span></a></li></ul></div>';

$this->assertEquals($expected, $result);
}

/**
* @test
*/
public function it_can_generate_a_pinterest_share_link_with_a_custom_class_with_fa5()
{
config(['laravel-share.fontAwesomeVersion' => 5]);
$result = ShareFacade::page('https://codeswitch.be', null, ['class' => 'my-class'])
->pinterest();
$expected = '<div id="social-links"><ul><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button my-class" id=""><span class="fab fa-pinterest"></span></a></li></ul></div>';

$this->assertEquals($expected, $result);
}

/**
* @test
*/
public function it_can_generate_a_pinterest_share_link_with_a_custom_class_and_custom_id()
{
$result = ShareFacade::page('https://codeswitch.be', null, ['class' => 'my-class', 'id' => 'my-id'])
->pinterest();
$expected = '<div id="social-links"><ul><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fa fa-pinterest"></span></a></li></ul></div>';

$this->assertEquals($expected, $result);
}

/**
* @test
*/
public function it_can_generate_a_pinterest_share_link_with_a_custom_class_and_custom_id_with_fa5()
{
config(['laravel-share.fontAwesomeVersion' => 5]);
$result = ShareFacade::page('https://codeswitch.be', null, ['class' => 'my-class', 'id' => 'my-id'])
->pinterest();
$expected = '<div id="social-links"><ul><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button my-class" id="my-id"><span class="fab fa-pinterest"></span></a></li></ul></div>';

$this->assertEquals($expected, $result);
}

/**
* @test
*/
public function it_can_generate_a_pinterest_share_link_with_custom_prefix_and_suffix()
{
$result = ShareFacade::page('https://codeswitch.be', null, [], '<ul>', '</ul>')
->pinterest();
$expected = '<ul><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button " id=""><span class="fa fa-pinterest"></span></a></li></ul>';

$this->assertEquals($expected, $result);
}

/**
* @test
*/
public function it_can_generate_a_pinterest_share_link_with_custom_prefix_and_suffix_with_fa5()
{
config(['laravel-share.fontAwesomeVersion' => 5]);
$result = ShareFacade::page('https://codeswitch.be', null, [], '<ul>', '</ul>')
->pinterest();
$expected = '<ul><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button " id=""><span class="fab fa-pinterest"></span></a></li></ul>';

$this->assertEquals($expected, $result);
}

/**
* @test
*/
public function it_can_generate_a_pinterest_share_link_with_all_extra_options()
{
$result = ShareFacade::page('https://codeswitch.be', 'title that is not used for fb', ['class' => 'my-class my-class2', 'id' => 'fb-share'], '<ul>', '</ul>')
->pinterest();
$expected = '<ul><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button my-class my-class2" id="fb-share"><span class="fa fa-pinterest"></span></a></li></ul>';

$this->assertEquals($expected, $result);
}

/**
* @test
*/
public function it_can_generate_a_pinterest_share_link_with_all_extra_options_fa5()
{
config(['laravel-share.fontAwesomeVersion' => 5]);
$result = ShareFacade::page('https://codeswitch.be', 'title that is not used for fb', ['class' => 'my-class my-class2', 'id' => 'fb-share'], '<ul>', '</ul>')
->pinterest();
$expected = '<ul><li><a href="http://pinterest.com/pin/create/button/?url=https://codeswitch.be" class="social-button my-class my-class2" id="fb-share"><span class="fab fa-pinterest"></span></a></li></ul>';

$this->assertEquals($expected, $result);
}
}

0 comments on commit 2f0902f

Please sign in to comment.