Пример #1
0
 public function testClientAction()
 {
     $runName = uniqid('', true);
     $prvFileName = 'testfile_client_id_rsa_' . date('Ymd_His') . '_' . $runName . '.prv';
     $pubFileName = 'testfile_client_id_rsa_' . date('Ymd_His') . '_' . $runName . '.pub';
     file_put_contents('test_data/' . $prvFileName, static::NODE_LOCAL_SSL_KEY_PRV1);
     file_put_contents('test_data/' . $pubFileName, static::NODE_LOCAL_SSL_KEY_PUB1);
     $settings = new Settings();
     $settings->data['datadir'] = 'test_data';
     $settings->data['firstRun'] = false;
     $settings->data['timeCreated'] = time();
     $settings->data['node']['uriLocal'] = '';
     $settings->data['node']['id'] = 'cafed00d-2131-4159-8e11-0b4dbadb1738';
     $settings->data['node']['sslKeyPrvPass'] = '******';
     $settings->data['node']['sslKeyPrvPath'] = 'test_data/' . $prvFileName;
     $settings->data['node']['sslKeyPubPath'] = 'test_data/' . $pubFileName;
     $settings->data['user']['nickname'] = 'user_' . substr(md5(time()), 0, 4);
     $log = new Logger('test_application');
     #$log->pushHandler(new LoggerStreamHandler('php://stdout', Logger::DEBUG));
     $kernel = new Kernel();
     $kernel->setLog($log);
     $kernel->setSettings($settings);
     $kernel->init();
     $server = $kernel->getServer();
     $server->setLog($log);
     $client = new Client();
     $client->setSslPrv($settings->data['node']['sslKeyPrvPath'], $settings->data['node']['sslKeyPrvPass']);
     $client->setId(1);
     $client->setServer($server);
     $action = new ClientAction(ClientAction::CRITERION_NONE);
     $client->actionAdd($action);
     $oldActions = $client->actionsGetByCriterion(ClientAction::CRITERION_NONE);
     $this->assertEquals(array($action), $oldActions);
     $oldAction = $client->actionGetByCriterion(ClientAction::CRITERION_NONE);
     $this->assertEquals($action, $oldAction);
     $client->actionRemove($action);
     $oldActions = $client->actionsGetByCriterion(ClientAction::CRITERION_NONE);
     $this->assertEquals(array(), $oldActions);
     $oldAction = $client->actionGetByCriterion(ClientAction::CRITERION_NONE);
     $this->assertEquals(null, $oldAction);
     $actions = array();
     $action = new ClientAction(ClientAction::CRITERION_NONE);
     $actions[] = $action;
     $client->actionsAdd($actions);
     $client->actionsExecute(ClientAction::CRITERION_NONE);
     $client->actionsAdd(new ClientAction(ClientAction::CRITERION_NONE));
     $client->actionsAdd(new ClientAction(ClientAction::CRITERION_AFTER_PREVIOUS_ACTIONS));
     $client->checkActions();
     $kernel->shutdown();
     @unlink('test_data/hashcashdb.yml');
     @unlink('test_data/msgdb.yml');
     @unlink('test_data/nodesnewdb.yml');
 }