159 lines
5.6 KiB
PHP
159 lines
5.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group Lib
|
|
* @group Unit
|
|
*/
|
|
|
|
use App\Libraries\abcParse\AbcParser;
|
|
|
|
class AbcParserTest extends \Codeception\TestCase\Test
|
|
{
|
|
private $_facade;
|
|
|
|
private $valid_abc_1 = "
|
|
//blank first line means this isn't a file header anymore!
|
|
A: trad
|
|
B: Traditional English tunes
|
|
C: trad.
|
|
X:3
|
|
M:4/4
|
|
K:C
|
|
gaab babc :|
|
|
";
|
|
|
|
private $valid_abc_2 = "
|
|
X:40
|
|
T:Abbotts Bromley Horn Dance
|
|
A: trad
|
|
C: trad.
|
|
D: None
|
|
G:lute
|
|
H: Thousand year old tradition
|
|
The Horns live in the church and are removed for the dance once a year
|
|
R:Jig
|
|
F:none.abc
|
|
B: Traditional English tunes
|
|
W:None
|
|
Q:1/8=80
|
|
L:1/8
|
|
M:6/8
|
|
N:Traditional English
|
|
O:England
|
|
Z:Andy Hornby
|
|
%%TUNEURL: http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html
|
|
%%ID:00000dab
|
|
S:http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html
|
|
P:ABC
|
|
K:G
|
|
e|B2e G2e|B2e E2G|FGA GAB|1AGF G2:|2AGF E2|
|
|
|e|c2e cde|A2c ABc|FGA GFE|_E=EF B,2g|
|
|
e2g efg|c2e cde|dcB AGF|E3E2
|
|
|:A|BcB e3|BcB f3|BcB AGF|1G2F G2:|2E3-E2|]
|
|
";
|
|
|
|
private $valid_abc_3 = "A: trad
|
|
B: Traditional English tunes
|
|
C: trad.
|
|
D: None
|
|
F:none.abc
|
|
H: Thousand year old tradition
|
|
The Horns live in the church and are removed for the dance once a year
|
|
L:1/8
|
|
M:6/8
|
|
N:Traditional English
|
|
O:England
|
|
R:Jig
|
|
S:http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html
|
|
Z:Andy Hornby
|
|
|
|
X:3
|
|
M:4/4
|
|
K:C
|
|
gaab babc :|
|
|
";
|
|
|
|
|
|
public function setUp()
|
|
{
|
|
parent::setup();
|
|
$this->_facade = new AbcParser();
|
|
}
|
|
|
|
public function test_not_header_data_no_crash()
|
|
{
|
|
$result = $this->_facade->parseABC($this->valid_abc_1);
|
|
$this->assertTrue(is_a($result, 'App\Libraries\abcParse\TuneCollection'));
|
|
}
|
|
|
|
|
|
public function test_all_parameters_for_tune()
|
|
{
|
|
$result = $this->_facade->parseABC($this->valid_abc_2);
|
|
$this->assertTrue(is_a($result, 'App\Libraries\abcParse\TuneCollection'));
|
|
|
|
// Tune details
|
|
$tune = $result[0];
|
|
// var_dump($tune); die();
|
|
$this->assertEquals('40', $result[0]->get('X'));
|
|
$this->assertEquals('Abbotts Bromley Horn Dance', array_shift($tune->get('T')) );
|
|
$this->assertEquals('England', array_shift($tune->get('O')) );
|
|
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'trad')), array_shift($tune->get('A')) );
|
|
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'trad.')), array_shift($tune->get('C')) );
|
|
$this->assertEquals('England', array_shift($tune->get('O')) );
|
|
$this->assertEquals('lute', array_shift($tune->get('G')) );
|
|
$history = $tune->get('H');
|
|
$this->assertEquals(2, count($history));
|
|
$this->assertEquals('Thousand year old tradition', $history[0] );
|
|
$this->assertEquals('The Horns live in the church and are removed for the dance once a year', $history[1] );
|
|
$this->assertEquals('Jig', array_shift($tune->get('R')) );
|
|
|
|
// setting details
|
|
$setting = $tune[0];
|
|
// var_dump($setting);die;
|
|
$this->assertEquals('Traditional English', array_shift($setting->get('N')) );
|
|
$this->assertEquals('1/8', $setting->get('L') );
|
|
$this->assertEquals('6/8', $setting->get('M') );
|
|
$this->assertEquals('G', $setting->get('K') );
|
|
$expectedMusic = "
|
|
e|B2e G2e|B2e E2G|FGA GAB|1AGF G2:|2AGF E2|
|
|
|e|c2e cde|A2c ABc|FGA GFE|_E=EF B,2g|
|
|
e2g efg|c2e cde|dcB AGF|E3E2
|
|
|:A|BcB e3|BcB f3|BcB AGF|1G2F G2:|2E3-E2|]
|
|
";
|
|
$this->assertEquals(trim($expectedMusic), $setting->get('music'), "music strings should match" );
|
|
|
|
$Z = new App\Libraries\abcParse\Person(array('name'=>'Andy Hornby'));
|
|
$this->assertEquals($Z, array_shift($setting->get('Z')) );
|
|
|
|
$this->assertEquals('None', array_shift($setting->get('D')) );
|
|
$this->assertEquals('http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html', array_shift($setting->get('S')) );
|
|
$this->assertEquals('None', array_shift($setting->get('W')) );
|
|
$this->assertEquals('Traditional English tunes', array_shift($setting->get('B')) );
|
|
$this->assertEquals('none.abc', array_shift($setting->get('F')) );
|
|
$this->assertEquals('ABC', $setting->get('P') );
|
|
$this->assertEquals('1/8=80', $setting->get('Q') );
|
|
}
|
|
|
|
|
|
public function test_all_parameters_for_collection()
|
|
{
|
|
$collection = $this->_facade->parseABC($this->valid_abc_3);
|
|
$this->assertTrue(is_a($collection, 'App\Libraries\abcParse\TuneCollection'));
|
|
|
|
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'trad')), array_shift($collection->get('A')) );
|
|
$this->assertEquals('Traditional English tunes', array_shift($collection->get('B')) );
|
|
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'trad.')), array_shift($collection->get('C')) );
|
|
$this->assertEquals('None', array_shift($collection->get('D')) );
|
|
$this->assertEquals('none.abc', array_shift($collection->get('F')) );
|
|
$this->assertEquals('Thousand year old tradition', array_shift($collection->get('H')) );
|
|
$this->assertEquals('1/8', $collection->get('L') );
|
|
$this->assertEquals('6/8', $collection->get('M') );
|
|
$this->assertEquals('Traditional English', array_shift($collection->get('N')) );
|
|
$this->assertEquals('England', array_shift($collection->get('O')) );
|
|
$this->assertEquals('Jig', $collection->get('R') );
|
|
$this->assertEquals('http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html', array_shift($collection->get('S')) );
|
|
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'Andy Hornby')), array_shift($collection->get('Z')) );
|
|
}
|
|
}
|