Skip to content

Commit

Permalink
Merge pull request #733 from jarednova/eaton-master
Browse files Browse the repository at this point in the history
Eaton master
  • Loading branch information
jarednova committed Nov 10, 2015
2 parents de48a12 + f3c30d2 commit 658413d
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 88 deletions.
8 changes: 7 additions & 1 deletion lib/image/timber-image-operation-tojpg.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ function image_create( $filename, $ext = 'auto' ) {
$ext = $ext['ext'];
}
}
$ext = strtolower($ext);
if ( $ext == 'gif' ) {
return imagecreatefromgif($filename);
}
return imagecreatefrompng($filename);
if ( $ext == 'png' ) {
return imagecreatefrompng($filename);
}
if ( $ext == 'jpg' || $ext == 'jpeg') {
return imagecreatefromjpeg($filename);
}
}
}
2 changes: 1 addition & 1 deletion lib/timber-term-getter.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@ private static function correct_taxonomy_names($taxs) {
return $taxs;
}

}
}
147 changes: 73 additions & 74 deletions tests/test-timber-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@

class TestTimberHelper extends WP_UnitTestCase {

function testCloseTagsWithSelfClosingTags(){
$p = '<p>My thing is this <hr>Whatever';
$html = TimberHelper::close_tags($p);
$this->assertEquals('<p>My thing is this <hr />Whatever</p>', $html);
}
function testCloseTagsWithSelfClosingTags(){
$p = '<p>My thing is this <hr>Whatever';
$html = TimberHelper::close_tags($p);
$this->assertEquals('<p>My thing is this <hr />Whatever</p>', $html);
}

function testCommentForm() {
$post_id = $this->factory->post->create();
$form = TimberHelper::get_comment_form($post_id);
$form = trim($form);
$this->assertStringStartsWith('<div id="respond"', $form);
}
function testCommentForm() {
$post_id = $this->factory->post->create();
$form = TimberHelper::get_comment_form($post_id);
$form = trim($form);
$this->assertStringStartsWith('<div id="respond"', $form);
}

function testWPTitle(){
function testWPTitle(){
//since we're testing with twentyfourteen -- need to remove its filters on wp_title
remove_all_filters('wp_title');
remove_theme_support( 'title-tag' );

$this->assertEquals('', TimberHelper::get_wp_title());
}

Expand All @@ -32,72 +31,72 @@ function testWPTitleSingle(){
$this->assertEquals('My New Post', TimberHelper::get_wp_title());
}

function testCloseTags(){
$str = '<a href="http://wordpress.org">Hi!';
$closed = TimberHelper::close_tags($str);
$this->assertEquals($str.'</a>', $closed);
}
function testCloseTags(){
$str = '<a href="http://wordpress.org">Hi!';
$closed = TimberHelper::close_tags($str);
$this->assertEquals($str.'</a>', $closed);
}

function testArrayToObject(){
$arr = array('jared' => 'super cool');
$obj = TimberHelper::array_to_object($arr);
$this->assertEquals('super cool', $obj->jared);
}
function testArrayToObject(){
$arr = array('jared' => 'super cool');
$obj = TimberHelper::array_to_object($arr);
$this->assertEquals('super cool', $obj->jared);
}

function testGetObjectIndexByProperty(){
$obj1 = new stdClass();
$obj1->name = 'mark';
$obj1->skill = 'acro yoga';
$obj2 = new stdClass();
$obj2->name = 'austin';
$obj2->skill = 'cooking';
$arr = array($obj1, $obj2);
$index = TimberHelper::get_object_index_by_property($arr, 'skill', 'cooking');
$this->assertEquals(1, $index);
$obj = TimberHelper::get_object_by_property($arr, 'skill', 'cooking');
$this->assertEquals('austin', $obj->name);
}
function testGetObjectIndexByProperty(){
$obj1 = new stdClass();
$obj1->name = 'mark';
$obj1->skill = 'acro yoga';
$obj2 = new stdClass();
$obj2->name = 'austin';
$obj2->skill = 'cooking';
$arr = array($obj1, $obj2);
$index = TimberHelper::get_object_index_by_property($arr, 'skill', 'cooking');
$this->assertEquals(1, $index);
$obj = TimberHelper::get_object_by_property($arr, 'skill', 'cooking');
$this->assertEquals('austin', $obj->name);
}

function testTimers() {
$start = TimberHelper::start_timer();
sleep(1);
$end = TimberHelper::stop_timer($start);
$this->assertContains(' seconds.', $end);
$time = str_replace(' seconds.', '', $end);
$this->assertGreaterThan(1, $time);
}
function testTimers() {
$start = TimberHelper::start_timer();
sleep(1);
$end = TimberHelper::stop_timer($start);
$this->assertContains(' seconds.', $end);
$time = str_replace(' seconds.', '', $end);
$this->assertGreaterThan(1, $time);
}

function testArrayTruncate() {
$arr = array('Buster', 'GOB', 'Michael', 'Lindsay');
$arr = TimberHelper::array_truncate($arr, 2);
$this->assertContains('Buster', $arr);
$this->assertEquals(2, count($arr));
$this->assertFalse(in_array('Lindsay', $arr));
}
function testArrayTruncate() {
$arr = array('Buster', 'GOB', 'Michael', 'Lindsay');
$arr = TimberHelper::array_truncate($arr, 2);
$this->assertContains('Buster', $arr);
$this->assertEquals(2, count($arr));
$this->assertFalse(in_array('Lindsay', $arr));
}

function testIsTrue() {
$true = TimberHelper::is_true('true');
$this->assertTrue($true);
$false = TimberHelper::is_true('false');
$this->assertFalse($false);
$estelleGetty = TimberHelper::is_true('Estelle Getty');
$this->assertTrue($estelleGetty);
}
function testIsTrue() {
$true = TimberHelper::is_true('true');
$this->assertTrue($true);
$false = TimberHelper::is_true('false');
$this->assertFalse($false);
$estelleGetty = TimberHelper::is_true('Estelle Getty');
$this->assertTrue($estelleGetty);
}

function testIsEven() {
$this->assertTrue(TimberHelper::iseven(2));
$this->assertFalse(TimberHelper::iseven(7));
}
function testIsEven() {
$this->assertTrue(TimberHelper::iseven(2));
$this->assertFalse(TimberHelper::iseven(7));
}

function testIsOdd() {
$this->assertFalse(TimberHelper::isodd(2));
$this->assertTrue(TimberHelper::isodd(7));
}
function testIsOdd() {
$this->assertFalse(TimberHelper::isodd(2));
$this->assertTrue(TimberHelper::isodd(7));
}

function testErrorLog() {
ob_start();
$this->assertTrue(TimberHelper::error_log('foo'));
$this->assertTrue(TimberHelper::error_log(array('Dark Helmet', 'Barf')));
$data = ob_get_flush();
}
}
function testErrorLog() {
ob_start();
$this->assertTrue(TimberHelper::error_log('foo'));
$this->assertTrue(TimberHelper::error_log(array('Dark Helmet', 'Barf')));
$data = ob_get_flush();
}
}
55 changes: 55 additions & 0 deletions tests/test-timber-image-tojpg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

