/**
  * Check whenever given language package up to date
  *
  * @param string $languageCode
  *
  * @return bool
  */
 public function isFresh($languageCode)
 {
     if (!isset($this->processedLanguages[$languageCode])) {
         $configData = $this->cm->get(TranslationStatusInterface::META_CONFIG_KEY);
         $stats = $this->statisticProvider->get();
         if (isset($configData[$languageCode])) {
             $stats = array_filter($stats, function ($langInfo) use($languageCode) {
                 return $langInfo['code'] === $languageCode;
             });
             $lang = array_pop($stats);
             if ($lang) {
                 $installationDate = $this->getDateTimeFromString($configData[$languageCode]['lastBuildDate']);
                 $currentBuildDate = $this->getDateTimeFromString($lang['lastBuildDate']);
                 $this->processedLanguages[$languageCode] = $installationDate >= $currentBuildDate;
             } else {
                 // could not retrieve current language stats, so assume that it's fresh
                 $this->processedLanguages[$languageCode] = true;
             }
         } else {
             // if we do not have information about installed time then assume that needs update
             $this->processedLanguages[$languageCode] = false;
         }
     }
     return $this->processedLanguages[$languageCode];
 }
 /**
  * @dataProvider isFreshDataProvider
  *
  * @param array  $configData
  * @param array  $statisticData
  * @param string $langCode
  * @param bool   $expectedResult
  */
 public function testIsFresh(array $configData, array $statisticData, $langCode, $expectedResult)
 {
     $this->cm->expects($this->once())->method('get')->with($this->equalTo(TranslationStatusInterface::META_CONFIG_KEY))->will($this->returnValue($configData));
     $this->sp->expects($this->once())->method('get')->will($this->returnValue($statisticData));
     $result1 = $this->extension->isFresh($langCode);
     // second call should not fail expectation above
     // result should be cached
     $result2 = $this->extension->isFresh($langCode);
     $this->assertSame($result1, $result2);
     $this->assertSame($expectedResult, $result1);
 }
 /**
  * @dataProvider getProvider
  *
  * @param mixed $cachedData
  * @param array $resultExpected
  * @param bool  $fetchExpected
  * @param array $fetchedResult
  * @param bool  $isException
  */
 public function testGet($cachedData, $resultExpected, $fetchExpected, $fetchedResult = [], $isException = false)
 {
     $this->cache->expects($this->once())->method('fetch')->with($this->equalTo(TranslationStatisticProvider::CACHE_KEY))->will($this->returnValue($cachedData));
     if ($fetchExpected) {
         if ($isException) {
             $this->adapter->expects($this->once())->method('fetchStatistic')->will($this->throwException($fetchedResult));
         } else {
             $this->adapter->expects($this->once())->method('fetchStatistic')->will($this->returnValue($fetchedResult));
         }
         $this->cache->expects($this->once())->method('save')->with($this->equalTo(TranslationStatisticProvider::CACHE_KEY));
     } else {
         $this->adapter->expects($this->never())->method('fetchStatistic');
     }
     $result = $this->provider->get();
     $this->assertSame($resultExpected, $result);
 }