public function testRequestFormationWithNewSerial()
 {
     $oConfig = $this->getConfig();
     $oConfig->setConfigParam('aSerials', array('license_key'));
     $oConfig->setConfigParam('sClusterId', array('generated_unique_cluster_id'));
     $iValidNodeTime = oxRegistry::get("oxUtilsDate")->getTime();
     $oConfig->setConfigParam('aServersData', array('server_id1' => array('id' => 'server_id1', 'timestamp' => $iValidNodeTime, 'ip' => '127.0.0.1', 'lastFrontendUsage' => $iValidNodeTime, 'lastAdminUsage' => $iValidNodeTime, 'isValid' => true)));
     // imitating package revision file
     $oConfig->setConfigParam('sShopDir', $this->mockPackageRevisionFile());
     $sEdition = $oConfig->getEdition();
     $sVersion = $oConfig->getVersion();
     $sShopUrl = $oConfig->getShopUrl();
     $sRevision = $oConfig->getRevision();
     $iAdminUsers = $this->getTestConfig()->getShopEdition() == 'EE' ? 6 : 1;
     $sXml = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
     $sXml .= '<olcRequest>';
     $sXml .= '<pVersion>1.1</pVersion>';
     $sXml .= '<keys>';
     $sXml .= '<key>license_key</key>';
     $sXml .= '<key state="new">new_serial</key>';
     $sXml .= '</keys>';
     if ($sRevision) {
         $sXml .= "<revision>{$sRevision}</revision>";
     } else {
         $sXml .= '<revision></revision>';
     }
     $sXml .= '<productSpecificInformation>';
     $sXml .= '<servers>';
     $sXml .= '<server>';
     $sXml .= '<id>server_id1</id>';
     $sXml .= '<ip>127.0.0.1</ip>';
     $sXml .= "<lastFrontendUsage>{$iValidNodeTime}</lastFrontendUsage>";
     $sXml .= "<lastAdminUsage>{$iValidNodeTime}</lastAdminUsage>";
     $sXml .= '</server>';
     $sXml .= '</servers>';
     $sXml .= '<counters>';
     $sXml .= '<counter>';
     $sXml .= '<name>admin users</name>';
     $sXml .= "<value>{$iAdminUsers}</value>";
     $sXml .= '</counter>';
     $sXml .= '<counter>';
     $sXml .= '<name>active admin users</name>';
     $sXml .= "<value>{$iAdminUsers}</value>";
     $sXml .= '</counter>';
     $sXml .= '<counter>';
     $sXml .= '<name>subShops</name>';
     $sXml .= '<value>1</value>';
     $sXml .= '</counter>';
     $sXml .= '</counters>';
     $sXml .= '</productSpecificInformation>';
     $sXml .= '<clusterId>generated_unique_cluster_id</clusterId>';
     $sXml .= "<edition>{$sEdition}</edition>";
     $sXml .= "<version>{$sVersion}</version>";
     $sXml .= "<shopUrl>{$sShopUrl}</shopUrl>";
     $sXml .= '<productId>eShop</productId>';
     $sXml .= '</olcRequest>' . "\n";
     $oCurl = $this->getMock('oxCurl', array('setParameters', 'execute'));
     $oCurl->expects($this->atLeastOnce())->method('setParameters')->with($this->equalTo(array('xmlRequest' => $sXml)));
     $oCurl->expects($this->any())->method('execute')->will($this->returnValue(true));
     /** @var oxCurl $oCurl */
     $oEmailBuilder = oxNew('oxOnlineServerEmailBuilder');
     $oSimpleXml = oxNew('oxSimpleXml');
     $oLicenseCaller = new oxOnlineLicenseCheckCaller($oCurl, $oEmailBuilder, $oSimpleXml);
     $oUserCounter = oxNew('oxUserCounter');
     $oServersManager = oxNew('oxServersManager');
     $oLicenseCheck = new oxOnlineLicenseCheck($oLicenseCaller);
     $oLicenseCheck->setUserCounter($oUserCounter);
     $oLicenseCheck->setServersManager($oServersManager);
     $oLicenseCheck->validateNewSerial('new_serial');
 }
 public function testSerialsAreTakenFromConfigInShopSerialsValidation()
 {
     $iAdminUsers = 25;
     $iActiveAdminUsers = 10;
     $iSubShops = 5;
     $aServers = array('7da43ed884a1ad1d6035d4c1d630fc4e' => array('id' => '7da43ed884a1ad1d6035d4c1d630fc4e', 'timestamp' => '1409911182', 'ip' => null, 'lastFrontendUsage' => '1409911182', 'lastAdminUsage' => null));
     $aCounters = array(array('name' => 'admin users', 'value' => $iAdminUsers), array('name' => 'active admin users', 'value' => $iActiveAdminUsers), array('name' => 'subShops', 'value' => $iSubShops));
     $oConfig = $this->getMock('oxConfig', array('getMandateCount'));
     $oConfig->expects($this->any())->method('getMandateCount')->will($this->returnValue($iSubShops));
     /** @var oxConfig $oConfig */
     oxRegistry::set('oxConfig', $oConfig);
     $oRequest = oxNew('oxOnlineLicenseCheckRequest');
     $oRequest->edition = $this->getConfig()->getEdition();
     $oRequest->version = $this->getConfig()->getVersion();
     $oRequest->revision = $this->getConfig()->getRevision();
     $oRequest->shopUrl = $this->getConfig()->getShopUrl();
     $oRequest->pVersion = '1.1';
     $oRequest->productId = 'eShop';
     $oRequest->keys = array('key' => array('key1', 'key2'));
     $oRequest->productSpecificInformation = new stdClass();
     $oRequest->productSpecificInformation->servers = array('server' => $aServers);
     $oRequest->productSpecificInformation->counters = array('counter' => $aCounters);
     $this->getConfig()->setConfigParam("aSerials", array('key1', 'key2'));
     $oCaller = $this->getMock('oxOnlineLicenseCheckCaller', array('doRequest'), array(), '', false);
     $oCaller->expects($this->once())->method('doRequest')->with($oRequest);
     /** @var oxOnlineLicenseCheckCaller $oUserCounter */
     $oUserCounter = $this->getMock('oxUserCounter', array('getAdminCount', 'getActiveAdminCount'), array(), '', false);
     $oUserCounter->expects($this->once())->method('getAdminCount')->will($this->returnValue($iAdminUsers));
     $oUserCounter->expects($this->once())->method('getActiveAdminCount')->will($this->returnValue($iActiveAdminUsers));
     /** @var oxUserCounter $oUserCounter */
     $oServersManager = $this->getMock('oxServersManager', array('getServers'), array(), '', false);
     $oServersManager->expects($this->once())->method('getServers')->will($this->returnValue($aServers));
     /** @var oxServersManager $oServersManager */
     $oLicenseCheck = new oxOnlineLicenseCheck($oCaller);
     $oLicenseCheck->setServersManager($oServersManager);
     $oLicenseCheck->setUserCounter($oUserCounter);
     $oLicenseCheck->validateShopSerials();
 }