class TestTimberImageToJPG extends WP_UnitTestCase {

function remove($file) {

}

function testPNGtoJPG() {
$filename = TestTimberImage::copyTestImage( 'flag.png' );
$str = Timber::compile_string('{{file|tojpg}}', array('file' => $filename));
$renamed = str_replace('.png', '.jpg', $filename);
$this->assertFileExists($renamed);
$this->assertGreaterThan(1000, filesize($renamed));
$this->assertEquals('image/png', mime_content_type($filename));
$this->assertEquals('image/jpeg', mime_content_type($renamed));
unlink($filename);
unlink($renamed);
}

function testGIFtoJPG() {
$filename = TestTimberImage::copyTestImage( 'boyer.gif' );
$str = Timber::compile_string('{{file|tojpg}}', array('file' => $filename));
$renamed = str_replace('.gif', '.jpg', $filename);
$this->assertFileExists($renamed);
$this->assertGreaterThan(1000, filesize($renamed));
$this->assertEquals('image/gif', mime_content_type($filename));
$this->assertEquals('image/jpeg', mime_content_type($renamed));
unlink($filename);
unlink($renamed);
}

function testJPGtoJPG() {
$filename = TestTimberImage::copyTestImage( 'stl.jpg' );
$original_size = filesize($filename);
$str = Timber::compile_string('{{file|tojpg}}', array('file' => $filename));
$new_size = filesize($filename);
$this->assertEquals($original_size, $new_size);
$this->assertEquals('image/jpeg', mime_content_type($filename));
unlink($filename);
}

function testJPEGtoJPG() {
$filename = TestTimberImage::copyTestImage( 'jarednova.jpeg' );
$str = Timber::compile_string('{{file|tojpg}}', array('file' => $filename));
$renamed = str_replace('.jpeg', '.jpg', $filename);
$this->assertFileExists($renamed);
$this->assertGreaterThan(1000, filesize($renamed));
$this->assertEquals('image/jpeg', mime_content_type($filename));
$this->assertEquals('image/jpeg', mime_content_type($renamed));
unlink($filename);
unlink($renamed);
}

}
30 changes: 18 additions & 12 deletions tests/test-timber-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ function testPostSlug(){
}

