示例#1
0
 /**
  * specific search image function, build query url and parse json result.
  *
  * @param $text
  * @param $numPerPage
  * @param $pageSeq
  * @return array
  */
 public function search_image($text, $numPerPage, $pageSeq)
 {
     $response = $this->send_request($text, $numPerPage, $pageSeq);
     $result = json_decode($response, true);
     $images = array();
     $total_num = null;
     if (isset($result['stat']) && $result['stat'] == 'ok') {
         $total_num = $result['photos']['total'];
         foreach ($result['photos']['photo'] as $photo) {
             $images[] = Wrapper\Flickrimage::from_array($photo);
         }
     }
     return array($images, $total_num);
 }
示例#2
0
 public function test_from_array()
 {
     $raw_array = array();
     $raw_array['id'] = '21429256362';
     $raw_array['owner'] = '27889738';
     $raw_array['secret'] = '711f03378e';
     $raw_array['server'] = '5647';
     $raw_array['farm'] = 6;
     $raw_array['title'] = 'Panel for Patriot PAC-3 Guided Missile Round Trainer at JASDF Yokota Festival 2014';
     $raw_array['ispublic'] = 1;
     $raw_array['isfriend'] = 0;
     $raw_array['isfamily'] = 0;
     $flickrimage = Wrapper\Flickrimage::from_array($raw_array);
     $this->assertEquals($this->flickrimage, $flickrimage);
 }
示例#3
0
 public function test_mock_search_image()
 {
     $text = "BMW";
     $numPerPage = 5;
     $pageSeq = 1;
     $flickrapi = $this->getMockBuilder('FlickrSearch\\Model\\FlickrAPI')->setMethods(array('send_request'))->getMock();
     $flickrapi->expects($this->once())->method('send_request')->willReturn($this->get_test_data_json());
     list($images, $total_images_num) = $flickrapi->search_image($text, $numPerPage, $pageSeq);
     $test_json = json_decode($this->get_test_data_json(), true);
     $expected_images = array();
     $expected_total_images_number = $test_json['photos']['total'];
     foreach ($test_json['photos']['photo'] as $photo) {
         $expected_images[] = Wrapper\Flickrimage::from_array($photo);
     }
     $expected_images = array(new Wrapper\Flickrimage("21429256362", "27889738@N07", "711f03378e", "5647", 6, "Panel for Patriot PAC-3 Guided Missile Round Trainer at JASDF Yokota Festival 2014", 1, 0, 0), new Wrapper\Flickrimage("21194609688", "27889738@N07", "2afdd89062", "657", 1, "JASDF Yokota Festival in Yokota Friendship Festival 2014", 1, 0, 0), new Wrapper\Flickrimage("20844454434", "27889738@N07", "ff41cef669", "741", 1, "Fighter Aircfrafts in Yokota Friendship Festival 2014", 1, 0, 0), new Wrapper\Flickrimage("21225757978", "27889738@N07", "55f66e3d98", "5685", 6, "Patriot PAC-3 Guided Missile Round Trainer Displayed at JASDF Yokota Festival 2014", 1, 0, 0), new Wrapper\Flickrimage("21071084118", "50484221@N07", "f67c269f27", "5833", 6, "Novembers Doom (Acoustic set), 05/09/2015", 1, 0, 0));
     $this->assertEquals($expected_images, $images);
     $this->assertEquals($expected_total_images_number, $total_images_num);
 }