/**
  * @dataProvider deviceIdAgentProvider
  *
  * @param string $userAgent
  * @param string $expectedDeviceId
  */
 public function testMatch($userAgent, $expectedDeviceId)
 {
     $header = array('HTTP_USER_AGENT' => $userAgent);
     $request = new GenericRequest($header, $userAgent, null, false);
     $deviceId = $this->object->match($request);
     self::assertSame($expectedDeviceId, $deviceId);
 }
 private function verifyRepository()
 {
     /**
      * verify required device ids
      */
     foreach ($this->userAgentHandlerChain->getHandlers() as $handler) {
         /**
          * @var \Wurfl\Handlers\AbstractHandler
          */
         foreach ($handler::$constantIDs as $requireDeviceId) {
             $device = $this->persistenceProvider->load($requireDeviceId);
             if ($device === null) {
                 throw new ConsistencyException('wurfl.xml load error - device id [' . $requireDeviceId . '] is missing - ' . 'you may need to update the wurfl.xml file to a more recent version');
             }
         }
     }
     /**
      * verify required capabilities
      */
     $requiredCaps = VirtualCapabilityProvider::getRequiredCapabilities();
     /** @var \Wurfl\Device\ModelDeviceInterface $genericDevice */
     $genericDevice = $this->persistenceProvider->load('generic');
     $loadedCaps = array_keys($genericDevice->getCapabilities());
     $missingCaps = array_diff($requiredCaps, $loadedCaps);
     if (count($missingCaps) > 0) {
         throw new ConsistencyException('Missing required WURFL Capabilities: ' . implode(', ', $missingCaps));
     }
     $invalidFallbacks = array_diff(array_keys($this->fallbacks), $this->devices);
     if (count($invalidFallbacks) > 0) {
         foreach ($invalidFallbacks as $invalidFallback) {
             $device = new CustomDevice(array($this->persistenceProvider->load($this->fallbacks[$invalidFallback])));
             throw new ConsistencyException(sprintf('Invalid Fallback %s for the device %s', $invalidFallback, $device->id));
         }
     }
     $this->fallbacks = array();
     $this->devices = array();
 }
 /**
  * Initializes the factory with an instance of all possible \Wurfl\Handlers\AbstractHandler objects
  *
  * @return \Wurfl\Handlers\Chain\UserAgentHandlerChain
  */
 private static function init()
 {
     $userAgentHandlerChain = new UserAgentHandlerChain();
     /** @var $genericNormalizers UserAgentNormalizer */
     $genericNormalizers = self::createGenericNormalizers();
     /**** Smart TVs ****/
     $userAgentHandlerChain->addUserAgentHandler(new SmartTVHandler($genericNormalizers));
     /**** Mobile devices ****/
     $userAgentHandlerChain->addUserAgentHandler(new KindleHandler($genericNormalizers));
     /**** UCWEB ****/
     $ucwebu3Normalizer = clone $genericNormalizers;
     $ucwebu3Normalizer->add(new UcwebU3());
     $userAgentHandlerChain->addUserAgentHandler(new UcwebU3Handler($ucwebu3Normalizer));
     $ucwebu2Normalizer = clone $genericNormalizers;
     $ucwebu2Normalizer->add(new UcwebU2());
     $userAgentHandlerChain->addUserAgentHandler(new UcwebU2Handler($ucwebu2Normalizer));
     /**** Mobile platforms ****/
     //Windows Phone must be above Android to resolve WP 8.1 and above UAs correctly
     $winPhoneNormalizer = clone $genericNormalizers;
     $winPhoneNormalizer->add(new WindowsPhone());
     $userAgentHandlerChain->addUserAgentHandler(new WindowsPhoneHandler($winPhoneNormalizer));
     // Android Matcher Chain
     $userAgentHandlerChain->addUserAgentHandler(new OperaMiniOnAndroidHandler($genericNormalizers));
     $operaMobiNormalizer = clone $genericNormalizers;
     $operaMobiNormalizer->add(new OperaMobiOrTabletOnAndroid());
     $userAgentHandlerChain->addUserAgentHandler(new OperaMobiOrTabletOnAndroidHandler($operaMobiNormalizer));
     $userAgentHandlerChain->addUserAgentHandler(new FennecOnAndroidHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new Ucweb7OnAndroidHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new NetFrontOnAndroidHandler($genericNormalizers));
     $androidNormalizer = clone $genericNormalizers;
     $androidNormalizer->add(new Android());
     $userAgentHandlerChain->addUserAgentHandler(new AndroidHandler($androidNormalizer));
     $userAgentHandlerChain->addUserAgentHandler(new UbuntuTouchOSHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new TizenHandler($genericNormalizers));
     $appleNormalizer = clone $genericNormalizers;
     $appleNormalizer->add(new Apple());
     $userAgentHandlerChain->addUserAgentHandler(new AppleHandler($appleNormalizer));
     $userAgentHandlerChain->addUserAgentHandler(new NokiaOviBrowserHandler($genericNormalizers));
     /**** High workload mobile matchers ****/
     $userAgentHandlerChain->addUserAgentHandler(new NokiaHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new SamsungHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new BlackBerryHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new SonyEricssonHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new MotorolaHandler($genericNormalizers));
     /**** Other mobile matchers ****/
     $userAgentHandlerChain->addUserAgentHandler(new AlcatelHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new BenQHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new DoCoMoHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new GrundigHandler($genericNormalizers));
     $htcMacNormalizer = clone $genericNormalizers;
     $htcMacNormalizer->add(new HTCMac());
     $userAgentHandlerChain->addUserAgentHandler(new HTCMacHandler($htcMacNormalizer));
     $userAgentHandlerChain->addUserAgentHandler(new HTCHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new KDDIHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new KyoceraHandler($genericNormalizers));
     $lgNormalizer = clone $genericNormalizers;
     $lgNormalizer->add(new LG());
     $userAgentHandlerChain->addUserAgentHandler(new LGHandler($lgNormalizer));
     $userAgentHandlerChain->addUserAgentHandler(new LGUPLUSHandler($genericNormalizers));
     $maemoNormalizer = clone $genericNormalizers;
     $maemoNormalizer->add(new Maemo());
     $userAgentHandlerChain->addUserAgentHandler(new MaemoHandler($maemoNormalizer));
     $userAgentHandlerChain->addUserAgentHandler(new MitsubishiHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new NecHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new NintendoHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new PanasonicHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new PantechHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new PhilipsHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new PortalmmmHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new QtekHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new ReksioHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new SagemHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new SanyoHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new SharpHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new SiemensHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new SkyfireHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new SPVHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new ToshibaHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new VodafoneHandler($genericNormalizers));
     $webOSNormalizer = clone $genericNormalizers;
     $webOSNormalizer->add(new WebOS());
     $userAgentHandlerChain->addUserAgentHandler(new WebOSHandler($webOSNormalizer));
     $userAgentHandlerChain->addUserAgentHandler(new FirefoxOSHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new OperaMiniHandler($genericNormalizers));
     /**** Java Midlets ****/
     $userAgentHandlerChain->addUserAgentHandler(new JavaMidletHandler($genericNormalizers));
     /**** Tablet Browsers ****/
     $userAgentHandlerChain->addUserAgentHandler(new WindowsRTHandler($genericNormalizers));
     /**** Robots / Crawlers ****/
     $userAgentHandlerChain->addUserAgentHandler(new BotCrawlerTranscoderHandler($genericNormalizers));
     /**** Game Consoles ****/
     $userAgentHandlerChain->addUserAgentHandler(new XboxHandler($genericNormalizers));
     /**** DesktopApplications ****/
     $desktopApplicationNormalizer = clone $genericNormalizers;
     $desktopApplicationNormalizer->add(new DesktopApplication());
     $userAgentHandlerChain->addUserAgentHandler(new DesktopApplicationHandler($desktopApplicationNormalizer));
     /**** Desktop Browsers ****/
     //MSIE above Chrome/Opera after MSIE 12+ say Chrome
     $msieNormalizer = clone $genericNormalizers;
     $msieNormalizer->add(new MSIE());
     $userAgentHandlerChain->addUserAgentHandler(new MSIEHandler($msieNormalizer));
     $operaNormalizer = clone $genericNormalizers;
     $operaNormalizer->add(new Opera());
     $userAgentHandlerChain->addUserAgentHandler(new OperaHandler($operaNormalizer));
     $chromeNormalizer = clone $genericNormalizers;
     $chromeNormalizer->add(new Chrome());
     $userAgentHandlerChain->addUserAgentHandler(new ChromeHandler($chromeNormalizer));
     $firefoxNormalizer = clone $genericNormalizers;
     $firefoxNormalizer->add(new Firefox());
     $userAgentHandlerChain->addUserAgentHandler(new FirefoxHandler($firefoxNormalizer));
     $safariNormalizer = clone $genericNormalizers;
     $safariNormalizer->add(new Safari());
     $userAgentHandlerChain->addUserAgentHandler(new SafariHandler($safariNormalizer));
     $userAgentHandlerChain->addUserAgentHandler(new KonquerorHandler($genericNormalizers));
     /**** All other requests ****/
     $userAgentHandlerChain->addUserAgentHandler(new CatchAllMozillaHandler($genericNormalizers));
     $userAgentHandlerChain->addUserAgentHandler(new CatchAllRisHandler($genericNormalizers));
     return $userAgentHandlerChain;
 }