From 8ca9437a9c624a6dd12545bae0f84b090373d0b8 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sat, 29 Mar 2014 15:27:01 +0000 Subject: [PATCH] Remove obsolete JavaScript tests --- test/js/.jshintignore | 1 - test/js/.jshintrc | 6 - test/js/checkswag | 153 ---------------- test/js/regression/bug.4102.js | 39 ---- test/js/runtests | 149 --------------- test/js/test/icinga/componentTest.js | 168 ----------------- .../test/icinga/components/containerTest.js | 115 ------------ test/js/test/icinga/registryTest.js | 139 -------------- test/js/testlib/asyncmock.js | 61 ------- test/js/testlib/historymock.js | 92 ---------- test/js/testlib/requiremock.js | 172 ------------------ 11 files changed, 1095 deletions(-) delete mode 100644 test/js/.jshintignore delete mode 100644 test/js/.jshintrc delete mode 100755 test/js/checkswag delete mode 100644 test/js/regression/bug.4102.js delete mode 100755 test/js/runtests delete mode 100644 test/js/test/icinga/componentTest.js delete mode 100644 test/js/test/icinga/components/containerTest.js delete mode 100644 test/js/test/icinga/registryTest.js delete mode 100644 test/js/testlib/asyncmock.js delete mode 100644 test/js/testlib/historymock.js delete mode 100644 test/js/testlib/requiremock.js diff --git a/test/js/.jshintignore b/test/js/.jshintignore deleted file mode 100644 index c9b36835d..000000000 --- a/test/js/.jshintignore +++ /dev/null @@ -1 +0,0 @@ -../../library/vendor/** diff --git a/test/js/.jshintrc b/test/js/.jshintrc deleted file mode 100644 index 756e43b8a..000000000 --- a/test/js/.jshintrc +++ /dev/null @@ -1,6 +0,0 @@ -/* See http://www.jshint.com/docs/#usage on how to use this file */ - -{ - - -} diff --git a/test/js/checkswag b/test/js/checkswag deleted file mode 100755 index 375a25639..000000000 --- a/test/js/checkswag +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -import subprocess -from pipes import quote -from fnmatch import fnmatch -from optparse import OptionParser, BadOptionError, AmbiguousOptionError - - -APPLICATION = 'jshint' -DEFAULT_ARGS = [] - -VAGRANT_SCRIPT = '/vagrant/test/js/checkswag' -REPORT_DIRECTORY = '../../build/log' - - -class PassThroughOptionParser(OptionParser): - """ - An unknown option pass-through implementation of OptionParser. - - When unknown arguments are encountered, bundle with largs and try again, - until rargs is depleted. - - sys.exit(status) will still be called if a known argument is passed - incorrectly (e.g. missing arguments or bad argument types, etc.) - - Borrowed from: http://stackoverflow.com/a/9307174 - """ - def _process_args(self, largs, rargs, values): - while rargs: - try: - OptionParser._process_args(self, largs, rargs, values) - except (BadOptionError, AmbiguousOptionError), error: - largs.append(error.opt_str) - - -def execute_command(command, return_output=False, shell=False): - prog = subprocess.Popen(command, shell=shell, - stdout=subprocess.PIPE - if return_output - else None) - return prog.wait() if not return_output else \ - prog.communicate()[0] - - -def get_report_directory(): - path = os.path.abspath(REPORT_DIRECTORY) - - try: - os.makedirs(REPORT_DIRECTORY) - except OSError: - pass - - return path - - -def get_script_directory(): - return os.path.dirname(os.path.abspath(sys.argv[0])) - - -def parse_commandline(): - parser = PassThroughOptionParser(usage='%prog [options] [additional arguments' - ' for {0}]'.format(APPLICATION)) - parser.add_option('-b', '--build', action='store_true', - help='Enable reporting.') - parser.add_option('-v', '--verbose', action='store_true', - help='Be more verbose.') - parser.add_option('-i', '--include', metavar='PATTERN', action='append', - help='Include only specific files/test cases.' - ' (Can be supplied multiple times.)') - parser.add_option('-e', '--exclude', metavar='PATTERN', action='append', - help='Exclude specific files/test cases. ' - '(Can be supplied multiple times.)') - parser.add_option('-V', '--vagrant', action='store_true', - help='Run in vagrant VM') - return parser.parse_args() - - -def main(): - options, arguments = parse_commandline() - - if options.vagrant and os.environ['USER'] != 'vagrant': - # Check if vagrant is installed - vagrant_path = execute_command('which vagrant', True, True).strip() - if not vagrant_path: - print 'ERROR: vagrant not found!' - return 2 - - # Call the script in the Vagrant VM with the same parameters - commandline = ' '.join(quote(p) for p in sys.argv[1:]) - return execute_command('vagrant ssh -c "{0} {1}"' - ''.format(VAGRANT_SCRIPT, commandline), - shell=True) - else: - # Environment preparation and verification - os.chdir(get_script_directory()) - application_path = execute_command('which {0}'.format(APPLICATION), - True, True).strip() - if not application_path: - print 'ERROR: {0} not found!'.format(APPLICATION) - return 2 - - # Commandline preparation - command_options = [] - if options.build: - command_options.extend(['--reporter', 'jslint']) - else: - command_options.append('--verbose') - if options.verbose: - command_options.append('--show-non-errors') - path_args = [arguments.remove(a) or a - for a in arguments[:len(arguments)] - if os.path.isfile(a) or os.path.isdir(a)] - if not path_args: - path_args = ['../../public/js/icinga', '../../bin', - '../../modules/'] - if options.include: - path_args = [os.path.join(r, f) - for a in path_args - for r, _, fs in os.walk(a) - for f in fs - if any(fnmatch(os.path.join(r, f), p) - for p in options.include)] - if options.exclude: - walk = lambda p: os.walk(p) if os.path.isdir(p) else \ - [(os.path.dirname(p), None, - [os.path.basename(p)])] - path_args = [os.path.join(r, f) - for a in path_args - for r, _, fs in walk(a) - for f in fs - if not any(fnmatch(os.path.join(r, f), p) - for p in options.exclude)] - - # Application invocation.. - if options.build: - result_data = execute_command([application_path] + DEFAULT_ARGS + - command_options + arguments + - path_args, True) - result_path = os.path.join(get_report_directory(), - 'jshint_results.xml') - with open(result_path, 'w') as result_file: - result_file.write(result_data) - else: - print (application_path ) - execute_command([application_path] + DEFAULT_ARGS + - command_options + arguments + path_args) - return 0 - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/test/js/regression/bug.4102.js b/test/js/regression/bug.4102.js deleted file mode 100644 index b62711009..000000000 --- a/test/js/regression/bug.4102.js +++ /dev/null @@ -1,39 +0,0 @@ -// {{{ICINGA_LICENSE_HEADER}}} -/** - * This file is part of Icinga Web 2. - * - * Icinga Web 2 - Head for multiple monitoring backends. - * Copyright (C) 2013 Icinga Development Team - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * @copyright 2013 Icinga Development Team - * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 - * @author Icinga Development Team - * - */ -// {{{ICINGA_LICENSE_HEADER}}} - -describe('regression test for bug #4102', function(){ - it('Object.create', function(){ - Object.create.should.be.a('function'); - - var t = { - name: 'test123' - }; - - t.should.have.property('name').and.equal('test123'); - }); -}); diff --git a/test/js/runtests b/test/js/runtests deleted file mode 100755 index 499d88b3b..000000000 --- a/test/js/runtests +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -import subprocess -from pipes import quote -from optparse import OptionParser, BadOptionError, AmbiguousOptionError - - -APPLICATION = 'mocha' -DEFAULT_ARGS = ['--recursive', '--require', 'should'] - -VAGRANT_SCRIPT = '/vagrant/test/js/runtests' -REPORT_DIRECTORY = '../../build/log' - - -class PassThroughOptionParser(OptionParser): - """ - An unknown option pass-through implementation of OptionParser. - - When unknown arguments are encountered, bundle with largs and try again, - until rargs is depleted. - - sys.exit(status) will still be called if a known argument is passed - incorrectly (e.g. missing arguments or bad argument types, etc.) - - Borrowed from: http://stackoverflow.com/a/9307174 - """ - def _process_args(self, largs, rargs, values): - while rargs: - try: - OptionParser._process_args(self, largs, rargs, values) - except (BadOptionError, AmbiguousOptionError), error: - largs.append(error.opt_str) - - -def execute_command(command, return_output=False, shell=False): - prog = subprocess.Popen(command, shell=shell, - stdout=subprocess.PIPE - if return_output - else None) - return prog.wait() if not return_output else \ - prog.communicate()[0] - - -def get_report_directory(): - path = os.path.abspath(REPORT_DIRECTORY) - - try: - os.makedirs(REPORT_DIRECTORY) - except OSError: - pass - - return path - - -def get_script_directory(): - return os.path.dirname(os.path.abspath(sys.argv[0])) - - -def parse_commandline(): - parser = PassThroughOptionParser(usage='%prog [options] [additional arguments' - ' for {0}]'.format(APPLICATION)) - parser.add_option('-b', '--build', action='store_true', - help='Enable reporting.') - parser.add_option('-v', '--verbose', action='store_true', - help='Be more verbose.') - parser.add_option('-i', '--include', metavar='PATTERN', action='append', - help='Include only specific files/test cases.' - ' (Can be supplied multiple times.)') - parser.add_option('-e', '--exclude', metavar='PATTERN', action='append', - help='Exclude specific files/test cases. ' - '(Can be supplied multiple times.)') - parser.add_option('-V', '--vagrant', action='store_true', - help='Run in vagrant VM') - return parser.parse_args() - - -def main(): - options, arguments = parse_commandline() - - if options.vagrant and os.environ['USER'] != 'vagrant': - # Check if vagrant is installed - vagrant_path = execute_command('which vagrant', True, True).strip() - if not vagrant_path: - print 'ERROR: vagrant not found!' - return 2 - - # Call the script in the Vagrant VM with the same parameters - commandline = ' '.join(quote(p) for p in sys.argv[1:]) - return execute_command('vagrant ssh -c "{0} {1}"' - ''.format(VAGRANT_SCRIPT, commandline), - shell=True) - else: - # Environment preparation and verification - os.chdir(get_script_directory()) - application_path = execute_command('which {0}'.format(APPLICATION), - True, True).strip() - if not application_path: - print 'ERROR: {0} not found!'.format(APPLICATION) - return 2 - os.environ['NODE_PATH'] = os.environ.get('NODE_PATH', '') + \ - ':/usr/local/lib/node_modules' \ - ':/usr/local/share/npm/lib/node_modules' \ - ':/usr/lib/node_modules:./testlib' - - # Commandline preparation - command_options, more_command_options = [], None - if options.include or options.exclude: - for pattern in (options.include or options.exclude): - command_options.append('--grep') - command_options.append(pattern) - if options.exclude: - command_options.append('--invert') - if options.build: - more_command_options = command_options[:len(command_options)] + \ - ['--reporter', 'mocha-cobertura-reporter'] - command_options.extend(['--reporter', 'xunit']) - elif options.verbose: - command_options.extend(['--reporter', 'spec']) - else: - command_options.extend(['--reporter', 'nyan']) - if not any(os.path.isfile(a) or os.path.isdir(a) for a in arguments): - arguments.append('.') - - # Application invocation.. - if more_command_options is None: - execute_command([application_path] + DEFAULT_ARGS + - command_options + arguments) - else: - result_data = execute_command([application_path] + DEFAULT_ARGS + - command_options + arguments, True) - coverage_data = execute_command([application_path] + DEFAULT_ARGS + - more_command_options + arguments, - return_output=True) - # Result storage - report_directory = get_report_directory() - result_path = os.path.join(report_directory, 'mocha_results.xml') - coverage_path = os.path.join(report_directory, 'mocha_coverage.xml') - with open(result_path, 'w') as result_file: - result_file.write(result_data) - with open(coverage_path, 'w') as coverage_file: - coverage_file.write(coverage_data) - - return 0 - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/test/js/test/icinga/componentTest.js b/test/js/test/icinga/componentTest.js deleted file mode 100644 index 8f0d3034b..000000000 --- a/test/js/test/icinga/componentTest.js +++ /dev/null @@ -1,168 +0,0 @@ -// {{{ICINGA_LICENSE_HEADER}}} -/** - * This file is part of Icinga Web 2. - * - * Icinga Web 2 - Head for multiple monitoring backends. - * Copyright (C) 2013 Icinga Development Team - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * @copyright 2013 Icinga Development Team - * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 - * @author Icinga Development Team - * - */ -// {{{ICINGA_LICENSE_HEADER}}} - -require('should'); -var rjsmock = require('requiremock.js'); - -GLOBAL.document = $('body'); -var component; - -/** - * Set up the test fixture - * - * @param registry The optional registry mock that should be used. - */ -var setUp = function(registry) -{ - rjsmock.purgeDependencies(); - - requireNew('icinga/componentRegistry.js'); - registry = registry || rjsmock.getDefine(); - - rjsmock.registerDependencies({ - 'icinga/componentRegistry': registry, - - /* - * Available components - */ - 'components/app/component1': function(cmp) { - cmp.test = 'changed-by-component-1'; - this.type = function() { - return "app/component1"; - }; - return this; - }, - 'components/app/component2': function(cmp) { - cmp.test = 'changed-by-component-2'; - this.type = function() { - return "app/component2"; - }; - return this; - }, - 'components/module/component3': function(cmp) { - cmp.test = 'changed-by-component-3-from-module'; - this.type = function() { - return "module/component3"; - }; - return this; - } - }); - - $('body').empty(); - requireNew('icinga/componentLoader.js'); - component = rjsmock.getDefine(); -}; - -/** - * Add a new component to the current test-DOM - * - * @param type {String} The type of the component in the form: "/" - * @param id {String} The optional id of the component - */ -var addComponent = function(type, id) { - var txt = '
test
'; - - $('body').append(txt); -}; - -describe('Component loader', function() { - - it('Component loaded with automatic id', function() { - setUp(); - addComponent('app/component1'); - component.load(function() { - var cmpNode = $('#icinga-component-0'); - cmpNode.length.should.equal(1); - cmpNode[0].test.should.equal('changed-by-component-1'); - component.getById('icinga-component-0').type().should.equal('app/component1'); - }); - }); - - xit('Component load with user-defined id', function() { - setUp(); - addComponent('app/component2','some-id'); - - component.load(function() { - var cmpNode = $('#some-id'); - cmpNode.length.should.equal(1); - cmpNode[0].test.should.equal('changed-by-component-2'); - component.getById('some-id').type().should.equal('app/component2'); - }); - }); - - it('Garbage collection removes deleted components', function() { - setUp(); - addComponent('app/component1'); - addComponent('app/component2'); - addComponent('app/component2'); - addComponent('module/component3'); - - component.load(function() { - var components = component.getComponents(); - components.length.should.equal(4); - $('body').empty(); - component.load(function() { - var components = component.getComponents(); - components.length.should.equal(0); - }); - }); - }); - - it('Component queries are delegated to the registry correctly', function() { - var getByIdCalled = false; - var getByTypeCalled = false; - var getComponentsCalled = false; - - var registryMock = { - getById: function(id) { - getByIdCalled = true; - id.should.equal('some-id'); - }, - getByType: function(type) { - getByTypeCalled = true; - type.should.equal('some-type'); - }, - getComponents: function() { - getComponentsCalled = true; - } - }; - - setUp(registryMock); - - component.getById('some-id'); - getByIdCalled.should.be.true; - - component.getByType('some-type'); - getByTypeCalled.should.be.true; - - component.getComponents(); - getComponentsCalled.should.be.true; - }); -}); - diff --git a/test/js/test/icinga/components/containerTest.js b/test/js/test/icinga/components/containerTest.js deleted file mode 100644 index 4a7441093..000000000 --- a/test/js/test/icinga/components/containerTest.js +++ /dev/null @@ -1,115 +0,0 @@ -// {{{ICINGA_LICENSE_HEADER}}} -/** - * This file is part of Icinga Web 2. - * - * Icinga Web 2 - Head for multiple monitoring backends. - * Copyright (C) 2013 Icinga Development Team - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * @copyright 2013 Icinga Development Team - * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 - * @author Icinga Development Team - * - */ -// {{{ICINGA_LICENSE_HEADER}}} -/*global requireNew:false, describe: false, it:false */ - - -/** - * The assertion framework - * - * @type {should} - */ -var should = require('should'); - -/** - * RequireJS mocks for dynamically loading modules - * - * @type {requiremock} - */ -var rjsmock = require('requiremock.js'); - -/** - * URIjs object for easier URL manipulation - * - * @type {URIjs} - */ -var URI = require('URIjs'); - -// Setup required globals for this test -GLOBAL.document = $('body'); -GLOBAL.History = require('historymock.js'); -GLOBAL.Modernizr = { - history: true -}; - -/** - * Workaround as jQuery.contains doesn't work with the nodejs jQuery library on some test systems - * - * @returns {boolean} - */ -jQuery.contains = function() { - 'use strict'; - return true; -}; - -/** - * Create a basic dom only containing a main and detail container - * - */ -var createDOM = function() { - 'use strict'; - - document.empty(); - document.append( - $('
').attr('id', 'icingamain') - ).append( - $('
').attr('id', 'icingadetail') - ); -}; - -$.ajax = function(obj) { - obj.success("
"); - -}; -/** - * Test case - * - */ -describe('The container component', function() { - 'use strict'; - - /** - * Test dom selectors and instance creation - */ - it('should provide access to the main and detail component', function() { - createDOM(); - - rjsmock.registerDependencies({ - 'URIjs/URI' : URI, - 'icinga/util/url' : 'icinga/util/url.js' - }); - requireNew('icinga/components/container.js'); - var Container = rjsmock.getDefine(); - should.exist(Container.getMainContainer().containerDom, 'Assert that the main container has an DOM attached'); - should.exist(Container.getDetailContainer().containerDom, 'Assert that the detail container has an DOM attached'); - Container.getMainContainer().containerDom[0].should.equal( - $('#icingamain')[0], 'Assert the DOM of the main container being #icingamain'); - Container.getDetailContainer().containerDom[0].should.equal( - $('#icingadetail')[0], 'Assert the DOM of the detail container being #icingadetail'); - }); - -}); diff --git a/test/js/test/icinga/registryTest.js b/test/js/test/icinga/registryTest.js deleted file mode 100644 index 13a3e0991..000000000 --- a/test/js/test/icinga/registryTest.js +++ /dev/null @@ -1,139 +0,0 @@ -// {{{ICINGA_LICENSE_HEADER}}} -/** - * This file is part of Icinga Web 2. - * - * Icinga Web 2 - Head for multiple monitoring backends. - * Copyright (C) 2013 Icinga Development Team - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * @copyright 2013 Icinga Development Team - * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 - * @author Icinga Development Team - * - */ -// {{{ICINGA_LICENSE_HEADER}}} - -var should = require('should'); -var rjsmock = require('requiremock.js'); - -GLOBAL.document = $('body'); - -var registry; -var setUp = function() { - requireNew('icinga/componentRegistry.js'); - registry = rjsmock.getDefine(); -}; - -var cleanTestDom = function() { - $('body').empty(); -}; - - -describe('Component registry',function() { - it('Ids are created automatically in the form "icinga-component-"', function() { - setUp(); - - registry.add({}, null, null).should.equal('icinga-component-0'); - registry.add({}, null, null).should.equal('icinga-component-1'); - registry.add({}, null, null).should.equal('icinga-component-2'); - - cleanTestDom(); - }); - - xit('Existing ids are preserved', function() { - setUp(); - - registry.add({}, 'user-defined-id', null).should.equal('user-defined-id'); - - cleanTestDom(); - }); - - it('Components are correctly added to the library', function() { - setUp(); - - var cmp2 = { component: "cmp2" }; - registry.add(cmp2, null, null); - registry.getById('icinga-component-0').should.equal(cmp2); - - cleanTestDom(); - }); - - /** - * Not supported anymore - */ - xit('getId(component) should return the components assigned id.', function() { - setUp(); - - var cmp1 = { component: "cmp1" }; - registry.add(cmp1, 'user-defined-id', null); - registry.getId(cmp1).should.equal('user-defined-id'); - - var cmp2 = { component: "cmp2" }; - registry.add(cmp2, 'user-defined-id-2',null); - registry.getId(cmp2).should.equal('user-defined-id-2'); - - should.not.exist(registry.getId({})); - - cleanTestDom(); - }); - - it('getByType() should return all components of a certain type', function() { - setUp(); - - var cmp1 = { component: "some/type" }; - registry.add(cmp1,'some/type'); - - var cmp2 = { component: "some/type" }; - registry.add(cmp2, "some/type"); - - var cmp3 = { component: "other/type" }; - registry.add(cmp3, "other/type"); - - var cmps = registry.getByType('some/type'); - cmps.length.should.equal(2); - cmps[0].component.should.equal('some/type'); - cmps[1].component.should.equal('some/type'); - - cleanTestDom(); - }); - - it('getComponents() should return all components', function() { - setUp(); - - var cmp1 = { component: "cmp1" }; - registry.add(cmp1, null, null); - - var cmp2 = { component: "cmp2" }; - registry.add(cmp2, null, null); - - var cmp3 = { component: "cmp3" }; - registry.add(cmp3, null, null); - - var cmps = registry.getComponents(); - cmps.length.should.equal(3); - cmps[0].should.equal(cmp1); - cmps[1].should.equal(cmp2); - cmps[2].should.equal(cmp3); - - cleanTestDom(); - }); - - /* - * NOTE: The functionality of the garbage collection of this class is - * tested in the componentTest.js - */ -}); - diff --git a/test/js/testlib/asyncmock.js b/test/js/testlib/asyncmock.js deleted file mode 100644 index b5261f800..000000000 --- a/test/js/testlib/asyncmock.js +++ /dev/null @@ -1,61 +0,0 @@ -// {{{ICINGA_LICENSE_HEADER}}} -/** - * This file is part of Icinga Web 2. - * - * Icinga Web 2 - Head for multiple monitoring backends. - * Copyright (C) 2013 Icinga Development Team - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * @copyright 2013 Icinga Development Team - * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 - * @author Icinga Development Team - * - */ -// {{{ICINGA_LICENSE_HEADER}}} - -/** - * Helper for mocking $.async's XHR requests - * - */ - - -var getCallback = function(empty, response, succeed, headers) { - if (empty) - return function() {}; - return function(callback) { - callback(response, succeed, { - getAllResponseHeaders: function() { - return headers; - }, - getResponseHeader: function(header) { - return headers[header] || null; - } - }); - }; -}; - -module.exports = { - setNextAsyncResult: function(async, response, fails, headers) { - headers = headers || {}; - var succeed = fails ? "fail" : "success"; - async.__internalXHRImplementation = function(config) { - return { - done: getCallback(fails, response, succeed, headers), - fail: getCallback(!fails, response, succeed, headers) - }; - }; - } -}; diff --git a/test/js/testlib/historymock.js b/test/js/testlib/historymock.js deleted file mode 100644 index ea0e1d749..000000000 --- a/test/js/testlib/historymock.js +++ /dev/null @@ -1,92 +0,0 @@ -// {{{ICINGA_LICENSE_HEADER}}} -/** - * This file is part of Icinga Web 2. - * - * Icinga Web 2 - Head for multiple monitoring backends. - * Copyright (C) 2013 Icinga Development Team - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * @copyright 2013 Icinga Development Team - * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 - * @author Icinga Development Team - * - */ -// {{{ICINGA_LICENSE_HEADER}}} - -/** - * {{LICENSE_HEADER}} - * {{LICENSE_HEADER}} - */ - -var URI = require('URIjs'); - -(function() { - GLOBAL.window = { - location: { - href: 'http://localhost/icinga2-web/testcase', - pathname: '/icinga2-web/testcase', - query: '', - hash: '', - host: 'localhost', - protocol: 'http' - } - }; - "use strict"; - - var states = []; - - - /** - * Api for setting the window URL - * - * @param {string} url The new url to use for window.location - */ - window.setWindowUrl = function(url) { - var url = URI(url); - window.location.protocol = url.protocol(); - window.location.pathname = url.pathname(); - window.location.query = url.query(); - window.location.search = url.search(); - window.location.hash = url.hash(); - window.location.href = url.href(); - }; - - /** - * Mock for the History API - * - * @type {{pushState: Function, popState: Function, replaceState: Function, clear: Function}} - */ - module.exports = { - pushState: function(state, title, url) { - window.setWindowUrl(url); - states.push(arguments); - }, - popState: function() { - return states.pop(); - }, - replaceState: function(state, title, url) { - states.pop(); - window.setWindowUrl(url); - states.push(arguments); - }, - clearState: function() { - states = []; - }, - getState: function() { - return states; - } - }; -})(); \ No newline at end of file diff --git a/test/js/testlib/requiremock.js b/test/js/testlib/requiremock.js deleted file mode 100644 index 171d0dd70..000000000 --- a/test/js/testlib/requiremock.js +++ /dev/null @@ -1,172 +0,0 @@ -// {{{ICINGA_LICENSE_HEADER}}} -/** - * This file is part of Icinga Web 2. - * - * Icinga Web 2 - Head for multiple monitoring backends. - * Copyright (C) 2013 Icinga Development Team - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * @copyright 2013 Icinga Development Team - * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 - * @author Icinga Development Team - * - */ -// {{{ICINGA_LICENSE_HEADER}}} - -/** -* {{LICENSE_HEADER}} -* {{LICENSE_HEADER}} -**/ - -/** -* This node module acts as a mock for requirejs and allows you to -* define your own dependencies in your tests. It also removes the -* asynchronous character of dependency loading, so you don't need -* to handle everthing in the callbacks. -* -* Per default it resolves the 'logging' dependency by routing it -* to console. -* -**/ -var path = require('path'); -var registeredDependencies = {}; - -/** -* Mock for the requirejs(dependencyList, callback) function, loads -* all dependencies that have been registered under the given names -* in dependencies and calls fn with them as the parameter -* -**/ -var debug = false; -var requireJsMock = function(dependencies, fn) { - var fnArgs = []; - for (var i=0;iobject map of dependencies -* for lookup with requirejs()/define() -**/ -function registerDependencies(obj) { - for(var name in obj) { - registeredDependencies[name] = obj[name]; - } -} -var base = path.normalize(__dirname+"../../../../public/js"); -GLOBAL.requireNew = function(key) { - key = path.normalize(base+"/"+key); - delete require.cache[key]; - return require(key); -}; - -/** -* The API for this module -**/ -module.exports = { - purgeDependencies: purgeDependencies, - registerDependencies: registerDependencies, - getDefine: function(name) { - if (typeof name === "undefined") { - return registeredDependencies.__define__; - } else { - return registeredDependencies[name]; - } - } -}; -