Permalink
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?
match/app/tests/TestCase/Model/Table/ApiUsersTableTest.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
161 lines (140 sloc)
4.98 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* COmanage Match API Users 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\Model\Entity\ApiUser; | |
use Cake\ORM\TableRegistry; | |
/** | |
* ApiUsersTable tests. | |
*/ | |
class ApiUsersTableTest extends AbstractTableTestCase { | |
public $fixtures = ['app.Matchgrids', 'app.SystemsOfRecord', 'app.ApiUsers']; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getTable() { | |
return TableRegistry::getTableLocator()->get('ApiUsers'); | |
} | |
/** | |
* Test table initialization. | |
* | |
* @return void | |
*/ | |
public function testInitialize() { | |
$table = $this->getTable(); | |
$this->assertInstanceOf('App\Model\Table\ApiUsersTable', $table); | |
$this->assertTrue($table->hasBehavior('Timestamp')); | |
$this->assertBelongsTo('App\Model\Table\MatchgridsTable', 'Matchgrids'); | |
$this->assertBelongsTo('App\Model\Table\SystemsOfRecordTable', 'SystemsOfRecord'); | |
$this->assertEquals('system_of_record_id', $table->getAssociation('SystemsOfRecord')->getForeignKey()); | |
$this->assertEquals('system_of_record', $table->getAssociation('SystemsOfRecord')->getProperty()); | |
$this->assertEquals('username', $table->getDisplayField()); | |
$this->assertEquals('matchgrid_id', $table->getPrimaryLink()); | |
$this->assertTrue($table->requiresMatchgrid()); | |
$this->assertTrue($table->allowEmptyMatchgrid()); | |
$this->assertTrue($table->allowEmptyPrimaryLink()); | |
$expected = ['systemsOfRecord' => [ | |
'type' => 'select', | |
'model' => 'SystemsOfRecord', | |
'find' => 'filterPrimaryLink' | |
]]; | |
$this->assertEquals($expected, $table->getAutoViewVars()); | |
} | |
/** | |
* Test username field validation. | |
* | |
* @return void | |
*/ | |
public function testValidationUsername() { | |
$this->assertFieldMaxLength('username', 128); | |
$this->assertFieldNotEmpty('username'); | |
} | |
/** | |
* Test password field validation. | |
* | |
* @return void | |
*/ | |
public function testValidationPassword() { | |
$this->assertFieldMaxLength('password', 80); | |
$this->assertFieldNotEmpty('password'); | |
} | |
/** | |
* Test matchgrid_id field validation. | |
* | |
* @return void | |
*/ | |
public function testValidationMatchgridId() { | |
$this->assertFieldInteger('matchgrid_id'); | |
$this->assertFieldAllowEmpty('matchgrid_id'); | |
} | |
/** | |
* Test system_of_record_id field validation. | |
* | |
* @return void | |
*/ | |
public function testValidationSystemOfRecordId() { | |
$this->assertFieldInteger('system_of_record_id'); | |
$this->assertFieldAllowEmpty('system_of_record_id'); | |
} | |
/** | |
* Test username rules validation for Matchgrid API users. | |
* | |
* @return void | |
*/ | |
public function testRulesCheckUsernameMatchgridAPI() { | |
$this->createTestMatchgrid(); | |
// Should not be able to create a Matchgrid API user whose name is not of the 'matchgrid name'.'username' format | |
$entityNoDots = new ApiUser([ | |
'username' => 'MatchgridApiUserNoDot', | |
'matchgrid_id' => '1', | |
]); | |
$this->assertFalse($this->getTable()->save($entityNoDots)); | |
// Should be able to create a Matchgrid API user whose name is of the 'matchgrid name'.'username' format | |
$entityWithDots = new ApiUser([ | |
'username' => 'testmatchgrid.withDot', | |
'matchgrid_id' => '1', | |
]); | |
$this->assertInstanceOf('App\Model\Entity\ApiUser', $this->getTable()->save($entityWithDots)); | |
} | |
/** | |
* Test username rules validation for Platform API users. | |
* | |
* @return void | |
*/ | |
public function testRulesCheckUsernamePlatformAPI() { | |
// Should be able to create a Platform API user whose name does not contain a dot. | |
$entityNoDots = new ApiUser([ | |
'username' => 'platformApiUserNoDot' | |
]); | |
$this->assertInstanceOf('App\Model\Entity\ApiUser', $this->getTable()->save($entityNoDots)); | |
// Should not be able to create a Platform API user whose name contains a dot. | |
$entityWithDots = new ApiUser([ | |
'username' => 'platformApiUser.withDot' | |
]); | |
$this->assertFalse($this->getTable()->save($entityWithDots)); | |
} | |
// TODO findAuthorization ? | |
} |