Skip to content

Commit 81b87d2

Browse files
committed
MAGETWO-34390: Stabilization of replacing Zend_Locale with Native PHP Implementation
1 parent b7c5662 commit 81b87d2

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
// @codingStandardsIgnoreFile
8+
9+
namespace Magento\Framework\Locale\Bundle\Test\Unit;
10+
11+
use Magento\Framework\Locale\Bundle\DataBundle;
12+
13+
class DataBundleTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var \Magento\Framework\Locale\Bundle\DataBundle
17+
*/
18+
protected $bundleObject;
19+
20+
public function setUp()
21+
{
22+
$this->bundleObject = new DataBundle();
23+
}
24+
25+
/**
26+
* @param string $locale
27+
* @param \ResourceBundle $result
28+
* #@dataProvider dataProviderGet
29+
*/
30+
public function testGet($locale, \ResourceBundle $result)
31+
{
32+
$bundle = $this->bundleObject->get($locale);
33+
$this->assertInstanceOf('\ResourceBundle', $bundle);
34+
$this->assertEquals($result, $bundle);
35+
$this->assertEquals($result->count(), $bundle->count());
36+
$this->assertTrue($this->compareBundlesRecursively($bundle, $result));
37+
// Check the caching is working
38+
$bundleAgain = $this->bundleObject->get($locale);
39+
$this->assertInstanceOf('\ResourceBundle', $bundleAgain);
40+
$this->assertSame($bundle, $bundleAgain);
41+
}
42+
43+
/**
44+
* Checks whether bundles contains the same data
45+
*
46+
* @param \ResourceBundle $first
47+
* @param \ResourceBundle $second
48+
* @return bool
49+
*/
50+
protected function compareBundlesRecursively(\ResourceBundle $first, \ResourceBundle $second)
51+
{
52+
$isEquals = true;
53+
foreach ($first as $key => $value) {
54+
if ($value instanceof \ResourceBundle && $second[$key] instanceof \ResourceBundle) {
55+
$isEquals = $isEquals && $this->compareBundlesRecursively($value, $second[$key]);
56+
} else {
57+
$isEquals = $isEquals && $value === $second[$key];
58+
}
59+
}
60+
return $isEquals;
61+
}
62+
63+
/**
64+
* @return array
65+
*/
66+
public function dataProviderGet()
67+
{
68+
return [
69+
['en', new \ResourceBundle('en', 'ICUDATA')],
70+
['en_US', new \ResourceBundle('en', 'ICUDATA')],
71+
['en_US_Variant', new \ResourceBundle('en', 'ICUDATA')],
72+
['sr_Latn_SR', new \ResourceBundle('sr_Latn', 'ICUDATA')],
73+
['sr_Cyrl_SR', new \ResourceBundle('sr_Cyrl', 'ICUDATA')],
74+
];
75+
}
76+
}

0 commit comments

Comments
 (0)