<commit_before><?php
$base = realpath(dirname(__FILE__).'/../');
require_once($base . DIRECTORY_SEPARATOR . 'src/Cloudinary.php');
class CloudinaryTest extends PHPUnit_Framework_TestCase {
    public function setUp() {
        Cloudinary::config(array("cloud_name"=>"test123", "secure_distribution" => NULL, "private_cdn" => FALSE));
    }

    public function test_cloud_name() {
        // should use cloud_name from config
        $result = Cloudinary::cloudinary_url("test");
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/test", $result);
    }

    public function test_cloud_name_options() {
        // should allow overriding cloud_name in $options
        $options = array("cloud_name" => "test321");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://res.cloudinary.com/test321/image/upload/test", $result);
    }
    
    public function test_secure_distribution() {
        // should use default secure distribution if secure=TRUE        
        $options = array("secure" => TRUE);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("https://res.cloudinary.com/test123/image/upload/test", $result);
    }

    public function test_secure_distribution_overwrite() {
        // should allow overwriting secure distribution if secure=TRUE        
        $options = array("secure" => TRUE, "secure_distribution" => "something.else.com");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("https://something.else.com/test123/image/upload/test", $result);
    }

    public function test_secure_distibution() {
        // should take secure distribution from config if secure=TRUE
        Cloudinary::config(array("secure_distribution" => "config.secure.distribution.com"));
        $options = array("secure" => TRUE);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("https://config.secure.distribution.com/test123/image/upload/test", $result);
    }

    public function test_secure_akamai() {
        // should default to akamai if secure is given with private_cdn and no secure_distribution
        $options = array("secure" => TRUE, "private_cdn" => TRUE);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("https://test123-res.cloudinary.com/image/upload/test", $result);
    }

    public function test_secure_non_akamai() {
        // should not add cloud_name if private_cdn and secure non akamai secure_distribution
        $options = array("secure" => TRUE, "private_cdn" => TRUE, "secure_distribution" => "something.cloudfront.net");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("https://something.cloudfront.net/image/upload/test", $result);
    }

    public function test_http_private_cdn() {
        // should not add cloud_name if private_cdn and not secure
        $options = array("private_cdn" => TRUE);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://test123-res.cloudinary.com/image/upload/test", $result);
    }

    public function test_format() {
        // should use format from $options        
        $options = array("format" => "jpg");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/test.jpg", $result);
    }

    public function test_crop() {
        // should use width and height from $options even if crop is not given
        $options = array("width" => 100, "height" => 100);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/h_100,w_100/test", $result);
        $this->assertEquals(array("width" => 100, "height" => 100), $options);
        $options = array("width" => 100, "height" => 100, "crop" => "crop");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array("width" => 100, "height" => 100), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/c_crop,h_100,w_100/test", $result);
    }
    
    public function test_various_options() {
        // should use x, y, radius, prefix, gravity and quality from $options        
        $options = array("x" => 1, "y" => 2, "radius" => 3, "gravity" => "center", "quality" => 0.4, "prefix" => "a", "opacity" => 20);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/g_center,o_20,p_a,q_0.4,r_3,x_1,y_2/test", $result);
    }
    
    public function test_transformation_simple() {
        // should support named tranformation        
        $options = array("transformation" => "blip");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/t_blip/test", $result);
    }

    public function test_transformation_array() {
        // should support array of named tranformations        
        $options = array("transformation" => array("blip", "blop"));
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/t_blip.blop/test", $result);
    }

    public function test_base_transformations() {
        // should support base tranformation        
        $options = array("transformation" => array("x" => 100, "y" => 100, "crop" => "fill"), "crop" => "crop", "width" => 100);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array("width" => 100), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/c_fill,x_100,y_100/c_crop,w_100/test", $result);
    }

    public function test_base_transformation_array() {
        // should support array of base tranformations        
        $options = array("transformation" => array(array("x" => 100, "y" => 100, "width" => 200, "crop" => "fill"), array("radius" => 10)), "crop" => "crop", "width" => 100);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array("width" => 100), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/c_fill,w_200,x_100,y_100/r_10/c_crop,w_100/test", $result);
    }

    public function test_no_empty_transformation() {
        // should not include empty tranformations        
        $options = array("transformation" => array(array(), array("x" => 100, "y" => 100, "crop" => "fill"), array()));
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/c_fill,x_100,y_100/test", $result);
    }

    public function test_size() {
        // should support size        
        $options = array("size" => "10x10", "crop" => "crop");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array("width" => "10", "height" => "10"), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/c_crop,h_10,w_10/test", $result);
    }

    public function test_type() {
        // should use type from $options
        $options = array("type" => "facebook");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);<commit_msg>Added test_no_empty_options() to test empty parameters and zero values. Fixed some typos.<commit_after><?php
$base = realpath(dirname(__FILE__).'/../');
require_once($base . DIRECTORY_SEPARATOR . 'src/Cloudinary.php');
class CloudinaryTest extends PHPUnit_Framework_TestCase {
    public function setUp() {
        Cloudinary::config(array("cloud_name"=>"test123", "secure_distribution" => NULL, "private_cdn" => FALSE));
    }

    public function test_cloud_name() {
        // should use cloud_name from config
        $result = Cloudinary::cloudinary_url("test");
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/test", $result);
    }

    public function test_cloud_name_options() {
        // should allow overriding cloud_name in $options
        $options = array("cloud_name" => "test321");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://res.cloudinary.com/test321/image/upload/test", $result);
    }
    
    public function test_secure_distribution() {
        // should use default secure distribution if secure=TRUE        
        $options = array("secure" => TRUE);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("https://res.cloudinary.com/test123/image/upload/test", $result);
    }

    public function test_secure_distribution_overwrite() {
        // should allow overwriting secure distribution if secure=TRUE        
        $options = array("secure" => TRUE, "secure_distribution" => "something.else.com");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("https://something.else.com/test123/image/upload/test", $result);
    }

    public function test_secure_distibution() {
        // should take secure distribution from config if secure=TRUE
        Cloudinary::config(array("secure_distribution" => "config.secure.distribution.com"));
        $options = array("secure" => TRUE);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("https://config.secure.distribution.com/test123/image/upload/test", $result);
    }

    public function test_secure_akamai() {
        // should default to akamai if secure is given with private_cdn and no secure_distribution
        $options = array("secure" => TRUE, "private_cdn" => TRUE);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("https://test123-res.cloudinary.com/image/upload/test", $result);
    }

    public function test_secure_non_akamai() {
        // should not add cloud_name if private_cdn and secure non akamai secure_distribution
        $options = array("secure" => TRUE, "private_cdn" => TRUE, "secure_distribution" => "something.cloudfront.net");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("https://something.cloudfront.net/image/upload/test", $result);
    }

    public function test_http_private_cdn() {
        // should not add cloud_name if private_cdn and not secure
        $options = array("private_cdn" => TRUE);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://test123-res.cloudinary.com/image/upload/test", $result);
    }

    public function test_format() {
        // should use format from $options        
        $options = array("format" => "jpg");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/test.jpg", $result);
    }

    public function test_crop() {
        // should use width and height from $options even if crop is not given
        $options = array("width" => 100, "height" => 100);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/h_100,w_100/test", $result);
        $this->assertEquals(array("width" => 100, "height" => 100), $options);
        $options = array("width" => 100, "height" => 100, "crop" => "crop");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array("width" => 100, "height" => 100), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/c_crop,h_100,w_100/test", $result);
    }
    
    public function test_various_options() {
        // should use x, y, radius, prefix, gravity and quality from $options        
        $options = array("x" => 1, "y" => 2, "radius" => 3, "gravity" => "center", "quality" => 0.4, "prefix" => "a", "opacity" => 20);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/g_center,o_20,p_a,q_0.4,r_3,x_1,y_2/test", $result);
    }

    public function test_no_empty_options() {
        // should use x, y, width, height, crop, prefix and opacity from $options
        $options = array("x" => 0, "y" => '0', "width" => '', "height" => "", "crop" => ' ', "prefix" => false, "opacity" => null);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/x_0,y_0/test", $result);
    }
    
    public function test_transformation_simple() {
        // should support named transformation        
        $options = array("transformation" => "blip");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/t_blip/test", $result);
    }

    public function test_transformation_array() {
        // should support array of named transformations        
        $options = array("transformation" => array("blip", "blop"));
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/t_blip.blop/test", $result);
    }

    public function test_base_transformations() {
        // should support base transformation        
        $options = array("transformation" => array("x" => 100, "y" => 100, "crop" => "fill"), "crop" => "crop", "width" => 100);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array("width" => 100), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/c_fill,x_100,y_100/c_crop,w_100/test", $result);
    }

    public function test_base_transformation_array() {
        // should support array of base transformations        
        $options = array("transformation" => array(array("x" => 100, "y" => 100, "width" => 200, "crop" => "fill"), array("radius" => 10)), "crop" => "crop", "width" => 100);
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array("width" => 100), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/c_fill,w_200,x_100,y_100/r_10/c_crop,w_100/test", $result);
    }

    public function test_no_empty_transformation() {
        // should not include empty transformations        
        $options = array("transformation" => array(array(), array("x" => 100, "y" => 100, "crop" => "fill"), array()));
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/c_fill,x_100,y_100/test", $result);
    }

    public function test_size() {
        // should support size        
        $options = array("size" => "10x10", "crop" => "crop");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array("width" => "10", "height" => "10"), $options);
        $this->assertEquals("http://res.cloudinary.com/test123/image/upload/c_crop,h_10,w_10/test", $result);
    }

    public function test_type() {
        // should use type from $options
        $options = array("type" => "facebook");
        $result = Cloudinary::cloudinary_url("test", $options);
        $this->assertEquals(array(), $options);
{'fraction_non_alphanumeric': 0.16868548242735246, 'fraction_numerical': 0.02225669789366907, 'mean_word_length': 3.3668577384054195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 202, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4520264', 'n_tokens_mistral': 5211, 'n_tokens_neox': 4846, 'n_words': 950}