-
Notifications
You must be signed in to change notification settings - Fork 14
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 #817 from helsingborg-stad/test/helper-color
test: helper color
- Loading branch information
Showing
3 changed files
with
138 additions
and
19 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"redefinable-internals": [ | ||
"extension_loaded" | ||
"extension_loaded", | ||
"class_exists" | ||
] | ||
} |
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 Municipio\Tests\Helper; | ||
|
||
use Mockery; | ||
use WP_Mock; | ||
use WP_Mock\Tools\TestCase; | ||
use Municipio\Helper\Color; | ||
use tad\FunctionMocker\FunctionMocker; | ||
|
||
/** | ||
* Class ColorTest | ||
*/ | ||
class ColorTest extends TestCase | ||
{ | ||
/** | ||
* @testdox prepareColor returns an rgba color when getting a correct value array. | ||
*/ | ||
public function testPrepareColorReturnsRgbaColor() | ||
{ | ||
// When | ||
$result = Color::prepareColor( | ||
[ | ||
'value' => ['#000000', '0.5'], | ||
'default' => ['color' => '#ffffff', 'alpha' => '1'], | ||
|
||
] | ||
); | ||
|
||
// Then | ||
$this->assertEquals('rgba(0, 0, 0, 0.5)', $result); | ||
} | ||
|
||
/** | ||
* @testdox prepareColor returns default values as rgba if missing value array data. | ||
*/ | ||
public function testPrepareColorReturnsRgbaColorBasedOnDefaultValues() | ||
{ | ||
// When | ||
$result = Color::prepareColor( | ||
[ | ||
'value' => [], | ||
'default' => ['color' => '#ffffff', 'alpha' => '1'], | ||
|
||
] | ||
); | ||
|
||
// Then | ||
$this->assertEquals('rgba(255, 255, 255, 1)', $result); | ||
} | ||
|
||
/** | ||
* @testdox prepareColor returns false if faulty values. | ||
* @dataProvider prepareColorFalseProvider | ||
*/ | ||
public function testPrepareColorReturnsFalseIfFaultyValues($colors) | ||
{ | ||
// When | ||
$result = Color::prepareColor( | ||
$colors | ||
); | ||
|
||
// Then | ||
$this->assertFalse($result); | ||
} | ||
|
||
/** | ||
* @testdox getPalettes returns options if Kirki class is not found. | ||
*/ | ||
public function testGetPalettesReturnsArrayWithOptionsIfKirkiDoesNotExist() | ||
{ | ||
// Given | ||
$classExistsMock = FunctionMocker::replace('class_exists', false); | ||
|
||
// When | ||
$result = Color::getPalettes([ 'option' ]); | ||
|
||
// Then | ||
$classExistsMock->wasCalledWithOnce(['Kirki']); | ||
$this->assertEquals('option', $result[0]); | ||
} | ||
/** | ||
* @testdox getPalettes returns array with options | ||
*/ | ||
public function testGetPalettesReturnsArrayWithOptions() | ||
{ | ||
// Given | ||
$arr = ['key1' => 'value1', 'key2' => 'value2']; | ||
$kirki = Mockery::mock('overload:Kirki'); | ||
$kirki->shouldReceive('get_option')->andReturn($arr); | ||
|
||
// When | ||
$result = Color::getPalettes([ 'option' ]); | ||
|
||
// Then | ||
$this->assertEquals($arr, $result['option']); | ||
} | ||
|
||
/** | ||
* Provider | ||
*/ | ||
public function prepareColorFalseProvider() | ||
{ | ||
return [ | ||
[['value' => '']], | ||
[[]], | ||
[['default' => '']], | ||
]; | ||
} | ||
} |