-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #485 from sergeyklay/2.0.x
Initial test for Gravatr
- Loading branch information
Showing
2 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
namespace Phalcon\Test\Avatar; | ||
|
||
use Phalcon\Avatar\Gravatar; | ||
use Codeception\TestCase\Test; | ||
use Phalcon\Config; | ||
use UnitTester; | ||
|
||
/** | ||
* \Phalcon\Test\Avatar\GravatarTest | ||
* Tests for Phalcon\Avatar\Gravatar component | ||
* | ||
* @copyright (c) 2011-2015 Phalcon Team | ||
* @author Serghei Iakovlev <[email protected]> | ||
* @link http://phalconphp.com/ | ||
* @package Phalcon\Test\Avatar | ||
* @group Avatar | ||
* | ||
* The contents of this file are subject to the New BSD License that is | ||
* bundled with this package in the file docs/LICENSE.txt | ||
* | ||
* If you did not receive a copy of the license and are unable to obtain it | ||
* through the world-wide-web, please send an email to [email protected] | ||
* so that we can send you a copy immediately. | ||
*/ | ||
class GravatarTest extends Test | ||
{ | ||
/** | ||
* UnitTester Object | ||
* @var UnitTester | ||
*/ | ||
protected $tester; | ||
|
||
/** | ||
* executed before each test | ||
*/ | ||
protected function _before() | ||
{ | ||
} | ||
|
||
/** | ||
* executed after each test | ||
*/ | ||
protected function _after() | ||
{ | ||
} | ||
|
||
/** | ||
* @dataProvider incorrectConfigProvider | ||
* @expectedException \InvalidArgumentException | ||
* @expectedExceptionMessage Config must be either an array or \Phalcon\Config instance | ||
* @param mixed $config | ||
*/ | ||
public function testShouldThrowExceptionIfDbIsMissingOrInvalid($config) | ||
{ | ||
new Gravatar($config); | ||
} | ||
|
||
public function incorrectConfigProvider() | ||
{ | ||
return [ | ||
'string' => [__CLASS__], | ||
'null' => [null], | ||
'true' => [true], | ||
'false' => [false], | ||
'object' => [new \stdClass()], | ||
'float' => [microtime(true)], | ||
'int' => [PHP_INT_MAX], | ||
'callable' => [function () {}], | ||
'resource' => [tmpfile()], | ||
]; | ||
} | ||
|
||
public function testShouldUseConfigInstance() | ||
{ | ||
$gravatar = new Gravatar(new Config([])); | ||
$this->assertInstanceOf('Phalcon\Avatar\Gravatar', $gravatar); | ||
} | ||
|
||
public function testShouldUseArrayAsConfig() | ||
{ | ||
$gravatar = new Gravatar([]); | ||
$this->assertInstanceOf('Phalcon\Avatar\Gravatar', $gravatar); | ||
} | ||
|
||
public function testShouldSetUseDefaultValues() | ||
{ | ||
$gravatar = new Gravatar([]); | ||
|
||
$this->assertEquals(Gravatar::RATING_G, $gravatar->getRating()); | ||
$this->assertEquals(80, $gravatar->getSize()); | ||
$this->assertNotTrue($gravatar->isUseSecureURL()); | ||
} | ||
|
||
public function testShouldSetOptionsThroughConfig() | ||
{ | ||
$gravatar = new Gravatar([ | ||
'default_image' => 'retro', | ||
'rating' => 'x', | ||
'size' => 60, | ||
'use_https' => true | ||
]); | ||
|
||
$this->assertEquals('retro', $gravatar->getDefaultImage()); | ||
$this->assertEquals(Gravatar::RATING_X, $gravatar->getRating()); | ||
$this->assertEquals(60, $gravatar->getSize()); | ||
$this->assertTrue($gravatar->isUseSecureURL()); | ||
} | ||
} |