Completed
Pull Request — master (#1)
by Daryl
01:30
created

WpShareThisTest::_after()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
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')));
0 ignored issues
show
Bug introduced by
The function has_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
		$this->assertGreaterThan(0, /** @scrutinizer ignore-call */ has_action('wp_head',            array( WP_Share_This::class, '_wp_head')));
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
		/** @scrutinizer ignore-call */ 
57
  do_action('wp_enqueue_scripts');
Loading history...
57
		$this->assertTrue(wp_script_is('sharethis', 'enqueued'));
0 ignored issues
show
Bug introduced by
The function wp_script_is was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
		$this->assertTrue(/** @scrutinizer ignore-call */ wp_script_is('sharethis', 'enqueued'));
Loading history...
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);
0 ignored issues
show
Bug introduced by
The function wp_trim_excerpt was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
		$excerpt = /** @scrutinizer ignore-call */ wp_trim_excerpt($post->post_excerpt);
Loading history...
75
		$title   = $post->post_title;
76
77
		set_post_thumbnail( $post->ID, $image );
0 ignored issues
show
Bug introduced by
The function set_post_thumbnail was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
		/** @scrutinizer ignore-call */ 
78
  set_post_thumbnail( $post->ID, $image );
Loading history...
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
}