예제 #1
0
파일: MsgTest.php 프로젝트: thefox/phpchat
 public function testSaveLoad()
 {
     $runName = uniqid('', true);
     $fileName = 'testfile_msg_' . date('Ymd_His') . '_' . $runName . '.yml';
     $msg = new Msg('test_data/' . $fileName);
     $msg->setDatadirBasePath('test_data');
     $msg->setDataChanged(true);
     $msg->setVersion(21);
     $this->assertEquals(21, $msg->getVersion());
     $msg->setId('cafed00d-2131-4159-8e11-0b4dbadb1738');
     $this->assertEquals('cafed00d-2131-4159-8e11-0b4dbadb1738', $msg->getId());
     $msg->setRelayNodeId('cafed00d-2231-4159-8e11-0b4dbadb1738');
     $this->assertEquals('cafed00d-2231-4159-8e11-0b4dbadb1738', $msg->getRelayNodeId());
     $msg->setSrcNodeId('cafed00d-2331-4159-8e11-0b4dbadb1738');
     $this->assertEquals('cafed00d-2331-4159-8e11-0b4dbadb1738', $msg->getSrcNodeId());
     $msg->setSrcSslKeyPub(static::SRC1_SSL_KEY_PUB);
     $this->assertEquals(static::SRC1_SSL_KEY_PUB, $msg->getSrcSslKeyPub());
     $msg->setSrcUserNickname('thefox');
     $this->assertEquals('thefox', $msg->getSrcUserNickname());
     $msg->setDstNodeId('cafed00d-2431-4159-8e11-0b4dbadb1738');
     $this->assertEquals('cafed00d-2431-4159-8e11-0b4dbadb1738', $msg->getDstNodeId());
     $msg->setDstSslPubKey(static::DST1_SSL_KEY_PUB);
     $this->assertEquals(static::DST1_SSL_KEY_PUB, $msg->getDstSslPubKey());
     $msg->setSubject('my first subject');
     $this->assertEquals('my first subject', $msg->getSubject());
     $msg->setText('hello world! this is a test');
     $this->assertEquals('hello world! this is a test', $msg->getText());
     $msg->setPassword('my_password01');
     $this->assertEquals('my_password01', $msg->getPassword());
     $msg->setChecksum('checksuuuum_sum');
     $this->assertEquals('checksuuuum_sum', $msg->getChecksum());
     $msg->setSentNodes(array(21, 2, 1987));
     $msg->addSentNode(42);
     $this->assertEquals(array(21, 2, 1987, 42), $msg->getSentNodes());
     $msg->setRelayCount(22);
     $this->assertEquals(22, $msg->getRelayCount());
     $msg->setForwardCycles(23);
     $msg->incForwardCycles();
     $this->assertEquals(24, $msg->getForwardCycles());
     $msg->setEncryptionMode('D');
     $this->assertEquals('D', $msg->getEncryptionMode());
     $msg->setStatus('O');
     $this->assertEquals('O', $msg->getStatus());
     $msg->setTimeCreated(679874400);
     $this->assertEquals(679874400, $msg->getTimeCreated());
     $msg->setSslKeyPrv(static::SRC1_SSL_KEY_PRV, static::SSL_KEY_PRV_PASS);
     $this->assertTrue($msg->encrypt());
     $this->assertTrue((bool) $msg->save());
     $finder = new Finder();
     $files = $finder->in('test_data')->depth(0)->name($fileName)->files();
     $this->assertEquals(1, count($files));
     $msg = new Msg('test_data/' . $fileName);
     $msg->setDatadirBasePath('test_data');
     $this->assertTrue($msg->load());
     $this->assertEquals(21, $msg->getVersion());
     $this->assertEquals('cafed00d-2131-4159-8e11-0b4dbadb1738', $msg->getId());
     $this->assertEquals('cafed00d-2231-4159-8e11-0b4dbadb1738', $msg->getRelayNodeId());
     $this->assertEquals('cafed00d-2331-4159-8e11-0b4dbadb1738', $msg->getSrcNodeId());
     $this->assertEquals(static::SRC1_SSL_KEY_PUB, $msg->getSrcSslKeyPub());
     $this->assertEquals('cafed00d-2431-4159-8e11-0b4dbadb1738', $msg->getDstNodeId());
     $this->assertEquals(array(21, 2, 1987, 42), $msg->getSentNodes());
     $this->assertEquals(22, $msg->getRelayCount());
     $this->assertEquals(24, $msg->getForwardCycles());
     $this->assertEquals('D', $msg->getEncryptionMode());
     $this->assertEquals('O', $msg->getStatus());
     $this->assertEquals(679874400, $msg->getTimeCreated());
     $msg = new Msg('test_data/' . $fileName);
     $msg->setDatadirBasePath('test_data');
     $this->assertTrue($msg->load());
     $msg->setDstSslPubKey(static::DST1_SSL_KEY_PUB);
     $msg->setSslKeyPrv(static::DST1_SSL_KEY_PRV, static::SSL_KEY_PRV_PASS);
     $subject = 'N/A';
     $text = 'N/A';
     try {
         $text = $msg->decrypt();
         $subject = $msg->getSubject();
     } catch (Exception $e) {
         $text = $e->getMessage();
     }
     $this->assertEquals('my first subject', $subject);
     $this->assertEquals('hello world! this is a test', $text);
     $this->assertEquals('thefox', $msg->getSrcUserNickname());
     $msg = new Msg('test_data/' . $fileName);
     $msg->setDatadirBasePath('test_data');
     $this->assertTrue($msg->load());
     $msg->setDstSslPubKey(static::DST2_SSL_KEY_PUB);
     $msg->setSslKeyPrv(static::DST2_SSL_KEY_PRV, static::SSL_KEY_PRV_PASS);
     $subject = 'N/A';
     $text = 'N/A';
     try {
         $text = $msg->decrypt();
         $subject = $msg->getSubject();
     } catch (Exception $e) {
         $text = 'FAILED OK';
     }
     $this->assertEquals('N/A', $subject);
     $this->assertEquals('FAILED OK', $text);
     $this->assertEquals('', $msg->getSrcUserNickname());
     $msg = new Msg('test_data/not_existing.yml');
     $this->assertFalse($msg->load());
 }