Skip to content
This repository

Zf2-207, ZF2-212 #917

Merged
merged 2 commits into from over 2 years ago

4 participants

Saša Stamenković Robert Basic Marc Bennewitz Matthew Weier O'Phinney
Saša Stamenković

Fixed issues:

We were totally missing Cldr behavior without cache. So I added tests.

The only strange thing is that now ZendTest\Locale\Data\CldrTest::testLanguage fails, Cldr::getDisplayLanguage('de) returns languages in English. it would be nice if someone can take a look at it.

Robert Basic

Could it be possible to break up this in 2 separate pull requests? It's difficult to see what fixes what issue.

Thanks!

Saša Stamenković
Marc Bennewitz marc-mabe commented on the diff
tests/Zend/Locale/Data/CldrCachedTest.php
((50 lines not shown))
  50 + 'adapter' => array(
  51 + 'name' => 'Filesystem',
  52 + 'options' => array(
  53 + 'ttl' => 1,
  54 + 'cache_dir' => $this->_cacheDir,
  55 + )
  56 + ),
  57 + 'plugins' => array(
  58 + array(
  59 + 'name' => 'serializer',
  60 + 'options' => array(
  61 + 'serializer' => 'php_serialize',
  62 + ),
  63 + ),
  64 + ),
  65 + ));
2
Marc Bennewitz
marc-mabe added a note

I'd prefer to use the memory adapter on testing cache consumers to simplify things ;)

Saša Stamenković
umpirsky added a note

I agree, but I just moved this code from CldrTest to CldrCachedTest. You can fix that in new PR ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Matthew Weier O'Phinney weierophinney merged commit 0d350bb into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Mar 10, 2012
Saša Stamenković umpirsky Fixed ZF2-207. 5f163f8
Saša Stamenković umpirsky Fixed ZF2-212. 0d350bb
This page is out of date. Refresh to see the latest.
2  library/Zend/Cache/Storage/Adapter/Filesystem.php
@@ -1159,7 +1159,7 @@ protected function internalSetItem($key, $value, array &$options)
1159 1159
1160 1160 $info = null;
1161 1161 if ($baseOptions->getReadControl()) {
1162   - $info['hash'] = Utils::generateHash($this->getReadControlAlgo(), $value, true);
  1162 + $info['hash'] = Utils::generateHash($baseOptions->getReadControlAlgo(), $value, true);
1163 1163 $info['algo'] = $baseOptions->getReadControlAlgo();
1164 1164 }
1165 1165
2  library/Zend/Cache/Utils.php
@@ -179,7 +179,7 @@ static protected function getSystemMemoryCapacityWin()
179 179 *
180 180 * This helper adds the virtual hash algo "strlen".
181 181 *
182   - * @param string $data Name of selected hashing algorithm
  182 + * @param string $algo Name of selected hashing algorithm
