Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
1 contributor

Users who have contributed to this file

333 lines (285 sloc) 9.14 KB
<?php
/**
* COmanage Match Matchgrids Table Test
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*
*/
namespace App\Test\TestCase\Model\Table;
use App\Lib\Enum\ConfidenceModeEnum;
use App\Lib\Enum\ReferenceIdEnum;
use App\Lib\Enum\StatusEnum;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\TableRegistry;
/**
* MatchgridsTable tests.
*/
class MatchgridsTableTest extends AbstractTableTestCase {
public $fixtures = ['app.Matchgrids', 'app.AttributeGroups', 'app.Attributes'];
/**
* {@inheritdoc}
*/
public function getTable() {
return TableRegistry::getTableLocator()->get('Matchgrids');
}
/**
* Test table initialization.
*
* @return void
*/
public function testInitialize() {
$table = $this->getTable();
$this->assertInstanceOf('App\Model\Table\MatchgridsTable', $table);
$this->assertTrue($table->hasBehavior('Timestamp'));
$this->assertHasMany('App\Model\Table\ApiUsersTable', 'ApiUsers');
$this->assertTrue($table->getAssociation('ApiUsers')->getDependent());
$this->assertHasMany('App\Model\Table\AttributesTable', 'Attributes');
$this->assertTrue($table->getAssociation('Attributes')->getDependent());
$this->assertTrue($table->getAssociation('Attributes')->getCascadeCallbacks());
$this->assertHasMany('App\Model\Table\AttributeGroupsTable', 'AttributeGroups');
$this->assertTrue($table->getAssociation('AttributeGroups')->getDependent());
$this->assertHasMany('App\Model\Table\PermissionsTable', 'Permissions');
$this->assertTrue($table->getAssociation('Permissions')->getDependent());
$this->assertHasMany('App\Model\Table\RulesTable', 'Rules');
$this->assertTrue($table->getAssociation('Rules')->getDependent());
$this->assertTrue($table->getAssociation('Rules')->getCascadeCallbacks());
$this->assertHasMany('App\Model\Table\SystemsOfRecordTable', 'SystemsOfRecord');
$this->assertTrue($table->getAssociation('SystemsOfRecord')->getDependent());
$this->assertHasMany('App\Model\Table\RulesTable', 'CanonicalRules');
$this->assertEquals(['confidence_mode' => ConfidenceModeEnum::Canonical], $table->getAssociation('CanonicalRules')->getConditions());
$this->assertHasMany('App\Model\Table\RulesTable', 'PotentialRules');
$this->assertEquals(['confidence_mode' => ConfidenceModeEnum::Potential], $table->getAssociation('PotentialRules')->getConditions());
$this->assertEquals('table_name', $table->getDisplayField());
$expectedAutoViewVars = [
'referenceidMethods' => [
'type' => 'enum',
'class' => 'ReferenceIdEnum'
],
'statuses' => [
'type' => 'enum',
'class' => 'StatusEnum'
]
];
$this->assertEquals($expectedAutoViewVars, $table->getAutoViewVars());
}
/**
* Test matchgrid building.
*
* @return void
*/
public function testBuild() {
// Create test matchgrid table
$this->createTestMatchgrid();
// Build
$this->getTable()->build(1);
// Connect to test database
$db = ConnectionManager::get('test');
// Get schema of test matchgrid table
$schema = $db->getSchemaCollection()->describe('mg_testmatchgrid');
// Test columns
$expected = ['id', 'sor', 'sorid', 'referenceid', 'request_time', 'resolution_time'];
$this->assertEquals($expected, $schema->columns());
$result = $schema->getColumn('id');
$expected = [
'type' => 'integer',
'length' => 10,
'autoIncrement' => true,
'default' => NULL,
'null' => false,
'comment' => NULL,
'precision' => NULL,
'unsigned' => NULL,
];
$this->assertEquals($expected, $result);
$result = $schema->getColumn('sor');
$expected = [
'type' => 'string',
'length' => 64,
'default' => NULL,
'null' => true,
'collate' => NULL,
'comment' => NULL,
'precision' => NULL,
'fixed' => NULL,
];
$this->assertEquals($expected, $result);
$result = $schema->getColumn('sorid');
$this->assertEquals($expected, $result);
$result = $schema->getColumn('referenceid');
$this->assertEquals($expected, $result);
$result = $schema->getColumn('request_time');
// Log::debug('$result '.var_export($result, true));
$expected = [
'type' => 'timestamp',
'length' => NULL,
'default' => NULL,
'null' => true,
'comment' => NULL,
'precision' => NULL,
];
$this->assertEquals($expected, $result);
$result = $schema->getColumn('resolution_time');
$this->assertEquals($expected, $result);
// Test constraints
$expected = ['primary', 'matchgrid_i3'];
$this->assertEquals($expected, $schema->constraints());
$constraint = $schema->getConstraint('primary');
$expected = [
'type' => 'primary',
'columns' => [
'id',
],
'length' => [],
];
$this->assertEquals($expected, $constraint);
$constraint = $schema->getConstraint('matchgrid_i3');
$expected = [
'type' => 'unique',
'columns' => [
'sor',
'sorid'
],
'length' => [],
];
$this->assertEquals($expected, $constraint);
// Test indexes
$expected = ['matchgrid_i1', 'matchgrid_i2', 'matchgrid_i4', 'matchgrid_i5'];
$this->assertEquals($expected, $schema->indexes());
$index = $schema->getIndex('matchgrid_i1');
$expected = [
'type' => 'index',
'columns' => [
'sor'
],
'length' => [],
];
$this->assertEquals($expected, $index);
$index = $schema->getIndex('matchgrid_i2');
$expected = [
'type' => 'index',
'columns' => [
'sorid'
],
'length' => [],
];
$this->assertEquals($expected, $index);
$index = $schema->getIndex('matchgrid_i4');
$expected = [
'type' => 'index',
'columns' => [
'referenceid'
],
'length' => [],
];
$this->assertEquals($expected, $index);
$index = $schema->getIndex('matchgrid_i5');
$expected = [
'type' => 'index',
'columns' => [
'resolution_time'
],
'length' => [],
];
$this->assertEquals($expected, $index);
// Cleanup.
$db->execute('DROP TABLE mg_testmatchgrid');
}
/**
* Test calculation of matchgrid id.
*
* @return void
*/
public function testCalculateMatchgridId() {
$this->createTestMatchgrid();
$id = $this->getTable()->calculateMatchgridId(1);
$this->assertEquals(1, $id);
}
// TODO public function findActiveMatchgrids() {}
public function tearDown() {
parent::tearDown();
// TODO drop mg_testmatchgrid table ?
}
/**
* Test table_name field validation.
*
* @return void
*/
public function testValidationTableName() {
$this->assertFieldMaxLength('table_name', 128);
$this->assertFieldRegex('table_name', '/[a-zA-Z0-9_$]/');
$this->assertFieldNotEmpty('table_name');
}
/**
* Test description field validation.
*
* @return void
*/
public function testValidationDescription() {
$this->assertFieldMaxLength('description', 128);
$this->assertFieldAllowEmpty('description');
}
/**
* Test status field validation.
*
* @return void
*/
public function testValidationStatus() {
$list = [
StatusEnum::Active,
StatusEnum::Suspended
];
$this->assertFieldInList('status', $list);
$this->assertFieldNotEmpty('status');
}
/**
* Test referenceid_method field validation.
*
* @return void
*/
public function testValidationReferenceidMethod() {
$list = [
ReferenceIdEnum::Sequence,
ReferenceIdEnum::UUID
];
$this->assertFieldInList('referenceid_method', $list);
$this->assertFieldNotEmpty('referenceid_method');
}
/**
* Test referenceid_start field validation.
*
* @return void
*/
public function testValidationReferenceidStart() {
$this->assertFieldRangeUnbounded('referenceid_start', 1);
$this->assertFieldAllowEmpty('referenceid_start');
}
/**
* Test referenceid_prefix field validation.
*
* @return void
*/
public function testValidationReferenceidPrefix() {
$this->assertFieldMaxLength('referenceid_prefix', 32);
$this->assertFieldAllowEmpty('referenceid_prefix');
}
}