|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
4
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
|
5
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
|
6
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
|
7
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|
8
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace TwitterWidgetsTest\Timeline; |
|
12
|
|
|
|
|
13
|
|
|
use ReflectionClass; |
|
14
|
|
|
use TwitterWidgets\Options\WidgetOptions; |
|
15
|
|
|
use TwitterWidgets\Timeline\TimelineBuilder; |
|
16
|
|
|
use TwitterWidgetsTest\Assets\OptionsProvider; |
|
17
|
|
|
|
|
18
|
|
|
class TimelineBuilderTest extends OptionsProvider |
|
19
|
|
|
{ |
|
20
|
|
|
protected $widgetOptions; |
|
21
|
|
|
|
|
22
|
|
|
protected function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->widgetOptions = new WidgetOptions($this->arrayProvider()[0][0]); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testUserTimeline() |
|
28
|
|
|
{ |
|
29
|
|
|
$widgetOptions = $this->createMock(WidgetOptions::class); |
|
30
|
|
|
$timelineBuilder = new TimelineBuilder($widgetOptions); |
|
31
|
|
|
|
|
32
|
|
|
$this->assertInstanceOf(TimelineBuilder::class, $timelineBuilder); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testWidgetRenderingWithJs() |
|
36
|
|
|
{ |
|
37
|
|
|
$timelineBuilder = $this |
|
38
|
|
|
->getMockBuilder(TimelineBuilder::class) |
|
39
|
|
|
->disableOriginalConstructor() |
|
40
|
|
|
->setMethods(['filterAttr', 'getSingleWidgetJs']) |
|
41
|
|
|
->getMock(); |
|
42
|
|
|
|
|
43
|
|
|
$timelineBuilder |
|
44
|
|
|
->expects($this->once()) |
|
45
|
|
|
->method('filterAttr') |
|
46
|
|
|
->willReturn([]); |
|
47
|
|
|
|
|
48
|
|
|
$timelineBuilder |
|
49
|
|
|
->expects($this->once()) |
|
50
|
|
|
->method('getSingleWidgetJs') |
|
51
|
|
|
->willReturn('achievement unlocked!'); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertGreaterThan(0, strpos($timelineBuilder->renderWidget(), 'achievement unlocked!')); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testWidgetRenderingWithoutJs() |
|
57
|
|
|
{ |
|
58
|
|
|
$timelineBuilder = $this |
|
59
|
|
|
->getMockBuilder(TimelineBuilder::class) |
|
60
|
|
|
->disableOriginalConstructor() |
|
61
|
|
|
->setMethods(['filterAttr', 'getSingleWidgetJs']) |
|
62
|
|
|
->getMock(); |
|
63
|
|
|
|
|
64
|
|
|
$timelineBuilder |
|
65
|
|
|
->expects($this->once()) |
|
66
|
|
|
->method('filterAttr') |
|
67
|
|
|
->willReturn([]); |
|
68
|
|
|
|
|
69
|
|
|
$timelineBuilder |
|
70
|
|
|
->expects($this->never()) |
|
71
|
|
|
->method('getSingleWidgetJs') |
|
72
|
|
|
->willReturn('achievement unlocked!'); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertEquals(0, strpos($timelineBuilder->renderWidget(false), 'achievement unlocked!')); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testUnsetValuesAreNotRendered() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->widgetOptions->setClass(null); |
|
80
|
|
|
$timelineBuilder = new TimelineBuilder($this->widgetOptions); |
|
81
|
|
|
|
|
82
|
|
|
$this->assertEquals(0, strpos($timelineBuilder->renderWidget(false), 'class="customClass"')); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @expectedException \InvalidArgumentException |
|
87
|
|
|
*/ |
|
88
|
|
|
public function testNonBoolThrowException() |
|
89
|
|
|
{ |
|
90
|
|
|
$widgetOptions = $this->createMock(WidgetOptions::class); |
|
91
|
|
|
$timelineBuilder = new TimelineBuilder($widgetOptions); |
|
92
|
|
|
|
|
93
|
|
|
$timelineBuilder->renderWidget('helloyesthisisdog'); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function testOneTimeJsReturnsNeededCode() |
|
97
|
|
|
{ |
|
98
|
|
|
$widgetOptions = $this->createMock(WidgetOptions::class); |
|
99
|
|
|
$timelineBuilder = new TimelineBuilder($widgetOptions); |
|
100
|
|
|
|
|
101
|
|
|
$reflected = new ReflectionClass(TimelineBuilder::class); |
|
102
|
|
|
$method = $reflected->getMethod('getSingleWidgetJs'); |
|
103
|
|
|
$method->setAccessible(true); |
|
104
|
|
|
|
|
105
|
|
|
$this->assertGreaterThan(0, strpos($method->invokeArgs($timelineBuilder, []), 'widgets.js')); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: