/
TranscriptionsShellTest.php
105 lines (83 loc) · 3 KB
/
TranscriptionsShellTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace App\Test\TestCase\Shell;
use App\Lib\Autotranscription;
use App\Shell\TranscriptionsShell;
use Cake\Core\Configure;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\ConsoleIntegrationTestCase;
class TranscriptionsShellTest extends ConsoleIntegrationTestCase
{
public $fixtures = [
'app.sentences',
'app.transcriptions',
'app.users',
];
public $io;
public $TS;
private function getAutotranscriptionMock() {
$AT = $this->getMockBuilder(Autotranscription::class)
->setMethods([
'jpn_Jpan_to_Hrkt_generate',
'jpn_Jpan_to_Hrkt_validate',
'cmn_detectScript',
])
->getMock();
$AT->expects($this->any())
->method('jpn_Jpan_to_Hrkt_generate')
->will($this->returnValue('transcription in furigana'));
$AT->expects($this->any())
->method('jpn_Jpan_to_Hrkt_validate')
->will($this->returnValue(true));
$AT->expects($this->any())
->method('cmn_detectScript')
->will($this->returnValue('TEST'));
return $AT;
}
public function setUp()
{
parent::setUp();
$this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
$this->TS = new TranscriptionsShell($this->io);
$this->TS->initialize();
$AT = $this->getAutotranscriptionMock();
$this->TS->Transcriptions->setAutotranscription($AT);
Configure::write('Acl.database', 'test');
}
public function tearDown()
{
unset($this->TS);
parent::tearDown();
}
public function testAutogen_forAllSentences()
{
$transcrBefore = $this->TS->Transcriptions->find()->where(['lang' => 'jpn'])->count();
$this->TS->autogen('jpn');
$transcrAfter = $this->TS->Transcriptions->find()->where(['lang' => 'jpn'])->count();
$jpnSentences = TableRegistry::get('Sentences')->find()->where(['lang' => 'jpn'])->count();
$this->assertGreaterThan($transcrBefore, $transcrAfter);
$this->assertEquals($transcrAfter, $jpnSentences);
}
public function testAutogen_regenExisting()
{
$before = $this->TS->Transcriptions->find()->where(['sentence_id' => 10])->first();
$this->TS->autogen('jpn');
$after = $this->TS->Transcriptions->find()->where(['sentence_id' => 10])->first();
$this->assertNotEquals($before->text, $after->text);
}
public function testAutogen_batched()
{
$this->TS->batchOperationSize = 2;
$this->testAutogen_forAllSentences();
}
public function testSetSentencesScript()
{
$expectedScripts = ['TEST'];
$this->TS->setSentencesScript('cmn');
$scripts = TableRegistry::get('Sentences')
->find('list', ['valueField' => 'script'])
->where(['lang' => 'cmn'])
->toArray();
$scripts = array_keys(array_flip($scripts));
$this->assertEquals($expectedScripts, $scripts);
}
}