Skip to content

Commit d1b9353

Browse files
committed
Rename new attribute to something more generic
1 parent 2aff6f5 commit d1b9353

18 files changed

Lines changed: 109 additions & 109 deletions

File tree

packages/yoastseo/docs/CONTRACT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const paper = toPaper( {
2222
```
2323

2424
Notes:
25-
- **Covers the analysis inputs.** The neutral core is `text`, `keyphrase`, `synonyms`, `locale`, `description`, `title`, `slug`, `permalink`, `titleWidth`, `textTitle`, `date`, `writingDirection`, and an open `customData` object. Two typed e-commerce slices are validated, unlike `customData`: `productData` (product flags consumed by the identifier/SKU assessments) and `productImages` (the product's own images — `{ id?, src?, alt }` each; providing the field — even as an empty array — scopes the image assessments to these images instead of the images in the text). The contract also carries optional, **deprecated** WordPress-transitional fields (`wpBlocks`, `shortcodes`, `isFrontPage`): they are real analysis inputs that change WordPress scores, so a remote/API analysis needs them to reproduce in-browser results. They are marked deprecated. Non-WordPress consumers simply omit them.
25+
- **Covers the analysis inputs.** The neutral core is `text`, `keyphrase`, `synonyms`, `locale`, `description`, `title`, `slug`, `permalink`, `titleWidth`, `textTitle`, `date`, `writingDirection`, and an open `customData` object. Two typed e-commerce slices are validated, unlike `customData`: `productData` (product flags consumed by the identifier/SKU assessments) and `providedImages` (the analyzed item's own images — `{ id?, src?, alt }` each, e.g. a product's featured, gallery and variation images; providing the field — even as an empty array — scopes the image assessments to these images instead of the images in the text). The contract also carries optional, **deprecated** WordPress-transitional fields (`wpBlocks`, `shortcodes`, `isFrontPage`): they are real analysis inputs that change WordPress scores, so a remote/API analysis needs them to reproduce in-browser results. They are marked deprecated. Non-WordPress consumers simply omit them.
2626
- **`keyphrase` is the canonical field name.** `keyword` is accepted as a deprecated alias so existing consumers can adopt the contract without renaming.
2727
- **Validation.** `toPaper` throws on structurally invalid input (wrong types, unknown keys). Omitting an optional field is fine — the assessments that need it are simply skipped, matching the engine's existing behaviour.
2828
- **Closed by design.** The schema is not extensible. Extra top-level fields are rejected, and there is deliberately no hook for swapping in an extended schema — a consumer-specific field would not be part of a shared contract. Consumers that register their own assessments pass extra inputs through `customData`, whose contents the contract carries but does not validate.

packages/yoastseo/spec/contract/paperDtoSpec.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,36 +92,36 @@ describe( "the Paper input contract (PaperDto)", function() {
9292
expect( () => toPaper( { text: "x", productData: { hasGlobalSku: true } } ) ).toThrow();
9393
} );
9494

95-
it( "maps a typed productImages array onto the Paper", function() {
96-
const productImages = [
95+
it( "maps a typed providedImages array onto the Paper", function() {
96+
const providedImages = [
9797
{ id: 1, src: "https://example.com/image.jpg", alt: "An image" },
9898
{ alt: "" },
9999
];
100-
const paper = toPaper( { text: "x", productImages } );
100+
const paper = toPaper( { text: "x", providedImages } );
101101

102-
expect( paper.getProductImages() ).toEqual( productImages );
102+
expect( paper.getProvidedImages() ).toEqual( providedImages );
103103
} );
104104

105-
it( "leaves absent productImages to Paper's default null, meaning the producer did not opt in", function() {
105+
it( "leaves absent providedImages to Paper's default null, meaning the producer did not opt in", function() {
106106
const paper = toPaper( { text: "x" } );
107107

108-
expect( paper.getProductImages() ).toBeNull();
109-
expect( paper.hasProductImages() ).toBe( false );
108+
expect( paper.getProvidedImages() ).toBeNull();
109+
expect( paper.hasProvidedImages() ).toBe( false );
110110
} );
111111

112-
it( "accepts an empty productImages array as a valid opt-in: a product without images", function() {
113-
const paper = toPaper( { text: "x", productImages: [] } );
112+
it( "accepts an empty providedImages array as a valid opt-in: an item without images", function() {
113+
const paper = toPaper( { text: "x", providedImages: [] } );
114114

115-
expect( paper.getProductImages() ).toEqual( [] );
116-
expect( paper.hasProductImages() ).toBe( true );
115+
expect( paper.getProvidedImages() ).toEqual( [] );
116+
expect( paper.hasProvidedImages() ).toBe( true );
117117
} );
118118

119-
it( "type-checks productImages fields and rejects unknown keys (strict)", function() {
120-
expect( () => toPaper( { text: "x", productImages: { alt: "not an array" } } ) ).toThrow();
121-
expect( () => toPaper( { text: "x", productImages: [ { src: "https://example.com/image.jpg" } ] } ) ).toThrow();
122-
expect( () => toPaper( { text: "x", productImages: [ { alt: 1 } ] } ) ).toThrow();
123-
expect( () => toPaper( { text: "x", productImages: [ { id: "1", alt: "" } ] } ) ).toThrow();
124-
expect( () => toPaper( { text: "x", productImages: [ { alt: "", altText: "typo" } ] } ) ).toThrow();
119+
it( "type-checks providedImages fields and rejects unknown keys (strict)", function() {
120+
expect( () => toPaper( { text: "x", providedImages: { alt: "not an array" } } ) ).toThrow();
121+
expect( () => toPaper( { text: "x", providedImages: [ { src: "https://example.com/image.jpg" } ] } ) ).toThrow();
122+
expect( () => toPaper( { text: "x", providedImages: [ { alt: 1 } ] } ) ).toThrow();
123+
expect( () => toPaper( { text: "x", providedImages: [ { id: "1", alt: "" } ] } ) ).toThrow();
124+
expect( () => toPaper( { text: "x", providedImages: [ { alt: "", altText: "typo" } ] } ) ).toThrow();
125125
} );
126126

127127
it( "accepts the deprecated WP-transitional fields and maps them onto the Paper", function() {

packages/yoastseo/spec/languageProcessing/helpers/image/getImagesInScopeSpec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Paper from "../../../../src/values/Paper";
44
import buildTree from "../../../specHelpers/parse/buildTree";
55
import EnglishResearcher from "../../../../src/languageProcessing/languages/en/Researcher";
66

7-
const productImages = [
7+
const providedImages = [
88
{ id: 1, src: "https://example.com/featured.jpg", alt: "A featured image" },
99
{ id: 2, src: "https://example.com/gallery.jpg", alt: "" },
1010
];
@@ -23,28 +23,28 @@ const buildPaperWithTreeImage = ( attributes = {} ) => {
2323
};
2424

2525
describe( "getImagesInScope", function() {
26-
it( "returns the tree images when the paper carries no productImages attribute", function() {
26+
it( "returns the tree images when the paper carries no providedImages attribute", function() {
2727
const images = getImagesInScope( buildPaperWithTreeImage() );
2828

2929
expect( images ).toHaveLength( 1 );
3030
expect( images[ 0 ].attributes.alt ).toBe( "tree image" );
3131
} );
3232

33-
it( "returns only the product images, mapped to img pseudo-nodes, when the paper carries them", function() {
34-
const images = getImagesInScope( buildPaperWithTreeImage( { productImages } ) );
33+
it( "returns only the provided images, mapped to img pseudo-nodes, when the paper carries them", function() {
34+
const images = getImagesInScope( buildPaperWithTreeImage( { providedImages } ) );
3535

3636
expect( images ).toEqual( [
3737
{ name: "img", attributes: { src: "https://example.com/featured.jpg", alt: "A featured image" } },
3838
{ name: "img", attributes: { src: "https://example.com/gallery.jpg", alt: "" } },
3939
] );
4040
} );
4141

42-
it( "returns an empty array when the producer opted in with an empty productImages array, even when the text has images", function() {
43-
expect( getImagesInScope( buildPaperWithTreeImage( { productImages: [] } ) ) ).toEqual( [] );
42+
it( "returns an empty array when the producer opted in with an empty providedImages array, even when the text has images", function() {
43+
expect( getImagesInScope( buildPaperWithTreeImage( { providedImages: [] } ) ) ).toEqual( [] );
4444
} );
4545

46-
it( "defaults missing src and alt to empty strings when mapping product images", function() {
47-
expect( getImagesInScope( buildPaperWithTreeImage( { productImages: [ { id: 3 } ] } ) ) ).toEqual( [
46+
it( "defaults missing src and alt to empty strings when mapping provided images", function() {
47+
expect( getImagesInScope( buildPaperWithTreeImage( { providedImages: [ { id: 3 } ] } ) ) ).toEqual( [
4848
{ name: "img", attributes: { src: "", alt: "" } },
4949
] );
5050
} );
@@ -55,7 +55,7 @@ describe( "getImagesInScope", function() {
5555

5656
const treePaper = new Paper( `string <img src='${ src }' alt='${ alt }' />` );
5757
buildTree( treePaper, new EnglishResearcher( treePaper ) );
58-
const productPaper = new Paper( "string without images", { productImages: [ { id: 4, src, alt } ] } );
58+
const productPaper = new Paper( "string without images", { providedImages: [ { id: 4, src, alt } ] } );
5959

6060
const [ treeNode ] = getImagesInScope( treePaper );
6161
const [ productNode ] = getImagesInScope( productPaper );

packages/yoastseo/spec/languageProcessing/researches/altTagCountSpec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,11 @@ describe( "Counts images in a text", function() {
302302
} );
303303
} );
304304

305-
describe( "Counts alt-tags of the paper's product images when the producer provides them", function() {
306-
it( "classifies the paper's product images by their alt texts and ignores the images in the text", function() {
305+
describe( "Counts alt-tags of the paper's provided images when the producer provides them", function() {
306+
it( "classifies the paper's provided images by their alt texts and ignores the images in the text", function() {
307307
const paper = new Paper( "string <img src='http://plaatje' alt='keyword' />", {
308308
keyword: "keyword",
309-
productImages: [
309+
providedImages: [
310310
{ id: 1, src: "https://example.com/featured.jpg", alt: "keyword" },
311311
{ id: 2, src: "https://example.com/gallery.jpg", alt: "something else" },
312312
{ id: 3, src: "https://example.com/variation.jpg", alt: "" },
@@ -323,10 +323,10 @@ describe( "Counts alt-tags of the paper's product images when the producer provi
323323
expect( stringToCheck.withAltNonKeyword ).toBe( 1 );
324324
} );
325325

326-
it( "classifies alt-texted product images as withAlt when no keyphrase is set", function() {
326+
it( "classifies alt-texted provided images as withAlt when no keyphrase is set", function() {
327327
const paper = new Paper( "string", {
328328
keyword: "",
329-
productImages: [ { id: 1, src: "https://example.com/featured.jpg", alt: "A featured image" } ],
329+
providedImages: [ { id: 1, src: "https://example.com/featured.jpg", alt: "A featured image" } ],
330330
} );
331331
const researcher = new Researcher( paper );
332332
researcher.addResearchData( "morphology", morphologyData );
@@ -339,10 +339,10 @@ describe( "Counts alt-tags of the paper's product images when the producer provi
339339
expect( stringToCheck.withAltNonKeyword ).toBe( 0 );
340340
} );
341341

342-
it( "classifies nothing when the producer opted in with an empty productImages array, even when the text has images", function() {
342+
it( "classifies nothing when the producer opted in with an empty images array, even when the text has images", function() {
343343
const paper = new Paper( "string <img src='http://plaatje' alt='keyword' />", {
344344
keyword: "keyword",
345-
productImages: [],
345+
providedImages: [],
346346
} );
347347
const researcher = new Researcher( paper );
348348
researcher.addResearchData( "morphology", morphologyData );

packages/yoastseo/spec/languageProcessing/researches/imageCountInTextSpec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ describe( "Counts images in an text", function() {
2525
} );
2626
} );
2727

28-
describe( "Counts the paper's product images when the producer provides them", function() {
29-
it( "counts the paper's product images and ignores the images in the text", function() {
28+
describe( "Counts the paper's provided images when the producer provides them", function() {
29+
it( "counts the paper's provided images and ignores the images in the text", function() {
3030
const paper = new Paper( "string <img src='http://plaatje' alt='' />", {
31-
productImages: [
31+
providedImages: [
3232
{ id: 1, src: "https://example.com/featured.jpg", alt: "A featured image" },
3333
{ id: 2, src: "https://example.com/gallery.jpg", alt: "" },
3434
],
@@ -41,8 +41,8 @@ describe( "Counts the paper's product images when the producer provides them", f
4141
expect( imageCount ).toBe( 2 );
4242
} );
4343

44-
it( "returns imagecount 0 when the producer opted in with an empty productImages array, even when the text has images", function() {
45-
const paper = new Paper( "string <img src='http://plaatje' alt='' />", { productImages: [] } );
44+
it( "returns imagecount 0 when the producer opted in with an empty providedImages array, even when the text has images", function() {
45+
const paper = new Paper( "string <img src='http://plaatje' alt='' />", { providedImages: [] } );
4646
const researcher = new EnglishResearcher( paper );
4747
buildTree( paper, researcher );
4848

packages/yoastseo/spec/scoring/assessments/seo/ImageAltTagsAssessmentSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import Factory from "../../../../src/helpers/factory.js";
66
const imageAltTagsAssessment = new ImageAltTagsAssessment();
77

88
describe( "test to check if all images have alt tags", function() {
9-
it( "still assesses an empty text when the counted images come from the paper's product images", function() {
10-
// In the productImages scope the researches count paper-level images, so an empty text must not zero the result.
9+
it( "still assesses an empty text when the counted images come from the paper's provided images", function() {
10+
// When the paper provides its own images the researches count paper-level images, so an empty text must not zero the result.
1111
const result = imageAltTagsAssessment.getResult( new Paper( "" ), Factory.buildMockResearcher( {
1212
imageCount: 2,
1313
altTagCount: {

packages/yoastseo/spec/scoring/assessments/seo/ImageCountAssessmentSpec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ describe( "tests for the assessment applicability.", function() {
182182
} );
183183
} );
184184

185-
describe( "tests for the productImages scope.", function() {
186-
it( "still assesses an empty text when the counted images come from the paper's product images.", function() {
187-
// In the productImages scope the researches count paper-level images, so an empty text must not zero the result.
185+
describe( "tests for the provided-images scope.", function() {
186+
it( "still assesses an empty text when the counted images come from the paper's provided images.", function() {
187+
// When the paper provides its own images the researches count paper-level images, so an empty text must not zero the result.
188188
const assessment = imageCountAssessment.getResult( new Paper( "" ), Factory.buildMockResearcher( {
189189
imageCount: 4,
190190
}, true ) );

packages/yoastseo/spec/scoring/assessments/seo/KeyphraseInImageTextAssessmentSpec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ describe( "tests for the assessment applicability.", function() {
360360
} );
361361
} );
362362

363-
describe( "tests for the productImages scope.", function() {
364-
it( "still assesses an empty text when the counted images come from the paper's product images.", function() {
365-
// In the productImages scope the researches count paper-level images, so an empty text must not zero the result.
363+
describe( "tests for the provided-images scope.", function() {
364+
it( "still assesses an empty text when the counted images come from the paper's provided images.", function() {
365+
// When the paper provides its own images the researches count paper-level images, so an empty text must not zero the result.
366366
const assessment = new KeyphraseInImagesAssessment().getResult( new Paper( "", { keyword: "keyword" } ), Factory.buildMockResearcher( {
367367
imageCount: 4,
368368
altTagCount: { noAlt: 0, withAlt: 0, withAltKeyword: 1, withAltNonKeyword: 3 },

packages/yoastseo/spec/values/PaperSpec.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,25 +130,25 @@ describe( "Paper", function() {
130130
expect( paper.getProductData() ).toEqual( {} );
131131
} );
132132

133-
it( "returns product images", function() {
133+
it( "returns the provided images", function() {
134134
const attributes = {
135-
productImages: [ { id: 1, src: "https://example.com/image.jpg", alt: "An image" }, { id: 2, src: "", alt: "" } ],
135+
providedImages: [ { id: 1, src: "https://example.com/image.jpg", alt: "An image" }, { id: 2, src: "", alt: "" } ],
136136
};
137137
const paper = new Paper( "", attributes );
138-
expect( paper.getProductImages() ).toEqual( attributes.productImages );
138+
expect( paper.getProvidedImages() ).toEqual( attributes.providedImages );
139139
} );
140140

141-
it( "returns null for the product images when none are provided", function() {
141+
it( "returns null for the provided images when none are provided", function() {
142142
const paper = new Paper( "" );
143-
expect( paper.getProductImages() ).toBeNull();
144-
expect( paper.hasProductImages() ).toBe( false );
143+
expect( paper.getProvidedImages() ).toBeNull();
144+
expect( paper.hasProvidedImages() ).toBe( false );
145145
} );
146146

147-
it( "treats an explicitly provided empty product images array as having product images", function() {
147+
it( "treats an explicitly provided empty providedImages array as having provided images", function() {
148148
// The producer opted in: a product without images, which the image assessments must score as such.
149-
const paper = new Paper( "", { productImages: [] } );
150-
expect( paper.getProductImages() ).toEqual( [] );
151-
expect( paper.hasProductImages() ).toBe( true );
149+
const paper = new Paper( "", { providedImages: [] } );
150+
expect( paper.getProvidedImages() ).toEqual( [] );
151+
expect( paper.hasProvidedImages() ).toBe( true );
152152
} );
153153

154154
it( "returns the text title", function() {
@@ -230,9 +230,9 @@ describe( "Paper", function() {
230230
expect( paper1.equals( paper2 ) ).toBe( false );
231231
} );
232232

233-
it( "should identify two papers with similar content but dissimilar product images as not equal", function() {
234-
const paper1 = new Paper( "This is a test", { productImages: [ { id: 1, src: "https://example.com/image.jpg", alt: "An image" } ] } );
235-
const paper2 = new Paper( "This is a test", { productImages: [ { id: 1, src: "https://example.com/image.jpg", alt: "New alt" } ] } );
233+
it( "should identify two papers with similar content but dissimilar provided images as not equal", function() {
234+
const paper1 = new Paper( "This is a test", { providedImages: [ { id: 1, src: "https://example.com/image.jpg", alt: "An image" } ] } );
235+
const paper2 = new Paper( "This is a test", { providedImages: [ { id: 1, src: "https://example.com/image.jpg", alt: "New alt" } ] } );
236236
expect( paper1.equals( paper2 ) ).toBe( false );
237237
} );
238238
} );
@@ -250,10 +250,10 @@ describe( "Paper", function() {
250250
expect( paper1.hasSameTreeInputsAs( paper2 ) ).toBe( true );
251251
} );
252252

253-
it( "returns true when only the product images differ", function() {
254-
// Product images don't feed the tree builder, so a change must not invalidate the cached tree.
255-
const paper1 = new Paper( "<p>Hello world.</p>", { productImages: [ { id: 1, src: "https://example.com/image.jpg", alt: "An image" } ] } );
256-
const paper2 = new Paper( "<p>Hello world.</p>", { productImages: [ { id: 2, src: "https://example.com/other.jpg", alt: "" } ] } );
253+
it( "returns true when only the provided images differ", function() {
254+
// Provided images don't feed the tree builder, so a change must not invalidate the cached tree.
255+
const paper1 = new Paper( "<p>Hello world.</p>", { providedImages: [ { id: 1, src: "https://example.com/image.jpg", alt: "An image" } ] } );
256+
const paper2 = new Paper( "<p>Hello world.</p>", { providedImages: [ { id: 2, src: "https://example.com/other.jpg", alt: "" } ] } );
257257
expect( paper1.hasSameTreeInputsAs( paper2 ) ).toBe( true );
258258
} );
259259

@@ -385,11 +385,11 @@ describe( "Paper", function() {
385385
expect( parsed.getProductData() ).toEqual( productData );
386386
} );
387387

388-
it( "round-trips the product images through serialize and parse", () => {
389-
const productImages = [ { id: 1, src: "https://example.com/image.jpg", alt: "An image" }, { id: 2, src: "https://example.com/other.jpg", alt: "" } ];
390-
const paper = new Paper( "text", { productImages } );
388+
it( "round-trips the provided images through serialize and parse", () => {
389+
const providedImages = [ { id: 1, src: "https://example.com/image.jpg", alt: "An image" }, { id: 2, src: "https://example.com/other.jpg", alt: "" } ];
390+
const paper = new Paper( "text", { providedImages } );
391391
const parsed = Paper.parse( paper.serialize() );
392-
expect( parsed.getProductImages() ).toEqual( productImages );
392+
expect( parsed.getProvidedImages() ).toEqual( providedImages );
393393
} );
394394
} );
395395
describe( "A test for setters and getters", function() {

0 commit comments

Comments
 (0)