initial commit

This commit is contained in:
2016-04-15 21:38:56 -04:00
commit 1d3e8e3117
79 changed files with 16223 additions and 0 deletions

View File

@@ -0,0 +1,364 @@
<?php
use App\Libraries\abcParse\Setting;
use App\Libraries\abcParse\Person;
use \Codeception\TestCase\Test as TestCase;
/**
* @group Lib
*/
class SettingTest extends TestCase
{
private $_setting;
public function setUp()
{
$this->_setting = new Setting();
}
/**
* test the model contains the correct attributes
*/
public function test_model_definition()
{
$this->assertClassHasAttribute('settingID', Setting::class);
$this->assertClassHasAttribute('tuneID', Setting::class);
$this->assertClassHasAttribute('Z', Setting::class);
$this->assertClassHasAttribute('N', Setting::class);
$this->assertClassHasAttribute('D', Setting::class);
$this->assertClassHasAttribute('S', Setting::class);
$this->assertClassHasAttribute('W', Setting::class);
$this->assertClassHasAttribute('B', Setting::class);
$this->assertClassHasAttribute('F', Setting::class);
$this->assertClassHasAttribute('P', Setting::class);
$this->assertClassHasAttribute('Q', Setting::class);
$this->assertClassHasAttribute('L', Setting::class);
$this->assertClassHasAttribute('M', Setting::class);
$this->assertClassHasAttribute('K', Setting::class);
$this->assertClassHasAttribute('music', Setting::class);
// $this->assertClassHasAttribute('music_hash', Setting::class);
$this->assertClassHasAttribute('propertyNames', Setting::class);
}
/**
* test the set property method
*
* also tests the validate_line protected method
*
* @param (string) $property, the name of the property to set
* @param (mixed) value to set
* @param (Boolean) expected value for return value of set method
*
* @dataProvider provider_set
*/
public function test_set($property, $value, $expected_success, $expected_value = FALSE)
{
$success = $this->_setting->set($property, $value);
$this->assertEquals($expected_success, $success);
if($success)
{
if(! $expected_value ) { $expected_value = $value; }
$this->assertEquals($expected_value, $this->_setting->get($property));
}
}
/**
* @dataProvider provider_set
*/
public function test_magic_set($property, $value, $expected_success, $expected_value = FALSE)
{
$this->_setting->$property = $value;
if($expected_success)
{
$this->assertEquals($value, $this->_setting->get($property));
}
}
public function provider_set()
{
return array(
array('Y', 'anything', FALSE),
array('settingID', 1, TRUE),
array('tuneID', array('alpha'), FALSE),
array('tuneID', 'alpha', FALSE),
array('tuneID', '1', TRUE),
array('tuneID', 1, TRUE),
array('f', 1, FALSE),
array('F', 1, FALSE),
array('F', '1',FALSE),
array('F', array('aplha'), TRUE),
array('P', array('string'), FALSE),
array('P', 10, FALSE),
array('P', 'string', TRUE),
array('Q', array('string'), FALSE),
array('Q', 10, FALSE),
array('Q', 'string', FALSE),
array('Q', '1/8=200', TRUE),
array('L', array('string'), FALSE),
array('L', 10, FALSE),
array('L', 'string', FALSE),
array('L', '1/8', TRUE),
array('M', array('string'), FALSE),
array('M', 10, FALSE),
array('M', 'string', FALSE),
array('M', '6/8', TRUE),
array('M', 'C', TRUE),
array('M', 'c', TRUE),
array('M', 'C|', TRUE),
array('K', array('string'), FALSE),
array('K', 10, FALSE),
array('K', 'C', TRUE),
array('K', 'Am', TRUE),
array('K', 'A minor', TRUE),
array('K', 'E dorian', TRUE),
array('music', 'GABc:|\\', TRUE),
array('Z', new Person(), FALSE),
array('Z', array(new Person(), 'not a person'), FALSE),
array('Z', array(new Person()), TRUE),
array('Z', 111, FALSE),
array('N', array('a string'), TRUE),
array('D', array('a string'), TRUE),
array('S', array('a string'), TRUE),
array('W', array('a string'), TRUE),
array('B', array('a string'), TRUE),
);
}
/**
* the settingID can only be set if it's value is currently 0
* this ensures that we can't change a setting's id once it's set.
* the default, unset value for settingID is 0
*/
public function test_set_settingID()
{
$success = $this->_setting->set('settingID', 1);
$this->assertTrue($success, 'first attempt should succeed');
$success = $this->_setting->set('settingID', 2);
$this->assertFalse($success, 'second attempt should fail');
}
/**
* test the append value method
*
* @param (string) $property, the name of the property to set
* @param (mixed) value to append
* @param (Boolean) expected value for return value of append method
*
* @dataProvider provider_append
*/
public function test_append($property, $value, $expected)
{
$success = $this->_setting->append($property, $value);
$this->assertEquals($expected, $success);
if($success)
{
$this->assertContains($value, $this->_setting->get($property));
}
}
public function provider_append()
{
return array(
array('Y', 'anything', FALSE),
array('settingID', 1, FALSE),
array('tuneID', array('alpha'), FALSE),
array('tuneID', 'alpha', FALSE),
array('tuneID', '1', FALSE),
array('tuneID', 1, FALSE),
array('f', 1, FALSE),
array('F', 1, TRUE),
array('F', '1', TRUE),
array('F', array('aplha'), FALSE),
array('P', array('string'), FALSE),
array('P', 10, FALSE),
array('P', 'string', FALSE),
array('Q', array('string'), FALSE),
array('Q', 10, FALSE),
array('Q', 'string', FALSE),
array('Q', '1/8=200', FALSE),
array('L', array('string'), FALSE),
array('L', 10, FALSE),
array('L', 'string', FALSE),
array('L', '1/8', FALSE),
array('M', array('string'), FALSE),
array('M', 10, FALSE),
array('M', 'string', FALSE),
array('M', '6/8', FALSE),
array('M', 'C', FALSE),
array('M', 'c', FALSE),
array('M', 'C|', FALSE),
array('K', array('string'), FALSE),
array('K', 10, FALSE),
array('K', 'C', FALSE),
array('K', 'Am', FALSE),
array('K', 'A minor', FALSE),
array('K', 'E dorian', FALSE),
array('music', 'GABc:|\\', FALSE),
array('Z', new Person(), TRUE),
array('Z', array(new Person()), FALSE),
array('Z', 111, FALSE),
array('N', array('a string'), FALSE),
array('D', array('a string'), FALSE),
array('S', array('a string'), FALSE),
array('W', array('a string'), FALSE),
array('B', array('a string'), FALSE),
array('N', 'more notes', TRUE),
array('D', 'another record', TRUE),
array('S', 'another source', TRUE),
array('W', 'words', TRUE),
array('B', 'another book', TRUE),
);
}
/**
* @dataProvider provider_get
*/
public function test_get($key, $expected)
{
$result = $this->_setting->set($key, $expected);
$result = $this->_setting->get($key);
$this->assertEquals($expected, $result);
}
public function provider_get()
{
return array(
array('', FALSE),
array('me', FALSE),
array('settingID', 1),
array('tuneID', 2),
array('Q', '1/8=100'),
array('L', '1/8'),
array('M', '6/8'),
array('K', 'Am'),
array('music', 'GABc:|\\'),
array('Z', array(new Person())),
array('N', array('a string')),
array('D', array('a string')),
array('S', array('a string')),
array('W', array('a string')),
array('B', array('a string')),
);
}
/**
* test the static function equals
* returns true if the data properties of 2 Setting Objects
* are identical
*
* @param (array) $params list of properties to set on the objects
* @param (boolean) $expected result of running equals
*
* @dataProvider provider_equals
*/
public function test_equals($params)
{
// $this->markTestIncomplete();
$ob1 = new Setting();
$ob2 = new Setting();
foreach($params as $key => $val)
{
if(is_array($ob1->get($key)))
{
$ob1->append($key, $val);
$ob2->append($key, $val);
}
else {
$ob1->set($key, $val);
$ob2->set($key, $val);
}
}
$this->assertTrue(Setting::equals($ob1, $ob2));
}
/**
* test the static function equals
* returns true if the data properties of 2 Abc_Tunes
* are identical
*
* @param (array) $params list of properties to set on the objects
* @param (boolean) $expected result of running equals
*
* @dataProvider provider_equals
*/
public function test_equals_fails($params)
{
$ob1 = new Setting();
$ob2 = new Setting();
foreach($params as $key => $val)
{
if(is_array($ob1->get($key)))
{
$ob1->append($key, $val);
// $ob2->append($key, $val);
}
else {
$ob1->set($key, $val);
$ob2->set($key, $val+1);
}
}
$this->assertFalse(Setting::equals($ob1, $ob2));
}
public function provider_equals()
{
return array(
array( array('settingID'=>'2') ),
array( array('tuneID'=>'2') ),
array( array('Z'=> new Person()) ),
array( array('N'=>'an author') ),
array( array('D'=>'a composer') ),
array( array('S'=>'a group') ),
array( array('W'=>'some history') ),
array( array('B'=>'Plymouth') ),
array( array('F'=>'Jig') ),
array( array('P'=>'ABB') ),
array( array('Q'=>'1/8=100') ),
array( array('L'=>'1/4') ),
array( array('M'=>'2/4') ),
array( array('K'=>'G') ),
array( array('music'=>'a|cab|') ),
);
}
public function test_isChanged()
{
$setting = new Setting();
$this->assertInstanceOf(Setting::class, $setting);
$this->assertFalse($setting->is_changed(), 'after load should be no changes');
$setting->set('K','G');
$this->assertTrue($setting->is_changed(), 'updating the name changes the data');
}
public function test_construct()
{
$params = array(
'settingID' => 3,
'Z' => array(new Person()),
'P' => 'ABC'
);
$this->_setting = new Setting ($params);
foreach($params as $key => $val)
{
$this->assertEquals($val, $this->_setting->get($key));
}
}
}