Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Common / DiffArrayTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Common;
4
5 use Drupal\Component\Utility\DiffArray;
6 use Drupal\Tests\UnitTestCase;
7
8 /**
9  * Tests the DiffArray helper class.
10  *
11  * @group Common
12  */
13 class DiffArrayTest extends UnitTestCase {
14
15   /**
16    * Array to use for testing.
17    *
18    * @var array
19    */
20   protected $array1;
21
22   /**
23    * Array to use for testing.
24    *
25    * @var array
26    */
27   protected $array2;
28
29   protected function setUp() {
30     parent::setUp();
31
32     $this->array1 = [
33       'same' => 'yes',
34       'different' => 'no',
35       'array_empty_diff' => [],
36       'null' => NULL,
37       'int_diff' => 1,
38       'array_diff' => ['same' => 'same', 'array' => ['same' => 'same']],
39       'array_compared_to_string' => ['value'],
40       'string_compared_to_array' => 'value',
41       'new' => 'new',
42     ];
43     $this->array2 = [
44       'same' => 'yes',
45       'different' => 'yes',
46       'array_empty_diff' => [],
47       'null' => NULL,
48       'int_diff' => '1',
49       'array_diff' => ['same' => 'different', 'array' => ['same' => 'same']],
50       'array_compared_to_string' => 'value',
51       'string_compared_to_array' => ['value'],
52     ];
53   }
54
55   /**
56    * Tests DiffArray::diffAssocRecursive().
57    */
58   public function testDiffAssocRecursive() {
59     $expected = [
60       'different' => 'no',
61       'int_diff' => 1,
62       // The 'array' key should not be returned, as it's the same.
63       'array_diff' => ['same' => 'same'],
64       'array_compared_to_string' => ['value'],
65       'string_compared_to_array' => 'value',
66       'new' => 'new',
67     ];
68
69     $this->assertSame($expected, DiffArray::diffAssocRecursive($this->array1, $this->array2));
70   }
71
72 }