Skip to content

Commit

Permalink
Fix tests and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
marekgach committed Mar 11, 2020
1 parent a9dbb61 commit 3d26005
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
24 changes: 11 additions & 13 deletions tests/ChatGeneratorTest.php
Expand Up @@ -192,19 +192,7 @@ public function test_render_simple()
$this->chat->setKey('XYZ123456');
$ret = $this->chat->render();

$expected = "<script type=\"text/javascript\">
var _smartsupp = _smartsupp || {};
_smartsupp.key = 'XYZ123456';
window.smartsupp||(function(d) {
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
c.type='text/javascript';c.charset='utf-8';c.async=true;
c.src='//www.smartsuppchat.com/loader.js';s.parentNode.insertBefore(c,s);
})(document);
</script>";

$this->assertEquals($expected, $ret);
$this->assertEquals(file_get_contents(dirname(__FILE__) . '/chat_code_simple.txt'), $ret);
}

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

public function test_render_async()
{
$this->chat->setKey('XYZ123456');
$this->chat->setAsync();
$this->chat->setAsyncDelay(2500);
$ret = $this->chat->render();

$this->assertEquals(file_get_contents(dirname(__FILE__) . '/chat_code_async.txt'), $ret);
}

public function test_render_allParams()
{
$this->chat->setKey('XYZ123456');
Expand Down
8 changes: 4 additions & 4 deletions tests/chat_code.txt
@@ -1,6 +1,6 @@
<script type="text/javascript">
var _smartsupp = _smartsupp || {};
_smartsupp.key = 'XYZ123456';
var _smartsupp = _smartsupp || {};
_smartsupp.key = 'XYZ123456';
_smartsupp.cookieDomain = '.foo.bar';
_smartsupp.sendEmailTanscript = false;
_smartsupp.ratingEnabled = true; // by default false
Expand All @@ -16,11 +16,11 @@ _smartsupp.gaKey = 'UA-123456';
_smartsupp.gaOptions = {'cookieDomain': '.foo.bar'};
_smartsupp.hideWidget = true;
window.smartsupp||(function(d) {
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
c.type='text/javascript';c.charset='utf-8';c.async=true;
c.src='//www.smartsuppchat.com/loader.js';s.parentNode.insertBefore(c,s);
})(document);smartsupp('email', 'johny@depp.com');
smartsupp('name', 'Johny Depp');
smartsupp('variables', {orderTotal: {label: 'Total orders', value: '150'}, lastOrder: {label: 'Last ordered', value: '2015-07-09'}});
</script>
</script>
14 changes: 14 additions & 0 deletions tests/chat_code_async.txt
@@ -0,0 +1,14 @@
<script type="text/javascript">
setTimeout(function() {
window._smartsupp = window._smartsupp || {};
var _smartsupp = window._smartsupp;
_smartsupp.key = 'XYZ123456';

window.smartsupp||(function(d) {
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
c.type='text/javascript';c.charset='utf-8';c.async=true;
c.src='//www.smartsuppchat.com/loader.js';s.parentNode.insertBefore(c,s);
})(document);
}, 2500);
</script>
11 changes: 11 additions & 0 deletions tests/chat_code_simple.txt
@@ -0,0 +1,11 @@
<script type="text/javascript">
var _smartsupp = _smartsupp || {};
_smartsupp.key = 'XYZ123456';

window.smartsupp||(function(d) {
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
c.type='text/javascript';c.charset='utf-8';c.async=true;
c.src='//www.smartsuppchat.com/loader.js';s.parentNode.insertBefore(c,s);
})(document);
</script>

0 comments on commit 3d26005

Please sign in to comment.