This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/legacyworlds-server-data/db-structure/tests/admin/040-functions/030-tech/050-techdep-remove.sql
Emmanuel BENOîT af57e7d3b5 Technology definition functions
* Added stored procedures which manipulate technology definitions
themselves (defs.uoc_technology) or their dependencies (defs.techdep_add
and defs.techdep_remove)
2012-02-27 14:14:00 +01:00

51 lines
No EOL
1.8 KiB
PL/PgSQL

/*
* Test the defs.techdep_remove() function
*/
BEGIN;
\i utils/strings.sql
-- Make the columns we don't use in the technology definition table NULL-able
ALTER TABLE defs.technologies
ALTER technology_category_id DROP NOT NULL ,
ALTER technology_discovery_id DROP NOT NULL ,
ALTER technology_description_id DROP NOT NULL ,
ALTER technology_price DROP NOT NULL ,
ALTER technology_points DROP NOT NULL;
-- Create strings to use as the technologies' names
SELECT _create_test_strings( 2 , 'tech' );
-- Insert the technologies
INSERT INTO defs.technologies ( technology_name_id )
VALUES ( _get_string( 'tech1' ) ) ,
( _get_string( 'tech2' ) );
-- Add a dependency from tech2 to tech1
INSERT INTO defs.technology_dependencies(
technology_name_id , technology_name_id_depends
) VALUES ( _get_string( 'tech2' ) , _get_string( 'tech1' ) );
-- ***** TESTS BEGIN HERE *****
SELECT plan( 5 );
SELECT diag_test_name( 'defs.techdep_remove() - Bad dependent technology name' );
SELECT is( defs.techdep_remove( 'does not exist' , 'tech1' )::TEXT , 'MISSING' );
SELECT diag_test_name( 'defs.techdep_remove() - Bad dependency name' );
SELECT is( defs.techdep_remove( 'tech2' , 'does not exist' )::TEXT , 'MISSING' );
SELECT diag_test_name( 'defs.techdep_remove() - Correct name but no dependency' );
SELECT is( defs.techdep_remove( 'tech1' , 'tech2' )::TEXT , 'MISSING' );
SELECT diag_test_name( 'defs.techdep_remove() - Success - Return value' );
SELECT is( defs.techdep_remove( 'tech2' , 'tech1' )::TEXT , 'DELETED' );
SELECT diag_test_name( 'defs.techdep_remove() - Success - Table contents' );
SELECT is_empty($$
SELECT * FROM defs.technology_dependencies
WHERE technology_name_id = _get_string( 'tech2' )
AND technology_name_id_depends = _get_string( 'tech1' );
$$);
SELECT * FROM finish( );
ROLLBACK;