183 183 * @param string $data Message to be hashed.
184 184 * @param bool $raw When set to TRUE, outputs raw binary data. FALSE outputs lowercase hexits.
185 185 * @return string Hash value
2  library/Zend/Locale/Data/Cldr.php
@@ -1654,7 +1654,7 @@ protected static function readCldr($filePath, $locale, $cacheId, $keyPath, $keyA
1654 1654
1655 1655 if (self::hasCacheTagSupport()) {
1656 1656 self::getCache()->setItem($cacheId, self::$_result, array('tags' => array('Zend_Locale')));
1657   - } else {
  1657 + } elseif (self::hasCache()) {
1658 1658 self::getCache()->setItem($cacheId, self::$_result);
1659 1659 }
1660 1660
98 tests/Zend/Locale/Data/CldrCachedTest.php
... ... @@ -0,0 +1,98 @@
  1 +<?php
  2 +/**
  3 + * Zend Framework
  4 + *
  5 + * LICENSE
  6 + *
  7 + * This source file is subject to the new BSD license that is bundled
  8 + * with this package in the file LICENSE.txt.
  9 + * It is also available through the world-wide-web at this URL:
  10 + * http://framework.zend.com/license/new-bsd
  11 + * If you did not receive a copy of the license and are unable to
  12 + * obtain it through the world-wide-web, please send an email
  13 + * to license@zend.com so we can send you a copy immediately.
  14 + *
  15 + * @category Zend
  16 + * @package Zend_Locale
  17 + * @subpackage UnitTests
  18 + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19 + * @license http://framework.zend.com/license/new-bsd New BSD License
  20 + */
  21 +
  22 +namespace ZendTest\Locale\Data;
  23 +
  24 +use Zend\Locale\Data\Cldr,
  25 + Zend\Locale\Exception\InvalidArgumentException,
  26 + Zend\Locale\Locale,
  27 + Zend\Cache\StorageFactory as CacheFactory,
  28 + Zend\Cache\Storage\Adapter as CacheAdapter,
  29 + ZendTest\Locale\Data\CldrTest;
  30 +
  31 +/**
  32 + * @category Zend
  33 + * @package Zend_Locale
  34 + * @subpackage UnitTests
  35 + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  36 + * @license http://framework.zend.com/license/new-bsd New BSD License
  37 + * @group Zend_Locale
  38 + */
  39 +class CldrCachedTest extends CldrTest {
  40 +
  41 + private $_cache = null;
  42 +
  43 + public function setUp()
  44 + {
  45 + $this->_cacheDir = sys_get_temp_dir() . '/zend_locale_cldr';
  46 + $this->_removeRecursive($this->_cacheDir);
  47 + mkdir($this->_cacheDir);
  48 +
  49 + $this->_cache = CacheFactory::factory(array(
  50 + 'adapter' => array(
  51 + 'name' => 'Filesystem',
  52 + 'options' => array(
  53 + 'ttl' => 1,
  54 + 'cache_dir' => $this->_cacheDir,
  55 + )
  56 + ),
  57 + 'plugins' => array(
  58 + array(
  59 + 'name' => 'serializer',
  60 + 'options' => array(
  61 + 'serializer' => 'php_serialize',
  62 + ),
  63 + ),
  64 + ),
  65 + ));
  66 +
  67 + Cldr::setCache($this->_cache);
  68 + }
  69 +
  70 +
  71 + public function tearDown()
  72 + {
  73 + $this->_cache->clear(CacheAdapter::MATCH_ALL);
  74 + $this->_removeRecursive($this->_cacheDir);
  75 + }
  76 +
  77 +
  78 + protected function _removeRecursive($dir)
  79 + {
  80 + if (file_exists($dir)) {
  81 + $dirIt = new \DirectoryIterator($dir);
  82 + foreach ($dirIt as $entry) {
  83 + $fname = $entry->getFilename();
  84 + if ($fname == '.' || $fname == '..') {
  85 + continue;
  86 + }
  87 +
  88 + if ($entry->isFile()) {
  89 + unlink($entry->getPathname());
  90 + } else {
  91 + $this->_removeRecursive($entry->getPathname());
  92 + }
  93 + }
  94 +
  95 + rmdir($dir);
  96 + }
  97 + }
  98 +}
71 tests/Zend/Locale/Data/CldrTest.php
@@ -36,64 +36,19 @@
36 36 * @group Zend_Locale
37 37 */
38 38 class CldrTest extends \PHPUnit_Framework_TestCase
39   -{
40   -
41   - private $_cache = null;
42   -
43   - public function setUp()
44   - {
45   - $this->_cacheDir = sys_get_temp_dir() . '/zend_locale_cldr';
46   - $this->_removeRecursive($this->_cacheDir);
47   - mkdir($this->_cacheDir);
48   -
49   - $this->_cache = CacheFactory::factory(array(
50   - 'adapter' => array(
51   - 'name' => 'Filesystem',
52   - 'options' => array(
53   - 'ttl' => 1,
54   - 'cache_dir' => $this->_cacheDir,
55   - )
56   - ),
57   - 'plugins' => array(
58   - array(
59   - 'name' => 'serializer',
60   - 'options' => array(
61   - 'serializer' => 'php_serialize',
62   - ),
63   - ),
64   - ),
65   - ));
66   - Cldr::setCache($this->_cache);
67   - }
68   -
69   -
70   - public function tearDown()
71   - {
72   - $this->_cache->clear(CacheAdapter::MATCH_ALL);
73   - $this->_removeRecursive($this->_cacheDir);
74   - }
75   -
76   - protected function _removeRecursive($dir)
  39 +{
  40 + /**
  41 + * test for reading with cache disabled
  42 + * @see ZF2-212
  43 + */
  44 + public function testNoCache()
77 45 {
78   - if (file_exists($dir)) {
79   - $dirIt = new \DirectoryIterator($dir);
80   - foreach ($dirIt as $entry) {
81   - $fname = $entry->getFilename();
82   - if ($fname == '.' || $fname == '..') {
83   - continue;
84   - }
85   -
86   - if ($entry->isFile()) {
87   - unlink($entry->getPathname());
88   - } else {
89   - $this->_removeRecursive($entry->getPathname());
90   - }
91   - }
92   -
93   - rmdir($dir);
94   - }
  46 + Cldr::disableCache(true);
  47 + $this->testTerritory();
  48 + Cldr::disableCache(false);
95 49 }
96   -
  50 +
  51 +
97 52 /**
98 53 * test for reading with standard locale
99 54 * expected array
@@ -112,8 +67,8 @@ public function testNoLocale()
112 67 $locale = new Locale('de');
113 68 $this->assertTrue(is_array(Cldr::getDisplayLanguage($locale)));
114 69 }
115   -
116   -
  70 +
  71 +
117 72 /**
118 73 * test for reading without type
119 74 * expected empty array

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.