Commit ab06d84c authored by Marivaldo Junior's avatar Marivaldo Junior

test displaySubmit with custom data-callback; fix expected/actual order in asserts

parent 0f1d5bb7
<?php <?php
namespace Anhskohbo\NoCaptcha\Tests;
use Anhskohbo\NoCaptcha\NoCaptcha; use Anhskohbo\NoCaptcha\NoCaptcha;
class NoCaptchaTest extends PHPUnit_Framework_TestCase class NoCaptchaTest extends PHPUnit_Framework_TestCase
...@@ -23,9 +25,9 @@ class NoCaptchaTest extends PHPUnit_Framework_TestCase ...@@ -23,9 +25,9 @@ class NoCaptchaTest extends PHPUnit_Framework_TestCase
$withLang = '<script src="https://www.google.com/recaptcha/api.js?hl=vi" async defer></script>'."\n"; $withLang = '<script src="https://www.google.com/recaptcha/api.js?hl=vi" async defer></script>'."\n";
$withCallback = '<script src="https://www.google.com/recaptcha/api.js?render=explicit&onload=myOnloadCallback" async defer></script>'."\n"; $withCallback = '<script src="https://www.google.com/recaptcha/api.js?render=explicit&onload=myOnloadCallback" async defer></script>'."\n";
$this->assertEquals($this->captcha->renderJs(), $simple); $this->assertEquals($simple, $this->captcha->renderJs());
$this->assertEquals($this->captcha->renderJs('vi'), $withLang); $this->assertEquals($withLang, $this->captcha->renderJs('vi'));
$this->assertEquals($this->captcha->renderJs(null, true, 'myOnloadCallback'), $withCallback); $this->assertEquals($withCallback, $this->captcha->renderJs(null, true, 'myOnloadCallback'));
} }
public function testDisplay() public function testDisplay()
...@@ -35,8 +37,8 @@ class NoCaptchaTest extends PHPUnit_Framework_TestCase ...@@ -35,8 +37,8 @@ class NoCaptchaTest extends PHPUnit_Framework_TestCase
$simple = '<div data-sitekey="{site-key}" class="g-recaptcha"></div>'; $simple = '<div data-sitekey="{site-key}" class="g-recaptcha"></div>';
$withAttrs = '<div data-theme="light" data-sitekey="{site-key}" class="g-recaptcha"></div>'; $withAttrs = '<div data-theme="light" data-sitekey="{site-key}" class="g-recaptcha"></div>';
$this->assertEquals($this->captcha->display(), $simple); $this->assertEquals($simple, $this->captcha->display());
$this->assertEquals($this->captcha->display(['data-theme' => 'light']), $withAttrs); $this->assertEquals($withAttrs, $this->captcha->display(['data-theme' => 'light']));
} }
public function testdisplaySubmit() public function testdisplaySubmit()
...@@ -47,8 +49,18 @@ class NoCaptchaTest extends PHPUnit_Framework_TestCase ...@@ -47,8 +49,18 @@ class NoCaptchaTest extends PHPUnit_Framework_TestCase
$simple = '<button data-callback="onSubmittest" data-sitekey="{site-key}" class="g-recaptcha"><span>submit</span></button>'; $simple = '<button data-callback="onSubmittest" data-sitekey="{site-key}" class="g-recaptcha"><span>submit</span></button>';
$withAttrs = '<button data-theme="light" class="g-recaptcha 123" data-callback="onSubmittest" data-sitekey="{site-key}"><span>submit123</span></button>'; $withAttrs = '<button data-theme="light" class="g-recaptcha 123" data-callback="onSubmittest" data-sitekey="{site-key}"><span>submit123</span></button>';
$this->assertEquals($this->captcha->displaySubmit('test'), $simple . $javascript); $this->assertEquals($simple . $javascript, $this->captcha->displaySubmit('test'));
$withAttrsResult = $this->captcha->displaySubmit('test','submit123',['data-theme' => 'light', 'class' => '123']); $withAttrsResult = $this->captcha->displaySubmit('test','submit123',['data-theme' => 'light', 'class' => '123']);
$this->assertEquals($withAttrsResult, $withAttrs . $javascript); $this->assertEquals($withAttrs . $javascript, $withAttrsResult);
}
public function testdisplaySubmitWithCustomCallback()
{
$this->assertTrue($this->captcha instanceof NoCaptcha);
$withAttrs = '<button data-theme="light" class="g-recaptcha 123" data-callback="onSubmitCustomCallback" data-sitekey="{site-key}"><span>submit123</span></button>';
$withAttrsResult = $this->captcha->displaySubmit('test-custom','submit123',['data-theme' => 'light', 'class' => '123', 'data-callback' => 'onSubmitCustomCallback']);
$this->assertEquals($withAttrs, $withAttrsResult);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment