Skip to content

Commit

Permalink
Updating Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed May 22, 2015
1 parent f7003b7 commit c3bf50e
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 122 deletions.
21 changes: 2 additions & 19 deletions tests/Laravel/FacadeTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php namespace Arcanedev\NoCaptcha\Tests\Laravel;

use Arcanedev\NoCaptcha\Laravel\Facade as NoCaptcha;

use Arcanedev\NoCaptcha\Tests\LaravelTestCase;

class FacadeTest extends LaravelTestCase
Expand All @@ -24,10 +23,8 @@ public function tearDown()
| Test Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* @test
*/
public function testCanRenderScriptTag()
/** @test */
public function it_can_render_script_tag()
{
$this->assertEquals(
$this->getScriptTag(),
Expand All @@ -38,20 +35,6 @@ public function testCanRenderScriptTag()
$this->assertEmpty(NoCaptcha::script());
}

/**
* @test
*/
public function testCanRenderScriptTagBasedOnAppLocale()
{
$locale = 'fr';
$this->app['config']->set('app.locale', $locale);

$this->assertEquals(
$this->getScriptTag('fr'),
NoCaptcha::script()
);
}

/* ------------------------------------------------------------------------------------------------
| Other Functions
| ------------------------------------------------------------------------------------------------
Expand Down
6 changes: 2 additions & 4 deletions tests/Laravel/FormMacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ public function tearDown()
| Test Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* @test
*/
public function testCanRenderCaptcha()
/** @test */
public function it_can_render_captcha()
{
$captcha = $this->app['form']->captcha();

Expand Down
6 changes: 2 additions & 4 deletions tests/Laravel/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ public function tearDown()
| Test Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* @test
*/
public function testCanGetWhatHeProvides()
/** @test */
public function it_can_get_what_he_provides()
{
// This is for 100% code converge
$this->assertEquals([
Expand Down
22 changes: 8 additions & 14 deletions tests/Laravel/ValidatorRuleTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php namespace Arcanedev\NoCaptcha\Tests\Laravel;

use Arcanedev\NoCaptcha\Laravel\Facade as NoCaptcha;
use Arcanedev\NoCaptcha\Tests\LaravelTestCase;
use Mockery as m;

Expand Down Expand Up @@ -37,10 +36,8 @@ public function tearDown()
| Test Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* @test
*/
public function testCanPassCaptchaRule()
/** @test */
public function it_can_passes_captcha_rule()
{
$this->mockRequest([
'success' => true
Expand All @@ -56,10 +53,8 @@ public function testCanPassCaptchaRule()
$this->assertFalse($validator->fails());
}

/**
* @test
*/
public function testCanFailCaptchaRule()
/** @test */
public function it_can_fails_captcha_rule()
{
$this->mockRequest([
'success' => false,
Expand All @@ -69,6 +64,7 @@ public function testCanFailCaptchaRule()
$data = [
'g-recaptcha-response' => 'google-recaptcha-response',
];

$rules = [
'g-recaptcha-response' => 'required|captcha',
];
Expand All @@ -87,10 +83,8 @@ public function testCanFailCaptchaRule()
);
}

/**
* @test
*/
public function testCanFailCaptchaRuleWithMessages()
/** @test */
public function it_can_fail_captcha_rule_with_messages()
{
$this->mockRequest([
'success' => false,
Expand Down Expand Up @@ -127,7 +121,7 @@ public function testCanFailCaptchaRuleWithMessages()
*/
private function mockRequest($returns)
{
$request = m::mock('Arcanedev\NoCaptcha\Utilities\Request');
$request = m::mock('Arcanedev\\NoCaptcha\\Utilities\\Request');
$request->shouldReceive('send')->andReturn($returns);

$captcha = $this->app['arcanedev.no-captcha']->setRequestClient($request);
Expand Down
104 changes: 60 additions & 44 deletions tests/NoCaptchaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@

class NoCaptchaTest extends TestCase
{
/* ------------------------------------------------------------------------------------------------
| Constants
| ------------------------------------------------------------------------------------------------
*/
const NO_CAPTCHA_CLASS = 'Arcanedev\\NoCaptcha\\NoCaptcha';

/* ------------------------------------------------------------------------------------------------
| Properties
| ------------------------------------------------------------------------------------------------
*/
/** @var NoCaptcha */
private $noCaptcha;

const NO_CAPTCHA_CLASS = 'Arcanedev\\NoCaptcha\\NoCaptcha';

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
Expand All @@ -36,10 +40,8 @@ public function tearDown()
| Test Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* @test
*/
public function testCanBeInstantiated()
/** @test */
public function it_can_be_instantiated()
{
$this->assertInstanceOf(self::NO_CAPTCHA_CLASS, $this->noCaptcha);
}
Expand All @@ -50,7 +52,7 @@ public function testCanBeInstantiated()
* @expectedException \Arcanedev\NoCaptcha\Exceptions\InvalidTypeException
* @expectedExceptionMessage The secret key must be a string value, NULL given
*/
public function testMustThrowInvalidTypeExceptionOnSecretKey()
public function it_must_throw_invalid_type_exception_on_secret_key()
{
new NoCaptcha(null, null);
}
Expand All @@ -61,7 +63,7 @@ public function testMustThrowInvalidTypeExceptionOnSecretKey()
* @expectedException \Arcanedev\NoCaptcha\Exceptions\ApiException
* @expectedExceptionMessage The secret key must not be empty
*/
public function testMustThrowApiExceptionOnEmptySecretKey()
public function it_must_throw_api_exception_on_empty_secret_key()
{
new NoCaptcha(' ', null);
}
Expand All @@ -72,7 +74,7 @@ public function testMustThrowApiExceptionOnEmptySecretKey()
* @expectedException \Arcanedev\NoCaptcha\Exceptions\InvalidTypeException
* @expectedExceptionMessage The site key must be a string value, NULL given
*/
public function testMustThrowInvalidTypeExceptionOnSiteKey()
public function it_must_throw_invalid_type_exception_on_site_key()
{
new NoCaptcha('secret', null);
}
Expand All @@ -83,15 +85,13 @@ public function testMustThrowInvalidTypeExceptionOnSiteKey()
* @expectedException \Arcanedev\NoCaptcha\Exceptions\ApiException
* @expectedExceptionMessage The site key must not be empty
*/
public function testMustThrowApiExceptionOnEmptySiteKey()
public function it_must_throw_api_exception_on_empty_site_key()
{
new NoCaptcha('secret', ' ');
}

/**
* @test
*/
public function testCanRenderScriptTag()
/** @test */
public function it_can_render_script_tag()
{
$tag = '<script src="' . NoCaptcha::CLIENT_URL . '" async defer></script>';

Expand All @@ -101,32 +101,58 @@ public function testCanRenderScriptTag()
$this->assertEmpty($this->noCaptcha->script());
}

/**
* @test
*/
public function testCanRenderScriptTagWithLang()
/** @test */
public function it_can_render_script_tag_with_lang()
{
$lang = 'fr';
$tag = '<script src="' . NoCaptcha::CLIENT_URL . '?hl=' . $lang . '" async defer></script>';
$tag = '<script src="' . NoCaptcha::CLIENT_URL . '?hl=' . $lang . '" async defer></script>';

$this->noCaptcha = $this->createCaptcha($lang);

$this->assertEquals($tag, $this->noCaptcha->script());

// Echo out only once
// Not even twice
$this->assertEmpty($this->noCaptcha->script());
}

/**
* @test
*/
public function testCanDisplayCaptcha()
/** @test */
public function it_can_render_script_with_callback()
{
$captchas = ['captcha-1', 'captcha-2'];
$script =
'<script src="' . NoCaptcha::CLIENT_URL . '?onload=CaptchaCallback&render=explicit" async defer></script>
<script>
var CaptchaCallback = function(){
grecaptcha.render(\'captcha-1\', {\'sitekey\' : \'site-key\'});
grecaptcha.render(\'captcha-2\', {\'sitekey\' : \'site-key\'});
};
</script>';

$this->assertEquals(
array_map('trim', preg_split('/\r\n|\r|\n/', $script)),
array_map('trim', preg_split('/\r\n|\r|\n/', $this->noCaptcha->scriptWithCallback($captchas)))
);

// Not even twice
$this->assertEmpty($this->noCaptcha->script());
$this->assertEmpty($this->noCaptcha->scriptWithCallback($captchas));
}

/** @test */
public function it_can_display_captcha()
{
$this->assertEquals(
'<div class="g-recaptcha" data-sitekey="site-key"></div>',
$this->noCaptcha->display()
);

$this->assertEquals(
'<div class="g-recaptcha" data-sitekey="site-key" id="captcha-1"></div>',
$this->noCaptcha->display([
'id' => 'captcha-1'
])
);

$this->assertEquals(
'<div class="g-recaptcha" data-sitekey="site-key" data-type="image" data-theme="light"></div>',
$this->noCaptcha->display([
Expand All @@ -144,10 +170,8 @@ public function testCanDisplayCaptcha()
);
}

/**
* @test
*/
public function testCanDisplayImageCaptcha()
/** @test */
public function it_can_display_image_captcha()
{
$this->assertEquals(
'<div class="g-recaptcha" data-sitekey="site-key" data-type="image"></div>',
Expand Down Expand Up @@ -177,9 +201,7 @@ public function testCanDisplayImageCaptcha()
);
}

/**
* @test
*/
/** @test */
public function testCanDisplayAudioCaptcha()
{
$this->assertEquals(
Expand Down Expand Up @@ -210,10 +232,8 @@ public function testCanDisplayAudioCaptcha()
);
}

/**
* @test
*/
public function testCanDisplayCaptchaWithDefaults()
/** @test */
public function it_can_display_captcha_with_defaults()
{
$this->assertEquals(
'<div class="g-recaptcha" data-sitekey="site-key" data-type="image"></div>',
Expand Down Expand Up @@ -244,10 +264,8 @@ public function testCanDisplayCaptchaWithDefaults()
);
}

/**
* @test
*/
public function testCanVerify()
/** @test */
public function it_can_verify()
{
$request = m::mock('Arcanedev\NoCaptcha\Utilities\Request');
$request->shouldReceive('send')->andReturn([
Expand All @@ -261,10 +279,8 @@ public function testCanVerify()
$this->assertTrue($passes);
}

/**
* @test
*/
public function testCanVerifyButFails()
/** @test */
public function it_can_verify_with_fails()
{
$passes = $this->noCaptcha->verify('');

Expand Down Expand Up @@ -298,4 +314,4 @@ private function createCaptcha($lang = null)
{
return new NoCaptcha('secret-key', 'site-key', $lang);
}
}
}
4 changes: 3 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php namespace Arcanedev\NoCaptcha\Tests;

abstract class TestCase extends \PHPUnit_Framework_TestCase
use PHPUnit_Framework_TestCase;

abstract class TestCase extends PHPUnit_Framework_TestCase
{
/* ------------------------------------------------------------------------------------------------
| Main Functions
Expand Down
Loading

0 comments on commit c3bf50e

Please sign in to comment.