/* * Test the defs.techdep_clear() 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( 4 , 'tech' ); -- Insert the technologies INSERT INTO defs.technologies ( technology_name_id ) VALUES ( _get_string( 'tech1' ) ) , ( _get_string( 'tech2' ) ) , ( _get_string( 'tech3' ) ) , ( _get_string( 'tech4' ) ); -- Add a chain of dependencies INSERT INTO defs.technology_dependencies( technology_name_id , technology_name_id_depends ) VALUES ( _get_string( 'tech2' ) , _get_string( 'tech1' ) ) , ( _get_string( 'tech3' ) , _get_string( 'tech2' ) ) , ( _get_string( 'tech4' ) , _get_string( 'tech3' ) ); -- ***** TESTS BEGIN HERE ***** SELECT plan( 4 ); SELECT diag_test_name( 'defs.techdep_clear() - No failure on invalid technology name' ); SELECT lives_ok( $$ SELECT defs.techdep_clear( 'does not exist' ) $$ ); SELECT diag_test_name( 'defs.techdep_clear() - Successful call' ); SELECT lives_ok( $$ SELECT defs.techdep_clear( 'tech2' ) $$ ); SELECT diag_test_name( 'defs.techdep_clear() - Cleared technology has no dependencies' ); SELECT is_empty( $$ SELECT * FROM defs.technology_dependencies WHERE technology_name_id = _get_string( 'tech2' ); $$ ); SELECT diag_test_name( 'defs.techdep_clear() - Cleared technology has no reverse dependencies' ); SELECT is_empty( $$ SELECT * FROM defs.technology_dependencies WHERE technology_name_id_depends = _get_string( 'tech2' ); $$ ); SELECT * FROM finish( ); ROLLBACK;