Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BooleanUtilsTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\Stdlib\BooleanUtils;
9 
10 class BooleanUtilsTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $object;
16 
17  protected function setUp()
18  {
19  $this->object = new BooleanUtils();
20  }
21 
22  public function testConstructor()
23  {
24  $object = new BooleanUtils(['yep'], ['nope']);
25  $this->assertTrue($object->toBoolean('yep'));
26  $this->assertFalse($object->toBoolean('nope'));
27  }
28 
35  public function testToBoolean($input, $expected)
36  {
37  $actual = $this->object->toBoolean($input);
38  $this->assertSame($expected, $actual);
39  }
40 
44  public function toBooleanDataProvider()
45  {
46  return [
47  'boolean "true"' => [true, true],
48  'boolean "false"' => [false, false],
49  'boolean string "true"' => ['true', true],
50  'boolean string "false"' => ['false', false],
51  'boolean numeric "1"' => [1, true],
52  'boolean numeric "0"' => [0, false],
53  'boolean string "1"' => ['1', true],
54  'boolean string "0"' => ['0', false]
55  ];
56  }
57 
65  public function testToBooleanException($input)
66  {
67  $this->object->toBoolean($input);
68  }
69 
74  {
75  return [
76  'boolean string "on"' => ['on'],
77  'boolean string "off"' => ['off'],
78  'boolean string "yes"' => ['yes'],
79  'boolean string "no"' => ['no'],
80  'boolean string "TRUE"' => ['TRUE'],
81  'boolean string "FALSE"' => ['FALSE'],
82  'empty string' => [''],
83  'null' => [null]
84  ];
85  }
86 }