summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/qunit/smw/data/ext.smw.dataItem.time.test.js
blob: cf0f0aed36977bae2403d37c4a4640d0f3847c93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
 * QUnit tests
 *
 * @since 1.9
 *
 * @file
 * @ingroup SMW
 *
 * @licence GNU GPL v2 or later
 * @author mwjames
 */
( function ( $, mw, smw ) {
	'use strict';

	QUnit.module( 'ext.smw.dataItem.time', QUnit.newMwEnvironment() );

	var pass = 'Passes because ';

	/**
	 * Test accessibility
	 *
	 * @since: 1.9
	 */
	QUnit.test( 'instance', function ( assert ) {
		assert.expect( 1 );

		var result = new smw.dataItem.time( '1362200400' );
		assert.ok( result instanceof Object, pass + 'the smw.dataItem.time instance was accessible' );

	} );

	/**
	 * Test type
	 *
	 * @since: 1.9
	 */
	QUnit.test( 'getDIType', function ( assert ) {
		assert.expect( 1 );

		var result = new smw.dataItem.time( '1362200400' );
		assert.equal( result.getDIType(), '_dat', pass + 'returned _dat' );

	} );

	/**
	 * Test getUri
	 *
	 * @since: 1.9
	 */
	QUnit.test( 'getMwTimestamp', function ( assert ) {
		assert.expect( 2 );

		var result;

		result = new smw.dataItem.time( '1362200400' );
		assert.equal( result.getMwTimestamp(), '1362200400', pass + 'returned a MW timestamp' );

		result = new smw.dataItem.time( 1362200400 );
		assert.equal( result.getMwTimestamp(), '1362200400', pass + 'returned a MW timestamp' );

	} );

	/**
	 * Test getDate
	 *
	 * @since: 1.9
	 */
	QUnit.test( 'getDate', function ( assert ) {
		assert.expect( 1 );

		var result;

		result = new smw.dataItem.time( '1362200400' );
		assert.ok( result.getDate() instanceof Date, pass + 'returned a JavaScript Date instance' );

	} );

	/**
	 * Test getISO8601Date
	 *
	 * @since: 1.9
	 */
	QUnit.test( 'getISO8601Date', function ( assert ) {
		assert.expect( 1 );

		var result;

		result = new smw.dataItem.time( '1362200400' );
		assert.equal( result.getISO8601Date(), '2013-03-02T05:00:00.000Z', pass + 'returned a ISO string date/time' );

	} );

	/**
	 * Test getTimeString
	 *
	 * @since: 1.9
	 */
	QUnit.test( 'getTimeString', function ( assert ) {
		assert.expect( 1 );

		var result;

		result = new smw.dataItem.time( '1362200400' );
		assert.equal( result.getTimeString(), '05:00:00', pass + 'returned a time string' );

	} );

	/**
	 * Test getMediaWikiDate
	 *
	 * @since: 1.9
	 */
	QUnit.test( 'getMediaWikiDate', function ( assert ) {
		assert.expect( 1 );

		var result;

		// Use as helper to fetch language dep. month name
		var monthNames = [];
		$.map ( mw.config.get( 'wgMonthNames' ), function( index ) {
			if( index !== '' ){
				monthNames.push( index );
			}
		} );

		result = new smw.dataItem.time( '1362200400' );
		assert.equal( result.getMediaWikiDate(), '2 ' + monthNames[2] + ' 2013 05:00:00', pass + 'returned a MW date and time formatted string' );

	} );

}( jQuery, mediaWiki, semanticMediaWiki ) );