HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/delta/wp-content/themes/delta/vendor/timber/timber/tests/test-timber-comment-avatar.php
<?php

	class TestTimberCommentAvatar extends Timber_UnitTestCase {

		function testAvatarSize() {
			if ( !TestTimberImage::is_connected() ) {
				$this->markTestSkipped('Cannot test avatar images when not connected to internet');
			}
			$post_id = self::factory()->post->create();
			$comment_id = self::factory()->comment->create(array('comment_post_ID' => $post_id));
			$comment = new TimberComment($comment_id);

			# test default gravatr holding image
			$avatar = $comment->avatar("mystery");

			$this->assertTrue(substr ( $avatar , 0, 5 ) == "http:");
		}

		function testAvatarFalse() {
			update_option('show_avatars', false);
			$post_id = self::factory()->post->create();
			$comment_id = self::factory()->comment->create(array('comment_post_ID' => $post_id));
			$comment = new TimberComment($comment_id);

			# test default gravatr holding image
			$avatar = $comment->avatar();

			$this->assertFalse($avatar);
		}

		function testAvatarBlank() {
			if ( !TestTimberImage::is_connected() ) {
				$this->markTestSkipped('Cannot test avatar images when not connected to internet');
			}
			$post_id = self::factory()->post->create();
			$comment_id = self::factory()->comment->create(array('comment_post_ID' => $post_id));
			$comment = new TimberComment($comment_id);

			# test default gravatr holding image
			$avatar = $comment->avatar(92, "blank");

			$this->assertTrue(substr ( $avatar , 0, 5 ) == "http:");
		}

		function testAvatarGravatarDefault() {
			if ( !TestTimberImage::is_connected() ) {
				$this->markTestSkipped('Cannot test avatar images when not connected to internet');
			}
			$post_id = self::factory()->post->create();
			$comment_id = self::factory()->comment->create(array('comment_post_ID' => $post_id));
			$comment = new TimberComment($comment_id);

			# test default gravatr holding image
			$avatar = $comment->avatar(92, "gravatar_default");

			$this->assertTrue(substr ( $avatar , 0, 5 ) == "http:");
		}

		function testGravatar() {
			if (!TestTimberImage::is_connected()){
				$this->markTestSkipped('Cannot test avatar images when not connected to internet');
			}
			$post_id = self::factory()->post->create();
			$comment_id = self::factory()->comment->create(array('comment_post_ID' => $post_id, 'comment_author' => 'jarednova', 'comment_author_email' => 'jarednova@upstatement.com'));
			$comment = new TimberComment($comment_id);
			$gravatar = md5(file_get_contents($comment->avatar()));
			/* this keeps changing b/c of compression tweaks on WP.org, disabling the test */
			//$this->assertEquals($gravatar, md5(file_get_contents(dirname(__FILE__).'/assets/jarednova.jpeg')));

			$comment_id = self::factory()->comment->create(array('comment_post_ID' => $post_id, 'comment_author' => 'jarednova', 'comment_author_email' => 'notjared@upstatement.com'));
			$comment = new TimberComment($comment_id);
			$not_gravatar = md5(file_get_contents($comment->avatar()));
			$this->assertNotEquals($not_gravatar, md5(file_get_contents(dirname(__FILE__).'/assets/jarednova.jpeg')));
		}

		function testAvatarSimple(){
			if (!TestTimberImage::is_connected()){
				$this->markTestSkipped('Cannot test avatar images when not connected to internet');
			}
			$theme_url = get_theme_root_uri().'/'.get_stylesheet();
			$post_id = self::factory()->post->create();
			$comment_id = self::factory()->comment->create(array('comment_post_ID' => $post_id));
			$comment = new TimberComment($comment_id);

			# test default gravatr holding image
			$avatar = $comment->avatar(32, "mystery");

			$this->assertTrue(substr ( $avatar , 0, 5 ) == "http:");

			# does it work if its SSL?
			$_SERVER['HTTPS'] = 'on';
			$avatar = $comment->avatar(32, "mystery");
			$this->assertTrue(200 === $this->crawl($avatar));
			$this->assertTrue(substr ( $avatar , 0, 6 ) == "https:");
			$_SERVER['HTTPS'] = 'off';

			# pass custom url on different domain. can't check by crawling as
			# i get a 302 regardless of default url
			# so just check it comes back with it in the url
			$this->valid_avatar($comment, "http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png");

			# same domain.
			$this->valid_avatar($comment, $theme_url . "/images/default.png");

			#relative
			$default_url = "/images/default.png";
			$avatar = $comment->avatar(32, $default_url );
			if (strstr($avatar, '?')){
	  			list($url, $params) = explode('?', $avatar);
	  			$default_url = $theme_url . $default_url;
	  			# you get back the absoulte url to default in the avatar url?
	  			$this->assertEquals($params, "d=$default_url&amp;s=32");
	  		}
	  		# you get back url?
	  		$this->assertTrue(substr ( $theme_url. $avatar , 0, 5 ) == "http:");
		}


		function valid_avatar($comment, $default_url){
			$avatar = $comment->avatar(32, $default_url);
			if (strstr($avatar, '?')){
	  			list($url, $params) = explode('?', $avatar);
	  			# you get back the default in the avatar url?
	  			$this->assertEquals($params, "d=$default_url&amp;s=32");
	  		}
	  		# you get back url?
	  		$this->assertTrue(substr ( $avatar , 0, 5 ) == "http:");
		}


		function crawl($url){
			$handle = curl_init($url);
			curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE);
			/* Get the HTML or whatever is linked in $url. */
			$response = curl_exec($handle);
			/* Check for 404 (file not found). */
			$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
			curl_close($handle);
	  		return $httpCode;
		}

	}