/** * */ public function testGetIniVersion() { $file = $this->getMock('\\BrowscapPHP\\Helper\\Filesystem', array('exists'), array(), '', false); $file->expects(self::never())->method('exists')->will(self::returnValue(false)); $this->object->setFilesystem($file); $content = ';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Browscap Version [GJK_Browscap_Version] Version=5031 Released=Mon, 30 Jun 2014 17:55:58 +0200 Format=ASP Type='; self::assertSame(5031, $this->object->getIniVersion($content)); self::assertSame($this->object, $this->object->storeVersion()); }
/** * */ public function testGetIniVersion() { $file = $this->getMockBuilder(\BrowscapPHP\Helper\Filesystem::class)->disableOriginalConstructor()->setMethods(['exists'])->getMock(); $file->expects(self::never())->method('exists')->will(self::returnValue(false)); $this->object->setFilesystem($file); $content = ';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Browscap Version [GJK_Browscap_Version] Version=5031 Released=Mon, 30 Jun 2014 17:55:58 +0200 Format=ASP Type='; self::assertSame(5031, $this->object->getIniVersion($content)); self::assertSame($this->object, $this->object->storeVersion()); }
/** * fetches a remote file, parses it and writes the result into the cache * * if the local stored information are in the same version as the remote data no actions are * taken * * @param string $remoteFile The code for the remote file to load * @param string|null $buildFolder * @param int|null $buildNumber * * @throws \BrowscapPHP\Exception\FileNotFoundException * @throws \BrowscapPHP\Helper\Exception */ public function update($remoteFile = IniLoader::PHP_INI, $buildFolder = null, $buildNumber = null) { $this->getLogger()->debug('started fetching remote file'); $converter = new Converter($this->getLogger(), $this->getCache()); if (class_exists('\\Browscap\\Browscap')) { $resourceFolder = 'vendor/browscap/browscap/resources/'; if (null === $buildNumber) { $buildNumber = (int) file_get_contents('vendor/browscap/browscap/BUILD_NUMBER'); } if (null === $buildFolder) { $buildFolder = 'resources'; } $buildFolder .= '/browscap-ua-test-' . $buildNumber; $iniFile = $buildFolder . '/full_php_browscap.ini'; mkdir($buildFolder, 0777, true); $writerCollectionFactory = new PhpWriterFactory(); $writerCollection = $writerCollectionFactory->createCollection($this->getLogger(), $buildFolder); $buildGenerator = new BuildGenerator($resourceFolder, $buildFolder); $buildGenerator->setLogger($this->getLogger())->setCollectionCreator(new CollectionCreator())->setWriterCollection($writerCollection)->run($buildNumber, false); $converter->setVersion($buildNumber)->storeVersion()->convertFile($iniFile); $filesystem = new Filesystem(); $filesystem->remove($buildFolder); } else { $this->getLoader()->setRemoteFilename($remoteFile)->setOptions($this->options)->setLogger($this->getLogger()); $success = null; $cachedVersion = $this->getCache()->getItem('browscap.version', false, $success); try { $remoteVersion = $this->getLoader()->getRemoteVersion(); } catch (Helper\Exception $e) { $this->getLogger()->warning($e); $remoteVersion = null; $success = false; } if ($success && $cachedVersion && $remoteVersion && $remoteVersion <= $cachedVersion) { // no newer version available return; } $internalLoader = $this->getLoader()->getLoader(); try { $content = $this->getLoader()->load(); } catch (Helper\Exception $e) { throw new FetcherException('an error occured while loading remote data', 0, $e); } if (false === $content) { $error = error_get_last(); throw FetcherException::httpError($internalLoader->getUri(), $error['message']); } $this->getLogger()->debug('finished fetching remote file'); $content = $this->sanitizeContent($content); $iniVersion = $converter->getIniVersion($content); if ($iniVersion > $cachedVersion) { $converter->storeVersion()->convertString($content); } } }
/** * reads and parses an ini string and writes the results into the cache * * @param \BrowscapPHP\Helper\Converter $converter * @param string $content * @param int|null $cachedVersion */ private function storeContent(Converter $converter, $content, $cachedVersion) { $iniString = $this->sanitizeContent($content); $iniVersion = $converter->getIniVersion($iniString); if (!$cachedVersion || $iniVersion > $cachedVersion) { $converter->storeVersion()->convertString($iniString); } }
/** * */ public function testConvertStringWithoutPatternFaound() { $file = $this->getMock('\\BrowscapPHP\\Helper\\Filesystem', array('exists'), array(), '', false); $file->expects(self::never())->method('exists')->will(self::returnValue(false)); $this->object->setFilesystem($file); $content = ';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Browscap Version [GJK_Browscap_Version] Version=5031 Released=Mon, 30 Jun 2014 17:55:58 +0200 Format=ASP Type= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DefaultProperties [DefaultProperties] Comment=DefaultProperties Browser=DefaultProperties Version=0.0 MajorVer=0 MinorVer=0 Platform=unknown Platform_Version=unknown Alpha=false Beta=false Win16=false Win32=false Win64=false Frames=false IFrames=false Tables=false Cookies=false BackgroundSounds=false JavaScript=false VBScript=false JavaApplets=false ActiveXControls=false isMobileDevice=false isTablet=false isSyndicationReader=false Crawler=false CssVersion=0 AolVersion=0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ask [Ask] Parent=DefaultProperties Comment=Ask Browser=Ask Frames=1 IFrames=1 Tables=1 Crawler=1 Version=0.0 MajorVer=0 MinorVer=0 Platform=unknown Platform_Version=unknown Alpha= Beta= Win16= Win32= Win64= Cookies= BackgroundSounds= JavaScript= VBScript= JavaApplets= ActiveXControls= isMobileDevice= isTablet= isSyndicationReader= CssVersion=0 AolVersion=0 '; self::assertNull($this->object->convertString($content)); }