Skip to content

Commit 3d26005

Browse files
committed
Fix tests and coverage
1 parent a9dbb61 commit 3d26005

4 files changed

Lines changed: 40 additions & 17 deletions

File tree

tests/ChatGeneratorTest.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,7 @@ public function test_render_simple()
192192
$this->chat->setKey('XYZ123456');
193193
$ret = $this->chat->render();
194194

195-
$expected = "<script type=\"text/javascript\">
196-
var _smartsupp = _smartsupp || {};
197-
_smartsupp.key = 'XYZ123456';
198-
199-
window.smartsupp||(function(d) {
200-
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
201-
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
202-
c.type='text/javascript';c.charset='utf-8';c.async=true;
203-
c.src='//www.smartsuppchat.com/loader.js';s.parentNode.insertBefore(c,s);
204-
})(document);
205-
</script>";
206-
207-
$this->assertEquals($expected, $ret);
195+
$this->assertEquals(file_get_contents(dirname(__FILE__) . '/chat_code_simple.txt'), $ret);
208196
}
209197

210198
public function test_render_simpleOutput()
@@ -216,6 +204,16 @@ public function test_render_simpleOutput()
216204
$this->expectOutputRegex('/.*window.smartsupp.*/');
217205
}
218206

207+
public function test_render_async()
208+
{
209+
$this->chat->setKey('XYZ123456');
210+
$this->chat->setAsync();
211+
$this->chat->setAsyncDelay(2500);
212+
$ret = $this->chat->render();
213+
214+
$this->assertEquals(file_get_contents(dirname(__FILE__) . '/chat_code_async.txt'), $ret);
215+
}
216+
219217
public function test_render_allParams()
220218
{
221219
$this->chat->setKey('XYZ123456');

tests/chat_code.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script type="text/javascript">
2-
var _smartsupp = _smartsupp || {};
3-
_smartsupp.key = 'XYZ123456';
2+
var _smartsupp = _smartsupp || {};
3+
_smartsupp.key = 'XYZ123456';
44
_smartsupp.cookieDomain = '.foo.bar';
55
_smartsupp.sendEmailTanscript = false;
66
_smartsupp.ratingEnabled = true; // by default false
@@ -16,11 +16,11 @@ _smartsupp.gaKey = 'UA-123456';
1616
_smartsupp.gaOptions = {'cookieDomain': '.foo.bar'};
1717
_smartsupp.hideWidget = true;
1818
window.smartsupp||(function(d) {
19-
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
19+
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
2020
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
2121
c.type='text/javascript';c.charset='utf-8';c.async=true;
2222
c.src='//www.smartsuppchat.com/loader.js';s.parentNode.insertBefore(c,s);
2323
})(document);smartsupp('email', 'johny@depp.com');
2424
smartsupp('name', 'Johny Depp');
2525
smartsupp('variables', {orderTotal: {label: 'Total orders', value: '150'}, lastOrder: {label: 'Last ordered', value: '2015-07-09'}});
26-
</script>
26+
</script>

tests/chat_code_async.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script type="text/javascript">
2+
setTimeout(function() {
3+
window._smartsupp = window._smartsupp || {};
4+
var _smartsupp = window._smartsupp;
5+
_smartsupp.key = 'XYZ123456';
6+
7+
window.smartsupp||(function(d) {
8+
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
9+
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
10+
c.type='text/javascript';c.charset='utf-8';c.async=true;
11+
c.src='//www.smartsuppchat.com/loader.js';s.parentNode.insertBefore(c,s);
12+
})(document);
13+
}, 2500);
14+
</script>

tests/chat_code_simple.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script type="text/javascript">
2+
var _smartsupp = _smartsupp || {};
3+
_smartsupp.key = 'XYZ123456';
4+
5+
window.smartsupp||(function(d) {
6+
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
7+
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
8+
c.type='text/javascript';c.charset='utf-8';c.async=true;
9+
c.src='//www.smartsuppchat.com/loader.js';s.parentNode.insertBefore(c,s);
10+
})(document);
11+
</script>

0 commit comments

Comments
 (0)