Пример #1
0
 function assertThereIsAnArrayElementContaining($text, $array, $message = null)
 {
     $this->assertGreaterThan(0, count($array), 'The array is empty.');
     $message = $message ? $message : "No array element contains '{$text}'";
     $this->assertTrue(gp_array_any(function ($e) use($text) {
         return gp_in($text, $e);
     }, $array), $message);
 }
Пример #2
0
 function test_gp_array_any()
 {
     $this->assertEquals(false, gp_array_any('intval', array(0)));
     $this->assertEquals(false, gp_array_any(returner(false), array(1, 2, 3, 4)));
     $this->assertEquals(false, gp_array_any(returner(true), array()));
     $this->assertEquals(true, gp_array_any(returner(true), array(1, 2, 3, 4)));
     $this->assertEquals(true, gp_array_any(returner('$x', '$x % 2'), array(1, 2, 3, 4)));
 }
Пример #3
0
 public function set_difference_from($other_project)
 {
     $this_sets = (array) GP::$translation_set->by_project_id($this->id);
     $other_sets = (array) GP::$translation_set->by_project_id($other_project->id);
     $added = array();
     $removed = array();
     foreach ($other_sets as $other_set) {
         if (!gp_array_any(array($this, '_compare_set_item'), $this_sets, $other_set)) {
             $added[] = $other_set;
         }
     }
     foreach ($this_sets as $this_set) {
         if (!gp_array_any(array($this, '_compare_set_item'), $other_sets, $this_set)) {
             $removed[] = $this_set;
         }
     }
     return array('added' => $added, 'removed' => $removed);
 }
Пример #4
0
 function set_difference_from($other_project)
 {
     $this_sets = (array) GP::$translation_set->by_project_id($this->id);
     $other_sets = (array) GP::$translation_set->by_project_id($other_project->id);
     $added = array();
     $removed = array();
     foreach ($other_sets as $other_set) {
         $found = gp_array_any(function ($set) use($other_set) {
             return $set->locale == $other_set->locale && ($set->slug = $other_set->slug);
         }, $this_sets);
         if (!$found) {
             $added[] = $other_set;
         }
     }
     foreach ($this_sets as $this_set) {
         $found = gp_array_any(function ($set) use($this_set) {
             return $set->locale == $this_set->locale && ($set->slug = $this_set->slug);
         }, $other_sets);
         if (!$found) {
             $removed[] = $this_set;
         }
     }
     return array('added' => $added, 'removed' => $removed);
 }