<commit_before><?php
namespace Nexendrie\Translation\Bridges\Tracy;

use Tester\Assert;

require __DIR__ . "/../../../../bootstrap.php";

class PanelTest extends \Tester\TestCase {
  use \Testbench\TCompiledContainer;
  
  /** @var TranslationPanel */
  protected $panel;
  
  function setUp() {
    $this->panel = $this->getService(TranslationPanel::class);
  }
  
  function testGetTab() {
    $result = $this->panel->getTab();
    Assert::type("string", $result);
    $r = new \SimpleXMLElement($result);
    Assert::same("Translation", (string) $r["title"]);
    Assert::contains("en", (string) $r);
  }
  
  function testGetPanel() {
    $result = $this->panel->getPanel();
    Assert::type("string", $result);
    $r = new \SimpleXMLElement("<root>$result</root>");
    Assert::same(5, $r->count());
    Assert::same("Untranslated message: 0, loaded resources 0", (string) $r->p);
    Assert::same("Resolved language", (string) $r->div->h1);
    foreach($r->div->table->tr->children() as $i => $td) {
      if($i === 0) Assert::same("ManualLocaleResolver", (string) $td);
      elseif($i === 1) Assert::same("en", (string) $td);
    }
    foreach($r->children() as $i1 => $div) {
      if($i1 === 1) {
        Assert::same("Loaded resources", (string) $div->h1);
        foreach($div->table->th as $i2 => $td) {
          if($i2 === 0) Assert::same("Domain", (string) $td);
          elseif($i2 === 1) Assert::same("Filename", (string) $td);
        }
      } elseif($i1 === 2) {
        Assert::count(0, $div->children());
      }
    }
  }
}

$test = new PanelTest;
$test->run();
?><commit_msg>added more tests for translations panel<commit_after><?php
namespace Nexendrie\Translation\Bridges\Tracy;

use Tester\Assert,
    Nexendrie\Translation\Translator;

require __DIR__ . "/../../../../bootstrap.php";

class PanelTest extends \Tester\TestCase {
  use \Testbench\TCompiledContainer;
  
  /** @var TranslationPanel */
  protected $panel;
  
  function setUp() {
    $this->panel = $this->getService(TranslationPanel::class);
  }
  
  function testGetTab() {
    $result = $this->panel->getTab();
    Assert::type("string", $result);
    $r = new \SimpleXMLElement($result);
    Assert::same("Translation", (string) $r["title"]);
    Assert::contains("en", (string) $r);
  }
  
  function testGetPanel() {
    $result = $this->panel->getPanel();
    Assert::type("string", $result);
    $r = new \SimpleXMLElement("<root>$result</root>");
    Assert::same(5, $r->count());
    Assert::same("Untranslated message: 0, loaded resources 0", (string) $r->p);
    Assert::same("Resolved language", (string) $r->div->h1);
    foreach($r->div->table->tr->children() as $i => $td) {
      if($i === 0) Assert::same("ManualLocaleResolver", (string) $td);
      elseif($i === 1) Assert::same("en", (string) $td);
    }
    foreach($r->children() as $i1 => $div) {
      if($i1 === 1) {
        Assert::same("Loaded resources", (string) $div->h1);
        foreach($div->table->th as $i2 => $td) {
          if($i2 === 0) Assert::same("Domain", (string) $td);
          elseif($i2 === 1) Assert::same("Filename", (string) $td);
        }
      } elseif($i1 === 2) {
        Assert::count(0, $div->children());
      }
    }
  }
  
  function testGetPanelResources() {
    /** @var Translator $translator */
    $translator = $this->getService(Translator::class);
    $translator->translate("xyz");
    $result = $this->panel->getPanel();
    Assert::type("string", $result);
    $r = new \SimpleXMLElement("<root>$result</root>");
    Assert::same("Untranslated message: 0, loaded resources 2", (string) $r->p);
  }
  
  function testGetPanelWithMessages() {
    /** @var Translator $translator */
    $translator = $this->getService(Translator::class);
    $translator->translate("abcd");
    $result = $this->panel->getPanel();
    Assert::type("string", $result);
    $r = new \SimpleXMLElement("<root>$result</root>");
    Assert::same("Untranslated message: 1, loaded resources 2", (string) $r->p);
  }
}

$test = new PanelTest;
$test->run();
?>
{'fraction_non_alphanumeric': 0.21566205533596838, 'fraction_numerical': 0.009881422924901186, 'mean_word_length': 3.4938956714761376, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 69, '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': '5623841', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1340, 'n_words': 264}