Ejemplo n.º 1
0
 public function testIterationWithEmptyListPushed()
 {
     $map = new SS_Map(new ArrayList());
     $map->push('1', 'pushed');
     $text = "";
     foreach ($map as $k => $v) {
         $text .= "{$k}: {$v}\n";
     }
     $this->assertEquals("1: pushed\n", $text);
 }
Ejemplo n.º 2
0
 function testUnshift()
 {
     $list = DataObjectTest_TeamComment::get();
     $map = new SS_Map($list, 'Name', 'Comment');
     $map->unshift(-1, '(All)');
     $this->assertEquals(array(-1 => "(All)", "Joe" => "This is a team comment by Joe", "Bob" => "This is a team comment by Bob", "Phil" => "Phil is a unique guy, and comments on team2"), $map->toArray());
     $map->unshift(0, '(Select)');
     $this->assertEquals('(All)', $map[-1]);
     $this->assertEquals('(Select)', $map[0]);
     $this->assertEquals(array(0 => "(Select)", -1 => "(All)", "Joe" => "This is a team comment by Joe", "Bob" => "This is a team comment by Bob", "Phil" => "Phil is a unique guy, and comments on team2"), $map->toArray());
     $map->unshift("Bob", "Replaced");
     $this->assertEquals(array("Bob" => "Replaced", 0 => "(Select)", -1 => "(All)", "Joe" => "This is a team comment by Joe", "Phil" => "Phil is a unique guy, and comments on team2"), $map->toArray());
     $map->unshift("Phil", "Replaced as well");
     $this->assertEquals(array("Phil" => "Replaced as well", "Bob" => "Replaced", 0 => "(Select)", -1 => "(All)", "Joe" => "This is a team comment by Joe"), $map->toArray());
     $map->unshift("Joe", "Replaced the last one");
     $this->assertEquals(array("Joe" => "Replaced the last one", "Phil" => "Replaced as well", "Bob" => "Replaced", 0 => "(Select)", -1 => "(All)"), $map->toArray());
 }