function testInitFromURL()
 {
     $destination_path = $this->copyTestImage();
     $destination_url = str_replace(ABSPATH, 'http://' . $_SERVER['HTTP_HOST'] . '/', $destination_path);
     $image = new TimberImage($destination_url);
     $this->assertEquals($destination_url, $image->get_src());
     $this->assertEquals($destination_url, (string) $image);
 }
 function testFalseParent()
 {
     $pid = $this->factory->post->create();
     $filename = TestTimberImage::copyTestImage('arch.jpg');
     $attachment = array('post_title' => 'The Arch', 'post_content' => '');
     $iid = wp_insert_attachment($attachment, $filename, $pid);
     update_post_meta($iid, 'architect', 'Eero Saarinen');
     $image = new TimberImage($iid);
     $parent = $image->parent();
     $this->assertEquals($pid, $parent->ID);
     $this->assertFalse($parent->parent());
 }
 function testImageResizeRetinaFilter()
 {
     $filename = TestTimberImage::copyTestImage('eastern.jpg');
     $wp_filetype = wp_check_filetype(basename($filename), null);
     $post_id = $this->factory->post->create();
     $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($filename)), 'post_excerpt' => '', 'post_status' => 'inherit');
     $attach_id = wp_insert_attachment($attachment, $filename, $post_id);
     add_post_meta($post_id, '_thumbnail_id', $attach_id, true);
     $data = array();
     $data['post'] = new TimberPost($post_id);
     $str = '{{post.thumbnail.src|resize(100, 50)|retina(3)}}';
     $compiled = Timber::compile_string($str, $data);
     $img = new TimberImage($compiled);
     $this->assertContains('@3x', $compiled);
     $this->assertEquals(300, $img->width());
 }
示例#4
0
 protected function get_publisher_logo()
 {
     if ($this->logo_url) {
         $logo_obj = new \TimberImage($this->logo_url);
         $logo_schema_item = array();
         $logo_schema_item['@type'] = 'ImageObject';
         if ($logo_obj->src()) {
             $logo_schema_item['contentUrl'] = $logo_obj->src();
             $logo_schema_item['url'] = $logo_obj->src();
         }
         if ($logo_obj->width) {
             $logo_schema_item['width'] = $logo_obj->width;
         }
         if ($logo_obj->height) {
             $logo_schema_item['height'] = $logo_obj->height;
         }
         return $logo_schema_item;
     }
 }
示例#5
0
 function testInitFromURL()
 {
     $destination_path = self::copyTestImage();
     $destination_path = TimberURLHelper::get_rel_path($destination_path);
     $destination_url = 'http://' . $_SERVER['HTTP_HOST'] . $destination_path;
     $image = new TimberImage($destination_url);
     $this->assertEquals($destination_url, $image->get_src());
     $this->assertEquals($destination_url, (string) $image);
 }
示例#6
0
 function testTimberImageFromAttachment()
 {
     $iid = self::get_image_attachment();
     $image = new TimberImage($iid);
     $post = get_post($iid);
     $str = '{{ TimberImage(post).src }}';
     $result = Timber::compile_string($str, array('post' => $post));
     $this->assertEquals($image->src(), $result);
 }
示例#7
0
 function testPathInfo()
 {
     $filename = self::copyTestImage('arch.jpg');
     $image = new TimberImage($filename);
     $path_parts = $image->get_pathinfo();
     $this->assertEquals('jpg', $path_parts['extension']);
 }
 /**
  * @param $attachment_id
  */
 public function __construct($attachment_id)
 {
     parent::__construct($attachment_id);
 }