Skip to content

Commit

Permalink
Adding unit tests for the createList path function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoramite committed Oct 28, 2011
1 parent f81ee46 commit 539d68e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 16 deletions.
32 changes: 16 additions & 16 deletions content/inc/resource/utility/path.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ component {
return arguments.value;
}

public string function createList( required string path, any keys = [] ) {
public string function createList( required string path, any keys = [''] ) {
var pathList = '';
var pathPart = '';
var i = '';
Expand All @@ -51,22 +51,22 @@ component {
arguments.keys = [ arguments.keys ];
}

// If provided a key then prepend a slash so it can be added to the end of the pathPart
if(arrayLen(arguments.keys)) {
for( j = 1; j <= arrayLen(arguments.keys); j++ ) {
if(arguments.keys[j] != '') {
arguments.keys[j] = '/' & arguments.keys[j];

// Add to the base path list
pathList = listAppend(pathList, arguments.keys[j]);
} else {
// Handle the root path possibility
pathList = listAppend(pathList, '/');
}
// Default to a blank key if it doesn't have a key already
if(!arrayLen(arguments.keys)) {
arguments.keys = [''];
}

// Prepend a slash so it can be added to the end of the pathPart
for( j = 1; j <= arrayLen(arguments.keys); j++ ) {
if(arguments.keys[j] != '') {
arguments.keys[j] = '/' & arguments.keys[j];

// Add to the base path list
pathList = listAppend(pathList, arguments.keys[j]);
} else {
// Handle the root path possibility
pathList = listAppend(pathList, '/');
}
} else {
// Handle the root path possibility
pathList = listAppend(pathList, '/');
}

// Make the list from each part of the provided path
Expand Down
53 changes: 53 additions & 0 deletions test/inc/resource/utility/path_createList_shouldTest.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
component extends="mxunit.framework.TestCase" {
public void function setup() {
variables.path = createObject('component', 'plugins.content.inc.resource.utility.path').init();
}

public void function testReturnWithEmptyKeys_WithRootPath() {
assertEquals('/', variables.path.createList('/', []));
}

public void function testReturnWithEmptyKeys_WithMultiLevelPath() {
assertEquals('/,/one,/one/two', variables.path.createList('/one/two', []));
}

public void function testReturnWithEmptyKeys_WithSingleLevelPath() {
assertEquals('/,/one', variables.path.createList('/one', []));
}

public void function testReturnWithMultipleKeys_WithRootPath() {
assertEquals('/~,/^', variables.path.createList('/', ['~', '^']));
}

public void function testReturnWithMultipleKeys_WithMultiLevelPath() {
assertEquals('/~,/^,/one/~,/one/^,/one/two/~,/one/two/^', variables.path.createList('/one/two', ['~', '^']));
}

public void function testReturnWithMultipleKeys_WithSingleLevelPath() {
assertEquals('/~,/^,/one/~,/one/^', variables.path.createList('/one', ['~', '^']));
}

public void function testReturnWithoutKeys_WithRootPath() {
assertEquals('/', variables.path.createList('/'));
}

public void function testReturnWithoutKeys_WithMultiLevelPath() {
assertEquals('/,/one,/one/two', variables.path.createList('/one/two'));
}

public void function testReturnWithoutKeys_WithSingleLevelPath() {
assertEquals('/,/one', variables.path.createList('/one'));
}

public void function testReturnWithSingleKey_WithRootPath() {
assertEquals('/~', variables.path.createList('/', ['~']));
}

public void function testReturnWithSimpleKey_WithMultiLevelPath() {
assertEquals('/~,/one/~,/one/two/~', variables.path.createList('/one/two', ['~']));
}

public void function testReturnWithSimpleKey_WithSingleLevelPath() {
assertEquals('/~,/one/~', variables.path.createList('/one', ['~']));
}
}

0 comments on commit 539d68e

Please sign in to comment.