Esempio n. 1
0
 public function testGetPairs()
 {
     // Cleanup
     Keyword::deleteAll();
     $core_field_key = 'name';
     $numeric_field_key = 'heat_level';
     $string_field_key = 'external_url';
     // Cleanup
     Keyword::deleteAll();
     // Create posts
     $expected_pairs = array();
     for ($i = 0; $i < 50; $i++) {
         $keyword = new Keyword();
         $keyword->{$core_field_key} = 'keyword_' . str_pad($i, 5, '0', STR_PAD_LEFT);
         $keyword->{$string_field_key} = $i;
         $keyword->{$numeric_field_key} = $i;
         $term_id = $keyword->save();
         $expected_pairs[$term_id] = 'keyword_' . str_pad($i, 5, '0', STR_PAD_LEFT);
     }
     // getPairs
     $pairs = Keyword::getPairs();
     $this->assertEquals(50, count($pairs));
     $this->assertEquals($expected_pairs, $pairs);
     // limit
     $pairs = Keyword::getPairs(array('number' => 5));
     $this->assertEquals(5, count($pairs));
     // getPairs by core field
     $core_expected_pairs = array_slice($expected_pairs, 0, 15, true);
     $pairs = Keyword::getPairsBy($core_field_key, 'keyword_' . str_pad(15, 5, '0', STR_PAD_LEFT), '<');
     asort($pairs);
     asort($core_expected_pairs);
     $this->assertEquals($core_expected_pairs, $pairs);
     // getPairsBy meta field numeric
     $pairs = Keyword::getPairsBy($numeric_field_key, 20, '<');
     $this->assertEquals(20, count($pairs));
     $this->assertEquals(array_slice($expected_pairs, 0, 20, true), $pairs);
     // getPairsBy meta field string
     $string_meta_expected_pairs = array_slice($expected_pairs, 0, 15, true);
     $pairs = Keyword::getPairsBy($string_field_key, 15, '<');
     asort($pairs);
     asort($string_meta_expected_pairs);
     $this->assertEquals($string_meta_expected_pairs, $pairs);
 }