View source
<?php
namespace Drupal\Tests\tmgmt\Kernel;
use Drupal\tmgmt\Entity\Job;
class HelperTest extends TMGMTKernelTestBase {
function testTMGTJobMatchItem() {
$this
->addLanguage('fr');
$this
->addLanguage('es');
$job_en_fr = $this
->createJob('en', 'fr');
$job_en_sp = $this
->createJob('en', 'es');
$this
->assertEqual($job_en_fr
->id(), tmgmt_job_match_item('en', 'fr')
->id());
$this
->assertEqual($job_en_sp
->id(), tmgmt_job_match_item('en', 'es')
->id());
$this
->assertTrue(tmgmt_job_match_item('fr', 'es') instanceof Job);
}
function testDataIemLabel() {
$no_label = array(
'#text' => 'No label',
);
$this
->assertEqual(\Drupal::service('tmgmt.data')
->itemLabel($no_label), 'No label');
$this
->assertEqual(\Drupal::service('tmgmt.data')
->itemLabel($no_label, 6), 'No la…');
$label = array(
'#parent_label' => array(),
'#label' => 'A label',
);
$this
->assertEqual(\Drupal::service('tmgmt.data')
->itemLabel($label), 'A label');
$this
->assertEqual(\Drupal::service('tmgmt.data')
->itemLabel($label, 6), 'A lab…');
$parent_label = array(
'#parent_label' => array(
'Parent label',
'Sub label',
),
'#label' => 'A label',
);
$this
->assertEqual(\Drupal::service('tmgmt.data')
->itemLabel($parent_label), 'Parent label > Sub label');
$this
->assertEqual(\Drupal::service('tmgmt.data')
->itemLabel($parent_label, 18), 'Parent… > Sub la…');
$nested = array(
'#parent_label' => array(
'Parent label',
'Sub label',
'Sub-sub label',
),
'#label' => 'A label',
);
$this
->assertEqual(\Drupal::service('tmgmt.data')
->itemLabel($nested), 'Parent label > Sub label > Sub-sub label');
$this
->assertEqual(\Drupal::service('tmgmt.data')
->itemLabel($nested, 28), 'Parent… > Sub la… > Sub-su…');
$long_label = array(
'#parent_label' => array(
'Loooooooooooong label',
'Short',
),
'#label' => 'A label',
);
$this
->assertEqual(\Drupal::service('tmgmt.data')
->itemLabel($long_label), 'Loooooooooooong label > Short');
$this
->assertEqual(\Drupal::service('tmgmt.data')
->itemLabel($long_label, 30), 'Loooooooooooong label > Short');
$node_example = array(
'#parent_label' => array(
'This is a very loooong title, so looong',
'Body',
'Delta #0',
'Body',
),
'#label' => 'A label',
);
$this
->assertEqual(\Drupal::service('tmgmt.data')
->itemLabel($node_example), 'This is a very loooong title, so looong > Body > Delta #0 > Body');
$this
->assertEqual(\Drupal::service('tmgmt.data')
->itemLabel($node_example, 56), 'This is a very loooong title, … > Body > Delta #0 > Body');
}
function testWordCount() {
$unit_tests = array(
'empty' => array(
'text' => '',
'count' => 0,
),
'latin' => array(
'text' => 'Drupal is the best!',
'count' => 4,
),
'non-latin' => array(
'text' => 'Друпал лучший!',
'count' => 2,
),
'complex punctuation' => array(
'text' => '<[({-!ReAd@*;: ,?+MoRe...})]>\\|/',
'count' => 2,
'exclude_tags' => FALSE,
),
'repeat' => array(
'text' => 'repeat repeat',
'count' => 2,
),
'strip tags' => array(
'text' => '<a href="http://example.com">link text</a> plain text <div class="some-css-class"></div>',
'count' => 4,
),
);
$config = $this
->config('tmgmt.settings');
foreach ($unit_tests as $id => $test_data) {
$test_data += array(
'exclude_tags' => TRUE,
);
if ($config
->get('word_count_exclude_tags') != $test_data['exclude_tags']) {
$config
->set('word_count_exclude_tags', $test_data['exclude_tags'])
->save();
}
$this
->assertEqual($real_count = \Drupal::service('tmgmt.data')
->wordCount($test_data['text']), $desirable_count = $test_data['count'], t('@test_id: Real count (=@real_count) should be equal to desirable (=@desirable_count)', array(
'@test_id' => $id,
'@real_count' => $real_count,
'@desirable_count' => $desirable_count,
)));
}
}
}