-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Expand file tree
/
Copy pathHtmlEnumTest.php
More file actions
69 lines (58 loc) · 2.13 KB
/
HtmlEnumTest.php
File metadata and controls
69 lines (58 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
declare(strict_types=1);
namespace yiiunit\framework\helpers;
use yii\base\DynamicModel;
use yii\helpers\Html;
use yiiunit\framework\validators\stubs\IntStatus;
use yiiunit\framework\validators\stubs\StringStatus;
use yiiunit\framework\validators\stubs\Suit;
use yiiunit\TestCase;
/**
* @group helpers
* @requires PHP >= 8.1
*/
class HtmlEnumTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
require_once __DIR__ . '/../validators/stubs/EnumStubs.php';
$this->destroyApplication();
}
public function testGetAttributeValueWithStringBackedEnum(): void
{
$model = new DynamicModel(['status' => StringStatus::Active]);
$this->assertSame('active', Html::getAttributeValue($model, 'status'));
}
public function testGetAttributeValueWithIntBackedEnum(): void
{
$model = new DynamicModel(['status' => IntStatus::On]);
$this->assertSame(1, Html::getAttributeValue($model, 'status'));
}
public function testGetAttributeValueWithUnitEnum(): void
{
$model = new DynamicModel(['suit' => Suit::Hearts]);
$this->assertSame('Hearts', Html::getAttributeValue($model, 'suit'));
}
public function testGetAttributeValueWithArrayOfEnums(): void
{
$model = new DynamicModel(['statuses' => [StringStatus::Active, StringStatus::Inactive]]);
$this->assertSame(['active', 'inactive'], Html::getAttributeValue($model, 'statuses'));
}
public function testGetAttributeValueWithArrayOfUnitEnums(): void
{
$model = new DynamicModel(['suits' => [Suit::Hearts, Suit::Spades]]);
$this->assertSame(['Hearts', 'Spades'], Html::getAttributeValue($model, 'suits'));
}
public function testGetAttributeValueWithMixedArray(): void
{
$model = new DynamicModel(['items' => [StringStatus::Active, 'plain', 42]]);
$result = Html::getAttributeValue($model, 'items');
$this->assertSame(['active', 'plain', 42], $result);
}
}