Skip to content

Commit

Permalink
Merge dfd8845 into c8a1ebb
Browse files Browse the repository at this point in the history
  • Loading branch information
rraub committed Sep 18, 2015
2 parents c8a1ebb + dfd8845 commit ced68c7
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/tidy-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public function excerpt( $content_excerpt, $words = 50 ) {
$content = self::normalize_html_string( $content_excerpt );
$content = trim( $content );
// If we only have 1 paragraph and less than $words words, reset the content
// to the full event content
if ( count( explode( ' ', $content ) ) < $words ) {
// to the full content
if ( count( explode( ' ', $content ) ) <= $words ) {
return $content;
} else {
// We have some trimming to do
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/date-utilities-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
* @group utility
*/
class Date_Utilities_Test extends \PHPUnit_Framework_TestCase {

protected function setUp() {
// Our test cases assume a UTC timezone is defined
date_default_timezone_set( 'UTC' );
}

function test_date_turns_into_correct_calendar_representation() {
$timestamp = '1441746685';
$expected_date = '20150908T211125';
Expand Down
64 changes: 64 additions & 0 deletions tests/unit/tidy-service-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Nectary\Tests;

use Nectary\Services\Tidy_Service;

/**
* @group service
*/
class Tidy_Service_Test extends \PHPUnit_Framework_TestCase {
private $tidy_service;
private $tidy_service_mock;

protected function setUp() {
$this->tidy_service = new Tidy_Service();
$this->tidy_service_mock = $this->getMockBuilder( 'Nectary\Services\Tidy_Service' )
->setMethods( [ 'excerpt', 'normalize_html_string', 'tidy_parse_string'] )
->getMock();
}

function test_normalize_html_string_with_empty_string() {
$this->assertEquals( '', $this->tidy_service->normalize_html_string(' ') );
}

function test_normalize_html_string_in_html_tags() {
$this->assertEquals( 'content', $this->tidy_service->normalize_html_string( '<p> content </p>' ) );
}

function test_normalize_html_string_can_urldecode() {
$this->assertEquals( '&', $this->tidy_service->normalize_html_string( '&amp;' ) );
}

function test_normalize_html_string_can_urldecode_and_return_html() {
$this->assertEquals( '<b>word</b>', $this->tidy_service->normalize_html_string( '&lt;b&gt;word&lt;/b&gt;' ) );
}

function test_normalize_html_string_can_prevent_multiple_spaces() {
$this->assertEquals( 'foo bar', $this->tidy_service->normalize_html_string( ' foo bar' ) );
}

function test_excerpt_that_is_short_of_the_max_lenght() {
$this->assertEquals( 'two words', $this->tidy_service->excerpt( 'two words', 50 ) );
}

function test_excerpt_with_the_exact_lenght() {
$this->assertEquals( 'two words', $this->tidy_service->excerpt( 'two words', 2 ) );
}

function test_excerpt_that_is_too_long() {
$this->assertEquals( 'two...', $this->tidy_service->excerpt( 'two words', 1 ) );
}

function test_excerpt_removes_html() {
$this->assertEquals( 'two words', $this->tidy_service->excerpt( '<p>two words</p>', 2 ) );
}

function test_excerpt_doesnt_return_invalid_html() {
$this->assertEquals( 'more than...', $this->tidy_service->excerpt( '<p>more than two words', 2 ) );
}

function test_fallback_on_tidy_parse_string_library_missing() {
// TODO: test the behavior when the global function tidy_parse_string isn't defined
}
}

0 comments on commit ced68c7

Please sign in to comment.