<commit_before><?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
  }
}<commit_msg>added one more test case for tidy-service: string ends in a period<commit_after><?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_excerpt_doesnt_return_too_many_periods() {
    $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
  }
}
{'fraction_non_alphanumeric': 0.14978632478632478, 'fraction_numerical': 0.002777777777777778, 'mean_word_length': 5.0167095115681235, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 91, 'https://': 0, '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': '4647678', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1624, 'n_words': 260}