function testPostAuthor(){
$author_id = $this->factory->user->create(array('display_name' => 'Jared Novack'));
$author_id = $this->factory->user->create(array('display_name' => 'Jared Novack', 'user_login' => 'jared-novack'));
$pid = $this->factory->post->create(array('post_author' => $author_id));
$post = new TimberPost($pid);
$this->assertEquals('user-1', $post->author()->slug());
$this->assertEquals('jared-novack', $post->author()->slug());
$this->assertEquals('Jared Novack', $post->author()->name());
$template = 'By {{post.author}}';
$authorCompile = Timber::compile_string($template, array('post' => $post));
Expand All @@ -364,35 +364,41 @@ function testPostAuthor(){
}

function testPostAuthorInTwig(){
$author_id = $this->factory->user->create(array('display_name' => 'User 1'));
$author_id = $this->factory->user->create(array('display_name' => 'Jon Stewart', 'user_login' => 'jon-stewart'));
$pid = $this->factory->post->create(array('post_author' => $author_id));
$post = new TimberPost($pid);
$this->assertEquals('user-1', $post->author()->slug());
$this->assertEquals('User 1', $post->author()->name());
$this->assertEquals('jon-stewart', $post->author()->slug());
$this->assertEquals('Jon Stewart', $post->author()->name());
$template = 'By {{post.author}}';
$authorCompile = Timber::compile_string($template, array('post' => $post));
$template = 'By {{post.author.name}}';
$authorNameCompile = Timber::compile_string($template, array('post' => $post));
$this->assertEquals($authorCompile, $authorNameCompile);
$this->assertEquals('By User 1', $authorCompile);
$this->assertEquals('By Jon Stewart', $authorCompile);
}

function testPostModifiedAuthor() {
$author_id = $this->factory->user->create(array('display_name' => 'Woodward'));
$mod_author_id = $this->factory->user->create(array('display_name' => 'Bernstein'));
$author_id = $this->factory->user->create(array('display_name' => 'Woodward', 'user_login' => 'bob-woodward'));
$mod_author_id = $this->factory->user->create(array('display_name' => 'Bernstein', 'user_login' => 'carl-bernstein'));
$pid = $this->factory->post->create(array('post_author' => $author_id));
$post = new TimberPost($pid);
$this->assertEquals('user-1', $post->author()->slug());
$this->assertEquals('user-1', $post->modified_author()->slug());
$this->assertEquals('bob-woodward', $post->author()->slug());
$this->assertEquals('bob-woodward', $post->modified_author()->slug());
$this->assertEquals('Woodward', $post->author()->name());
$this->assertEquals('Woodward', $post->modified_author()->name());
update_post_meta($pid, '_edit_last', $mod_author_id);
$this->assertEquals('user-1', $post->author()->slug());
$this->assertEquals('user-2', $post->modified_author()->slug());
$this->assertEquals('bob-woodward', $post->author()->slug());
$this->assertEquals('carl-bernstein', $post->modified_author()->slug());
$this->assertEquals('Woodward', $post->author()->name());
$this->assertEquals('Bernstein', $post->modified_author()->name());
}

function tearDown() {
global $wpdb;
$query = "DELETE from $wpdb->users WHERE ID > 1";
$wpdb->query($query);
}

function testPostFormat() {
add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
$pid = $this->factory->post->create();
Expand Down

0 comments on commit 658413d

Please sign in to comment.