SocialMediaHelperTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 73
c 5
b 0
f 0
dl 0
loc 116
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 4 1
A setUp() 0 8 1
A testFacebook() 0 51 2
A testTwitter() 0 35 1
1
<?php
2
App::uses('View', 'View');
3
App::uses('Helper', 'View');
4
App::uses('SocialMediaHelper', 'SocialMedia.View/Helper');
5
App::uses('Utility', 'SocialMedia.Lib');
6
7
/**
8
 * SocialMediaHelper Test Case
9
 *
10
 */
11
class SocialMediaHelperTest extends CakeTestCase {
0 ignored issues
show
Bug introduced by
The type CakeTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
/**
14
 * setUp method
15
 *
16
 * @return void
17
 */
18
	public function setUp() {
19
		parent::setUp();
20
21
		Configure::write('SocialMedia.salt', '7Nh6AmgdkBXr0afrQObG79J+gXtMXrDYTnKlQxrhoYnXMXPrj3eMLALQfyCiNsVc');
0 ignored issues
show
Bug introduced by
The type Configure was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
		Configure::write('SocialMedia.facebookAppId', 505567138750925);
23
24
		$View = new View();
0 ignored issues
show
Bug introduced by
The type View was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
		$this->SocialMedia = new SocialMediaHelper($View);
0 ignored issues
show
Bug Best Practice introduced by
The property SocialMedia does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
	}
27
28
/**
29
 * tearDown method
30
 *
31
 * @return void
32
 */
33
	public function tearDown() {
34
		unset($this->SocialMedia);
35
36
		parent::tearDown();
37
	}
38
39
	public function testFacebook() {
40
		$fullBaseUrl = Configure::read('App.fullBaseUrl') ?: FULL_BASE_URL;
0 ignored issues
show
Bug introduced by
The constant FULL_BASE_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
41
42
		// Text link
43
		$title = __d('social_media', 'Share on Facebook');
0 ignored issues
show
Bug introduced by
The function __d 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

43
		$title = /** @scrutinizer ignore-call */ __d('social_media', 'Share on Facebook');
Loading history...
44
		$urlParameters = [
45
			'link' => 'your-url',
46
			'name' => 'your-name',
47
			'caption' => 'your-caption',
48
			'description' => 'your-description',
49
			'picture' => 'your-picture',
50
			'redirect_uri' => $fullBaseUrl
51
		];
52
53
		$result = $this->SocialMedia->facebook($title, $urlParameters);
54
		$expected = '<a href="https://www.facebook.com/dialog/feed?' .
55
								'app_id=505567138750925&amp;' .
56
								'redirect_uri=' . urlencode($fullBaseUrl) . '&amp;' .
57
								'link=your-url&amp;' .
58
								'name=your-name&amp;' .
59
								'caption=your-caption&amp;' .
60
								'description=your-description&amp;' .
61
								'picture=your-picture' .
62
								'">' . __d('social_media', 'Share on Facebook') . '</a>';
63
64
		$this->assertEqual($result, $expected);
65
66
		// Image link
67
		$image = '<img title="Facebook" src="/img/facebook.png">';
68
		$urlParameters = [
69
			'link' => 'your-url',
70
			'name' => 'your-name',
71
			'caption' => 'your-caption',
72
			'description' => 'your-description',
73
			'picture' => 'your-picture',
74
			'redirect_uri' => $fullBaseUrl
75
		];
76
		$options = ['escape' => false, 'escapeTitle' => false];
77
78
		$result = $this->SocialMedia->facebook($image, $urlParameters, $options);
79
		$expected = '<a href="https://www.facebook.com/dialog/feed?' .
80
								'app_id=505567138750925&amp;' .
81
								'redirect_uri=' . urlencode($fullBaseUrl) . '&amp;' .
82
								'link=your-url&amp;' .
83
								'name=your-name&amp;' .
84
								'caption=your-caption&amp;' .
85
								'description=your-description&amp;' .
86
								'picture=your-picture' .
87
								'">' . $image . '</a>';
88
89
		$this->assertEqual($result, $expected);
90
	}
91
92
	public function testTwitter() {
93
		// Text link
94
		$title = __d('social_media', 'Share on Twitter');
0 ignored issues
show
Bug introduced by
The function __d 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

94
		$title = /** @scrutinizer ignore-call */ __d('social_media', 'Share on Twitter');
Loading history...
95
		$urlParameters = [
96
			'url' => 'your-url',
97
			'text' => 'your-text',
98
			'via' => 'your-via'
99
		];
100
101
		$result = $this->SocialMedia->twitter($title, $urlParameters);
102
		$expected = '<a href="https://twitter.com/share?' .
103
								'url=your-url&amp;' .
104
								'text=your-text&amp;' .
105
								'via=your-via' .
106
								'">' . __d('social_media', 'Share on Twitter') . '</a>';
107
108
		$this->assertEqual($result, $expected);
109
110
		// Image link
111
		$image = '<img title="Twitter" src="/img/twitter.png">';
112
		$urlParameters = [
113
			'url' => 'your-url',
114
			'text' => 'your-text',
115
			'via' => 'your-via'
116
		];
117
		$options = ['escape' => false, 'escapeTitle' => false];
118
119
		$result = $this->SocialMedia->twitter($image, $urlParameters, $options);
120
		$expected = '<a href="https://twitter.com/share?' .
121
								'url=your-url&amp;' .
122
								'text=your-text&amp;' .
123
								'via=your-via' .
124
								'">' . $image . '</a>';
125
126
		$this->assertEqual($result, $expected);
127
	}
128
129
}
130