|
1
|
|
|
<?php |
|
2
|
|
|
use Clubdeuce\WPShareThis\WP_Share_This; |
|
3
|
|
|
|
|
4
|
|
|
require_once dirname( dirname( __DIR__ ) ) . '/wp-share-this.php'; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class WpShareThisTest |
|
8
|
|
|
* @coversDefaultClass \Clubdeuce\WPShareThis\WP_Share_This |
|
9
|
|
|
*/ |
|
10
|
|
|
class WpShareThisTest extends \Codeception\Test\Unit |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var \UnitTester |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $tester; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var WP_UnitTest_Factory_For_Attachment |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $attachment_factory; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var WP_UnitTest_Factory_For_Post |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $post_factory; |
|
26
|
|
|
|
|
27
|
|
|
protected function _before() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->post_factory = new WP_UnitTest_Factory_For_Post(); |
|
30
|
|
|
$this->attachment_factory = new WP_UnitTest_Factory_For_Attachment(); |
|
31
|
|
|
|
|
32
|
|
|
WP_Share_This::initialize(); |
|
33
|
|
|
WP_Share_This::register_id( 'foo' ); |
|
34
|
|
|
WP_Share_This::register_service( 'facebook'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function _after() |
|
38
|
|
|
{ |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @covers ::initialize |
|
43
|
|
|
*/ |
|
44
|
|
|
public function testHooks() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->assertGreaterThan(0, has_action('wp_head', array( WP_Share_This::class, '_wp_head'))); |
|
|
|
|
|
|
47
|
|
|
$this->assertGreaterThan(0, has_action('wp_enqueue_scripts', array( WP_Share_This::class, '_wp_enqueue_scripts'))); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @covers ::_wp_enqueue_scripts |
|
52
|
|
|
* @depends testHooks |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testScriptIsRegistered() |
|
55
|
|
|
{ |
|
56
|
|
|
do_action('wp_enqueue_scripts'); |
|
|
|
|
|
|
57
|
|
|
$this->assertTrue(wp_script_is('sharethis', 'enqueued')); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @covers ::the_sharing_links |
|
62
|
|
|
* @covers ::register_service |
|
63
|
|
|
* @covers ::_render_sharing_link |
|
64
|
|
|
* @covers ::_item_sharing_property |
|
65
|
|
|
* @covers ::_item_sharing_count |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testTheSharingLinks() |
|
68
|
|
|
{ |
|
69
|
|
|
/** |
|
70
|
|
|
* @var WP_Post $post |
|
71
|
|
|
*/ |
|
72
|
|
|
$post = $this->post_factory->create_and_get(); |
|
73
|
|
|
$image = $this->attachment_factory->create_upload_object(dirname(__DIR__) . '/_data/overheard-facebook.png', $post->ID); |
|
74
|
|
|
$excerpt = wp_trim_excerpt($post->post_excerpt); |
|
|
|
|
|
|
75
|
|
|
$title = $post->post_title; |
|
76
|
|
|
|
|
77
|
|
|
set_post_thumbnail( $post->ID, $image ); |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
ob_start(); |
|
80
|
|
|
WP_Share_This::the_sharing_links( $post ); |
|
81
|
|
|
|
|
82
|
|
|
$html = ob_get_clean(); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertInternalType('string', $html); |
|
85
|
|
|
$this->assertRegExp('#class="st-custom-button.*?" #', $html); |
|
86
|
|
|
$this->assertRegExp('#<div data-network="facebook".*?\>#', $html); |
|
87
|
|
|
$this->assertRegExp('#data-url="http://example\.org/\?p=[0-9]*?"#', $html); |
|
88
|
|
|
$this->assertRegExp('#data-image="http://example\.org/wp-content/uploads/[0-9]{4}/[0-9]{2}/overheard-facebook[-]*[0-9]*?\.png"#', $html); |
|
89
|
|
|
$this->assertRegExp("#data-title=\"{$title}\"#", $html); |
|
90
|
|
|
$this->assertRegExp("#data-description=\"{$excerpt}\"#", $html); |
|
91
|
|
|
$this->assertRegExp('#<span class="count"><\/span>#', $html); |
|
92
|
|
|
} |
|
93
|
|
|
} |