Path: blob/master/src/applications/diffusion/protocol/__tests__/DiffusionSubversionWireProtocolTestCase.php
12242 views
<?php12final class DiffusionSubversionWireProtocolTestCase3extends PhabricatorTestCase {45public function testSubversionWireProtocolParser() {6$this->assertSameSubversionMessages(7'( ) ',8array(9array(10),11));1213$this->assertSameSubversionMessages(14'( duck 5:quack 42 ( item1 item2 ) ) ',15array(16array(17array(18'type' => 'word',19'value' => 'duck',20),21array(22'type' => 'string',23'value' => 'quack',24),25array(26'type' => 'number',27'value' => 42,28),29array(30'type' => 'list',31'value' => array(32array(33'type' => 'word',34'value' => 'item1',35),36array(37'type' => 'word',38'value' => 'item2',39),40),41),42),43));4445$this->assertSameSubversionMessages(46'( msg1 ) ( msg2 ) ',47array(48array(49array(50'type' => 'word',51'value' => 'msg1',52),53),54array(55array(56'type' => 'word',57'value' => 'msg2',58),59),60));6162// This is testing that multiple spaces are parsed correctly. See T1314063// for discussion.64$this->assertSameSubversionMessages(65'( get-file true false ) ',66// ^-- Note extra space!67array(68array(69array(70'type' => 'word',71'value' => 'get-file',72),73array(74'type' => 'word',75'value' => 'true',76),77array(78'type' => 'word',79'value' => 'false',80),81),82),83'( get-file true false ) ');8485$this->assertSameSubversionMessages(86'( duck 5:quack moo ) ',87array(88array(89array(90'type' => 'word',91'value' => 'duck',92),93array(94'type' => 'string',95'value' => 'quack',96),97array(98'type' => 'word',99'value' => 'moo',100),101),102),103'( duck 5:quack moo ) ');104105}106107public function testSubversionWireProtocolPartialFrame() {108$proto = new DiffusionSubversionWireProtocol();109110// This is primarily a test that we don't hang when we write() a frame111// which straddles a string boundary.112$msg1 = $proto->writeData('( duck 5:qu');113$msg2 = $proto->writeData('ack ) ');114115$this->assertEqual(array(), ipull($msg1, 'structure'));116$this->assertEqual(117array(118array(119array(120'type' => 'word',121'value' => 'duck',122),123array(124'type' => 'string',125'value' => 'quack',126),127),128),129ipull($msg2, 'structure'));130}131132private function assertSameSubversionMessages(133$string,134array $structs,135$serial_string = null) {136137$proto = new DiffusionSubversionWireProtocol();138139// Verify that the wire message parses into the structs.140$messages = $proto->writeData($string);141$messages = ipull($messages, 'structure');142$this->assertEqual($structs, $messages, 'parse<'.$string.'>');143144// Verify that the structs serialize into the wire message.145$serial = array();146foreach ($structs as $struct) {147$serial[] = $proto->serializeStruct($struct);148}149$serial = implode('', $serial);150151if ($serial_string === null) {152$expect_serial = $string;153} else {154$expect_serial = $serial_string;155}156157$this->assertEqual($expect_serial, $serial, 'serialize<'.$string.'>');158}159}160161162