Santhosh has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/373279 )
Change subject: Unit tests for MWLink translation unit class
......................................................................
Unit tests for MWLink translation unit class
Change-Id: I25ffb50cf7c27ca1f5cf71176d31465fde470db0
---
M lib/translationunits/MWLink.js
M test/index.js
A test/translationunits/MWLink.test.js
A test/translationunits/MWLink.test.json
4 files changed, 313 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver
refs/changes/79/373279/1
diff --git a/lib/translationunits/MWLink.js b/lib/translationunits/MWLink.js
index d28269d..01e1345 100644
--- a/lib/translationunits/MWLink.js
+++ b/lib/translationunits/MWLink.js
@@ -30,6 +30,7 @@
if ( linkPairInfo.targetTitle ) {
// NOTE: This paths we are setting here are not relative paths.
this.node.attributes[ 'href' ] = linkPairInfo.targetTitle;
+ this.node.attributes[ 'title' ] = linkPairInfo.targetTitle;
adaptationInfo.targetTitle = yield
apiRequestManager.titleInfoRequest(
linkPairInfo.targetTitle, this.targetLanguage
);
diff --git a/test/index.js b/test/index.js
index b6feadd..142b56e 100644
--- a/test/index.js
+++ b/test/index.js
@@ -13,6 +13,7 @@
'lib/pageloader',
'lib/routes',
'lib/segmentation',
+ 'lib/translationunits',
'tests/**/*.js'
];
diff --git a/test/translationunits/MWLink.test.js
b/test/translationunits/MWLink.test.js
new file mode 100644
index 0000000..eb17808
--- /dev/null
+++ b/test/translationunits/MWLink.test.js
@@ -0,0 +1,24 @@
+'use strict';
+
+var assert = require( '../utils/assert.js' ),
+ server = require( '../utils/server.js' ),
+ async = require( 'async' ),
+ Adapter = require( '../../lib/Adapter' ),
+ tests = require( './MWLink.test.json' );
+
+describe( 'Link Adaptation tests', function () {
+ async.forEach( tests, function ( test ) {
+ it( 'should not have any errors when: ' + test.desc, function
() {
+ var translationunit, adapter;
+
+ adapter = new Adapter( test.from, test.to,
server.config );
+ translationunit = adapter.getAdapter( test.source );
+ return translationunit.adapt( test.source ).then(
function ( adaptedNode ) {
+ assert.deepEqual( adaptedNode.attributes.href,
test.result.attributes.href );
+ assert.deepEqual( adaptedNode.attributes.rel,
test.result.attributes.rel );
+ assert.deepEqual( adaptedNode.attributes.title,
test.result.attributes.title );
+ assert.deepEqual( JSON.parse(
adaptedNode.attributes[ 'data-cx' ] ), test.result.attributes[ 'data-cx' ] );
+ } );
+ } );
+ } );
+} );
diff --git a/test/translationunits/MWLink.test.json
b/test/translationunits/MWLink.test.json
new file mode 100644
index 0000000..f39befe
--- /dev/null
+++ b/test/translationunits/MWLink.test.json
@@ -0,0 +1,287 @@
+[
+ {
+ "desc": "Basic test",
+ "from": "en",
+ "to": "es",
+ "source": {
+ "attributes": {
+ "rel": "mw:WikiLink",
+ "href": "Oxygen",
+ "title": "Oxygen"
+ }
+ },
+ "result": {
+ "attributes": {
+ "rel": "mw:WikiLink",
+ "href": "Oxígeno",
+ "title": "Oxígeno",
+ "data-cx": {
+ "adapted": true,
+ "targetTitle": {
+ "pageid": 3267,
+ "ns": 0,
+ "title": "Oxígeno",
+ "contentmodel": "wikitext",
+ "pagelanguage": "es",
+ "pagelanguagehtmlcode": "es",
+ "pagelanguagedir": "ltr",
+ "touched":
"2017-08-22T17:53:12Z",
+ "lastrevid": 101258484,
+ "length": 104691,
+ "thumbnail": {
+ "source":
"https://upload.wikimedia.org/wikipedia/commons/thumb/7/77/O%2C8.jpg/80px-O%2C8.jpg",
+ "width": 80,
+ "height": 40
+ },
+ "pageimage": "O,8.jpg",
+ "terms": {
+ "description":
["elemento químico", "elemento químico"]
+ }
+ },
+ "sourceTitle": {
+ "pageid": 22303,
+ "ns": 0,
+ "title": "Oxygen",
+ "contentmodel": "wikitext",
+ "pagelanguage": "en",
+ "pagelanguagehtmlcode": "en",
+ "pagelanguagedir": "ltr",
+ "touched":
"2017-08-22T14:57:56Z",
+ "lastrevid": 796696396,
+ "length": 98654,
+ "thumbnail": {
+ "source":
"https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Liquid_oxygen_in_a_beaker_4.jpg/66px-Liquid_oxygen_in_a_beaker_4.jpg",
+ "width": 66,
+ "height": 80
+ },
+ "pageimage":
"Liquid_oxygen_in_a_beaker_4.jpg",
+ "terms": {
+ "description":
["element with the atomic number of 8", "element with the atomic number of 8"]
+ }
+ }
+ }
+
+ }
+ }
+ },
+ {
+ "desc": "Space in the title",
+ "from": "en",
+ "to": "es",
+ "source": {
+ "attributes": {
+ "rel": "mw:WikiLink",
+ "href": "Atomic number",
+ "title": "Atomic number"
+ }
+ },
+ "result": {
+ "attributes": {
+ "rel": "mw:WikiLink",
+ "href": "Número atómico",
+ "title": "Número atómico",
+ "data-cx": {
+ "adapted": true,
+ "targetTitle": {
+ "pageid": 1980,
+ "ns": 0,
+ "title": "Número atómico",
+ "contentmodel": "wikitext",
+ "pagelanguage": "es",
+ "pagelanguagehtmlcode": "es",
+ "pagelanguagedir": "ltr",
+ "touched":
"2017-08-22T17:15:11Z",
+ "lastrevid": 100517772,
+ "length": 8663,
+ "thumbnail": {
+ "source":
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/db/Element_identity.png/80px-Element_identity.png",
+ "width": 80,
+ "height": 80
+ },
+ "pageimage":
"Element_identity.png",
+ "terms": {
+ "description": ["número
total de protones que tiene el átomo", "número total de protones que tiene el
átomo"]
+ }
+ },
+ "sourceTitle": {
+ "pageid": 673,
+ "ns": 0,
+ "title": "Atomic number",
+ "contentmodel": "wikitext",
+ "pagelanguage": "en",
+ "pagelanguagehtmlcode": "en",
+ "pagelanguagedir": "ltr",
+ "touched":
"2017-08-08T20:00:47Z",
+ "lastrevid": 793422588,
+ "length": 14072,
+ "thumbnail": {
+ "source":
"https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Atomic_number_depiction.jpg/80px-Atomic_number_depiction.jpg",
+ "width": 80,
+ "height": 49
+ },
+ "pageimage":
"Atomic_number_depiction.jpg",
+ "terms": {
+ "description": ["number
of protons found in the nucleus of an atom", "number of protons found in the
nucleus of an atom"]
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "desc": "Relative URL",
+ "from": "en",
+ "to": "es",
+ "source": {
+ "attributes": {
+ "rel": "mw:WikiLink",
+ "href": "./Atomic number",
+ "title": "Atomic number"
+ }
+ },
+ "result": {
+ "attributes": {
+ "rel": "mw:WikiLink",
+ "href": "Número atómico",
+ "title": "Número atómico",
+ "data-cx": {
+ "adapted": true,
+ "targetTitle": {
+ "pageid": 1980,
+ "ns": 0,
+ "title": "Número atómico",
+ "contentmodel": "wikitext",
+ "pagelanguage": "es",
+ "pagelanguagehtmlcode": "es",
+ "pagelanguagedir": "ltr",
+ "touched":
"2017-08-22T17:15:11Z",
+ "lastrevid": 100517772,
+ "length": 8663,
+ "thumbnail": {
+ "source":
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/db/Element_identity.png/80px-Element_identity.png",
+ "width": 80,
+ "height": 80
+ },
+ "pageimage":
"Element_identity.png",
+ "terms": {
+ "description": ["número
total de protones que tiene el átomo", "número total de protones que tiene el
átomo"]
+ }
+ },
+ "sourceTitle": {
+ "pageid": 673,
+ "ns": 0,
+ "title": "Atomic number",
+ "contentmodel": "wikitext",
+ "pagelanguage": "en",
+ "pagelanguagehtmlcode": "en",
+ "pagelanguagedir": "ltr",
+ "touched":
"2017-08-08T20:00:47Z",
+ "lastrevid": 793422588,
+ "length": 14072,
+ "thumbnail": {
+ "source":
"https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Atomic_number_depiction.jpg/80px-Atomic_number_depiction.jpg",
+ "width": 80,
+ "height": 49
+ },
+ "pageimage":
"Atomic_number_depiction.jpg",
+ "terms": {
+ "description": ["number
of protons found in the nucleus of an atom", "number of protons found in the
nucleus of an atom"]
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "desc": "Title with paranthesis",
+ "from": "en",
+ "to": "es",
+ "source": {
+ "attributes": {
+ "rel": "mw:WikiLink",
+ "href": "./The_Godfather_(wrestler)",
+ "title": "The Godfather (wrestler)"
+ }
+ },
+ "result": {
+ "attributes": {
+ "rel": "mw:WikiLink",
+ "href": "Charles Wright (luchador)",
+ "title": "Charles Wright (luchador)",
+ "data-cx": {
+ "adapted": true,
+ "targetTitle": {
+ "pageid": 2834764,
+ "ns": 0,
+ "title": "Charles Wright
(luchador)",
+ "contentmodel": "wikitext",
+ "pagelanguage": "es",
+ "pagelanguagehtmlcode": "es",
+ "pagelanguagedir": "ltr",
+ "touched":
"2017-08-23T05:11:08Z",
+ "lastrevid": 98884680,
+ "length": 24590,
+ "thumbnail": {
+ "source":
"https://upload.wikimedia.org/wikipedia/commons/thumb/6/65/Paul_Wright_AKA_%28The_Godfather%29.jpg/50px-Paul_Wright_AKA_%28The_Godfather%29.jpg",
+ "width": 50,
+ "height": 80
+ },
+ "pageimage":
"Paul_Wright_AKA_(The_Godfather).jpg"
+ },
+ "sourceTitle": {
+ "pageid": 591648,
+ "ns": 0,
+ "title": "The Godfather
(wrestler)",
+ "contentmodel": "wikitext",
+ "pagelanguage": "en",
+ "pagelanguagehtmlcode": "en",
+ "pagelanguagedir": "ltr",
+ "touched":
"2017-08-20T06:08:16Z",
+ "lastrevid": 794051088,
+ "length": 36176,
+ "thumbnail": {
+ "source":
"https://upload.wikimedia.org/wikipedia/commons/thumb/f/f9/Charles_Wright_AKA_The_Godfather_WrestleMania_32_Axxess.jpg/51px-Charles_Wright_AKA_The_Godfather_WrestleMania_32_Axxess.jpg",
+ "width": 51,
+ "height": 80
+ },
+ "pageimage":
"Charles_Wright_AKA_The_Godfather_WrestleMania_32_Axxess.jpg",
+ "terms": {
+ "description":
["professional wrestler, strip club manager"]
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "desc": "Target title does not exist",
+ "from": "en",
+ "to": "es",
+ "source": {
+ "attributes": {
+ "rel": "mw:WikiLink",
+ "href": "./List_of_planets_with_life",
+ "title": "List of planets with life"
+ }
+ },
+ "result": {
+ "attributes": {
+ "rel": "mw:WikiLink",
+ "href": "./List_of_planets_with_life",
+ "title": "List of planets with life",
+ "data-cx": {
+ "adapted": false,
+ "sourceTitle": {
+ "contentmodel": "wikitext",
+ "missing": "",
+ "ns": 0,
+ "pagelanguage": "en",
+ "pagelanguagedir": "ltr",
+ "pagelanguagehtmlcode": "en",
+ "title": "List of planets with
life"
+ }
+ }
+ }
+ }
+ }
+]
--
To view, visit https://gerrit.wikimedia.org/r/373279
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I25ffb50cf7c27ca1f5cf71176d31465fde470db0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
