schema.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Schema from '../../src/model/schema';
  6. import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  7. import Element from '../../src/model/element';
  8. import Position from '../../src/model/position';
  9. import Text from '../../src/model/text';
  10. describe( 'Schema', () => {
  11. let schema, root1, r1p1, r1p2, r1bQ, r1bQp, root2;
  12. beforeEach( () => {
  13. schema = new Schema();
  14. root1 = new Element( '$root', null, [
  15. new Element( 'paragraph', null, 'foo' ),
  16. new Element( 'paragraph', { align: 'right' }, 'bar' ),
  17. new Element( 'blockQuote', null, [
  18. new Element( 'paragraph', null, 'foo' )
  19. ] )
  20. ] );
  21. r1p1 = root1.getChild( 0 );
  22. r1p2 = root1.getChild( 1 );
  23. r1bQ = root1.getChild( 2 );
  24. r1bQp = r1bQ.getChild( 0 );
  25. root2 = new Element( '$root2' );
  26. } );
  27. describe( 'register()', () => {
  28. it( 'allows registering an item', () => {
  29. schema.register( 'foo' );
  30. expect( schema.getRule( 'foo' ) ).to.be.an( 'object' );
  31. } );
  32. it( 'copies rules', () => {
  33. const rules = {};
  34. schema.register( 'foo', rules );
  35. rules.isBlock = true;
  36. expect( schema.getRules().foo ).to.not.have.property( 'isBlock' );
  37. } );
  38. it( 'throws when trying to register for a single item twice', () => {
  39. schema.register( 'foo' );
  40. expect( () => {
  41. schema.register( 'foo' );
  42. } ).to.throw( CKEditorError, /^schema-cannot-register-item-twice:/ );
  43. } );
  44. } );
  45. describe( 'extend()', () => {
  46. it( 'allows extending item\'s rules', () => {
  47. schema.register( 'foo' );
  48. schema.extend( 'foo', {
  49. isBlock: true
  50. } );
  51. expect( schema.getRule( 'foo' ) ).to.have.property( 'isBlock', true );
  52. } );
  53. it( 'copies rules', () => {
  54. schema.register( 'foo', {} );
  55. const rules = {};
  56. schema.extend( 'foo', rules );
  57. rules.isBlock = true;
  58. expect( schema.getRules().foo ).to.not.have.property( 'isBlock' );
  59. } );
  60. it( 'throws when trying to extend a not yet registered item', () => {
  61. expect( () => {
  62. schema.extend( 'foo' );
  63. } ).to.throw( CKEditorError, /^schema-cannot-extend-missing-item:/ );
  64. } );
  65. } );
  66. describe( 'getRules()', () => {
  67. it( 'returns compiled rules', () => {
  68. schema.register( '$root' );
  69. schema.register( 'foo', {
  70. allowIn: '$root'
  71. } );
  72. schema.extend( 'foo', {
  73. isBlock: true
  74. } );
  75. const rules = schema.getRules();
  76. expect( rules.foo ).to.deep.equal( {
  77. name: 'foo',
  78. allowIn: [ '$root' ],
  79. allowAttributes: [],
  80. isBlock: true
  81. } );
  82. } );
  83. it( 'copies all is* types', () => {
  84. schema.register( 'foo', {
  85. isBlock: true,
  86. isFoo: true
  87. } );
  88. schema.extend( 'foo', {
  89. isBar: true,
  90. isFoo: false // Just to check that the last one wins.
  91. } );
  92. const rules = schema.getRules();
  93. expect( rules.foo ).to.have.property( 'isBlock', true );
  94. expect( rules.foo ).to.have.property( 'isFoo', false );
  95. expect( rules.foo ).to.have.property( 'isBar', true );
  96. } );
  97. it( 'does not recompile rules if not needed', () => {
  98. schema.register( 'foo' );
  99. expect( schema.getRules() ).to.equal( schema.getRules() );
  100. } );
  101. it( 'ensures no duplicates in allowIn', () => {
  102. schema.register( '$root' );
  103. schema.register( 'foo', {
  104. allowIn: '$root'
  105. } );
  106. schema.extend( 'foo', {
  107. allowIn: '$root'
  108. } );
  109. const rules = schema.getRules();
  110. expect( rules.foo ).to.deep.equal( {
  111. name: 'foo',
  112. allowIn: [ '$root' ],
  113. allowAttributes: []
  114. } );
  115. } );
  116. it( 'ensures no unregistered items in allowIn', () => {
  117. schema.register( 'foo', {
  118. allowIn: '$root'
  119. } );
  120. const rules = schema.getRules();
  121. expect( rules.foo ).to.deep.equal( {
  122. name: 'foo',
  123. allowIn: [],
  124. allowAttributes: []
  125. } );
  126. } );
  127. it( 'ensures no duplicates in allowAttributes', () => {
  128. schema.register( 'paragraph', {
  129. allowAttributes: 'foo'
  130. } );
  131. schema.extend( 'paragraph', {
  132. allowAttributes: 'foo'
  133. } );
  134. const rules = schema.getRules();
  135. expect( rules.paragraph ).to.deep.equal( {
  136. name: 'paragraph',
  137. allowIn: [],
  138. allowAttributes: [ 'foo' ]
  139. } );
  140. } );
  141. it( 'ensures no duplicates in allowAttributes duplicated by allowAttributesOf', () => {
  142. schema.register( 'paragraph', {
  143. allowAttributes: 'foo',
  144. allowAttributesOf: '$block'
  145. } );
  146. schema.register( '$block', {
  147. allowAttributes: 'foo'
  148. } );
  149. const rules = schema.getRules();
  150. expect( rules.paragraph ).to.deep.equal( {
  151. name: 'paragraph',
  152. allowIn: [],
  153. allowAttributes: [ 'foo' ]
  154. } );
  155. } );
  156. } );
  157. describe( 'getRule()', () => {
  158. // TODO
  159. } );
  160. describe( 'isRegistered()', () => {
  161. it( 'returns true if an item was registered', () => {
  162. schema.register( 'foo' );
  163. expect( schema.isRegistered( 'foo' ) ).to.be.true;
  164. } );
  165. it( 'returns false if an item was not registered', () => {
  166. expect( schema.isRegistered( 'foo' ) ).to.be.false;
  167. } );
  168. } );
  169. describe( 'isBlock()', () => {
  170. it( 'returns true if an item was registered as a block', () => {
  171. schema.register( 'foo', {
  172. isBlock: true
  173. } );
  174. expect( schema.isBlock( 'foo' ) ).to.be.true;
  175. } );
  176. it( 'returns false if an item was not registered as a block', () => {
  177. schema.register( 'foo' );
  178. expect( schema.isBlock( 'foo' ) ).to.be.false;
  179. } );
  180. it( 'returns false if an item was not registered at all', () => {
  181. expect( schema.isBlock( 'foo' ) ).to.be.false;
  182. } );
  183. } );
  184. describe( 'isLimit()', () => {
  185. it( 'returns true if an item was registered as a limit element', () => {
  186. schema.register( 'foo', {
  187. isLimit: true
  188. } );
  189. expect( schema.isLimit( 'foo' ) ).to.be.true;
  190. } );
  191. it( 'returns false if an item was not registered as a limit element', () => {
  192. schema.register( 'foo' );
  193. expect( schema.isLimit( 'foo' ) ).to.be.false;
  194. } );
  195. it( 'returns false if an item was not registered at all', () => {
  196. expect( schema.isLimit( 'foo' ) ).to.be.false;
  197. } );
  198. } );
  199. describe( 'isObject()', () => {
  200. it( 'returns true if an item was registered as an object', () => {
  201. schema.register( 'foo', {
  202. isObject: true
  203. } );
  204. expect( schema.isObject( 'foo' ) ).to.be.true;
  205. } );
  206. it( 'returns false if an item was not registered as an object', () => {
  207. schema.register( 'foo' );
  208. expect( schema.isObject( 'foo' ) ).to.be.false;
  209. } );
  210. it( 'returns false if an item was not registered at all', () => {
  211. expect( schema.isObject( 'foo' ) ).to.be.false;
  212. } );
  213. } );
  214. describe( 'checkChild()', () => {
  215. beforeEach( () => {
  216. schema.register( '$root' );
  217. schema.register( 'paragraph', {
  218. allowIn: '$root'
  219. } );
  220. schema.register( '$text', {
  221. allowIn: 'paragraph'
  222. } );
  223. } );
  224. it( 'accepts an element as a context and a node name as a child', () => {
  225. expect( schema.checkChild( root1, 'paragraph' ) ).to.be.true;
  226. expect( schema.checkChild( root1, '$text' ) ).to.be.false;
  227. } );
  228. it( 'accepts a position as a context', () => {
  229. const posInRoot = Position.createAt( root1 );
  230. const posInParagraph = Position.createAt( r1p1 );
  231. expect( schema.checkChild( posInRoot, 'paragraph' ) ).to.be.true;
  232. expect( schema.checkChild( posInRoot, '$text' ) ).to.be.false;
  233. expect( schema.checkChild( posInParagraph, '$text' ) ).to.be.true;
  234. expect( schema.checkChild( posInParagraph, 'paragraph' ) ).to.be.false;
  235. } );
  236. // This is a temporary feature which is needed to make the current V->M conversion works.
  237. // It should be removed once V->M conversion uses real positions.
  238. // Of course, real positions have this advantage that we know element attributes at this point.
  239. it( 'accepts an array of element names as a context', () => {
  240. const contextInRoot = [ '$root' ];
  241. const contextInParagraph = [ '$root', 'paragraph' ];
  242. expect( schema.checkChild( contextInRoot, 'paragraph' ) ).to.be.true;
  243. expect( schema.checkChild( contextInRoot, '$text' ) ).to.be.false;
  244. expect( schema.checkChild( contextInParagraph, '$text' ) ).to.be.true;
  245. expect( schema.checkChild( contextInParagraph, 'paragraph' ) ).to.be.false;
  246. } );
  247. it( 'accepts an array of elements as a context', () => {
  248. const contextInRoot = [ root1 ];
  249. const contextInParagraph = [ root1, r1p1 ];
  250. expect( schema.checkChild( contextInRoot, 'paragraph' ) ).to.be.true;
  251. expect( schema.checkChild( contextInRoot, '$text' ) ).to.be.false;
  252. expect( schema.checkChild( contextInParagraph, '$text' ) ).to.be.true;
  253. expect( schema.checkChild( contextInParagraph, 'paragraph' ) ).to.be.false;
  254. } );
  255. // Again, this is needed temporarily to handle current V->M conversion
  256. it( 'accepts a mixed array of elements and strings as a context', () => {
  257. const contextInParagraph = [ '$root', r1p1 ];
  258. expect( schema.checkChild( contextInParagraph, '$text' ) ).to.be.true;
  259. expect( schema.checkChild( contextInParagraph, 'paragraph' ) ).to.be.false;
  260. } );
  261. it( 'accepts a node as a child', () => {
  262. expect( schema.checkChild( root1, r1p1 ) ).to.be.true;
  263. expect( schema.checkChild( root1, new Text( 'foo' ) ) ).to.be.false;
  264. } );
  265. // TODO checks fires event
  266. // TODO checks with a custom context array
  267. } );
  268. describe( 'checkAttribute()', () => {
  269. beforeEach( () => {
  270. schema.register( 'paragraph', {
  271. allowAttributes: 'align'
  272. } );
  273. schema.register( '$text', {
  274. allowAttributes: 'bold'
  275. } );
  276. } );
  277. it( 'accepts an element as a context', () => {
  278. expect( schema.checkAttribute( r1p1, 'align' ) ).to.be.true;
  279. expect( schema.checkAttribute( r1p1, 'bold' ) ).to.be.false;
  280. } );
  281. it( 'accepts a text as a context', () => {
  282. expect( schema.checkAttribute( new Text( 'foo' ), 'bold' ) ).to.be.true;
  283. expect( schema.checkAttribute( new Text( 'foo' ), 'align' ) ).to.be.false;
  284. } );
  285. // TODO checks fires event
  286. // TODO checks with a custom context array
  287. } );
  288. describe( 'rules compilation', () => {
  289. describe( 'allowIn cases', () => {
  290. it( 'passes $root>paragraph', () => {
  291. schema.register( '$root' );
  292. schema.register( 'paragraph', {
  293. allowIn: '$root'
  294. } );
  295. expect( schema.checkChild( root1, r1p1 ) ).to.be.true;
  296. } );
  297. it( 'passes $root>paragraph and $root2>paragraph – support for array values', () => {
  298. schema.register( '$root' );
  299. schema.register( '$root2' );
  300. schema.register( 'paragraph', {
  301. allowIn: [ '$root', '$root2' ]
  302. } );
  303. expect( schema.checkChild( root1, r1p1 ) ).to.be.true;
  304. expect( schema.checkChild( root2, r1p1 ) ).to.be.true;
  305. } );
  306. it( 'passes $root>paragraph[align] – attributes does not matter', () => {
  307. schema.register( '$root' );
  308. schema.register( 'paragraph', {
  309. allowIn: '$root'
  310. } );
  311. expect( schema.checkChild( root1, r1p2 ) ).to.be.true;
  312. } );
  313. it( 'passes $root>div>div – in case of circular refs', () => {
  314. schema.register( '$root' );
  315. schema.register( 'div', {
  316. allowIn: [ '$root', 'div' ]
  317. } );
  318. const div = new Element( 'div' );
  319. root1.appendChildren( div );
  320. const div2 = new Element( 'div' );
  321. expect( schema.checkChild( div, div2 ) ).to.be.true;
  322. } );
  323. it( 'passes $root>div>div – in case of circular refs, when div1==div2', () => {
  324. schema.register( '$root' );
  325. schema.register( 'div', {
  326. allowIn: [ '$root', 'div' ]
  327. } );
  328. const div = new Element( 'div' );
  329. root1.appendChildren( div );
  330. expect( schema.checkChild( div, div ) ).to.be.true;
  331. } );
  332. it( 'rejects $root>paragraph – unregistered paragraph', () => {
  333. schema.register( '$root' );
  334. expect( schema.checkChild( root1, r1p1 ) ).to.be.false;
  335. } );
  336. it( 'rejects $root>paragraph – registered different item', () => {
  337. schema.register( '$root' );
  338. schema.register( 'paragraph' );
  339. schema.register( 'listItem', {
  340. allowIn: '$root'
  341. } );
  342. expect( schema.checkChild( root1, r1p1 ) ).to.be.false;
  343. } );
  344. it( 'rejects $root>paragraph – paragraph allowed in different context', () => {
  345. schema.register( '$root' );
  346. schema.register( '$fancyRoot' );
  347. schema.register( 'paragraph', {
  348. allowIn: '$fancyRoot'
  349. } );
  350. expect( schema.checkChild( root1, r1p1 ) ).to.be.false;
  351. } );
  352. it( 'rejects $root>blockQuote>paragraph – since paragraph is only allowed in $root', () => {
  353. schema.register( '$root' );
  354. schema.register( 'paragraph', {
  355. allowIn: '$root'
  356. } );
  357. expect( schema.checkChild( r1bQ, r1bQp ) ).to.be.false;
  358. } );
  359. it( 'rejects $root>blockQuote>paragraph – since paragraph is only allowed in $root v2', () => {
  360. schema.register( '$root' );
  361. schema.register( 'blockQuote', {
  362. allowIn: '$root'
  363. } );
  364. schema.register( 'paragraph', {
  365. allowIn: '$root'
  366. } );
  367. expect( schema.checkChild( r1bQ, r1bQp ) ).to.be.false;
  368. } );
  369. it( 'rejects $root>blockQuote>paragraph>$text - since paragraph is not allowed in blockQuote', () => {
  370. schema.register( '$root' );
  371. schema.register( 'paragraph', {
  372. allowIn: '$root'
  373. } );
  374. schema.register( '$text', {
  375. allowIn: 'paragraph'
  376. } );
  377. expect( schema.checkChild( root1, r1bQp.getChild( 0 ) ) ).to.be.false;
  378. } );
  379. it( 'rejects $root>blockQuote>paragraph>$text - since blockQuote is not allowed in $root', () => {
  380. schema.register( '$root' );
  381. schema.register( 'blockQuote' );
  382. schema.register( 'paragraph', {
  383. allowIn: [ 'blockQuote', '$root' ]
  384. } );
  385. schema.register( '$text', {
  386. allowIn: 'paragraph'
  387. } );
  388. expect( schema.checkChild( root1, r1bQp.getChild( 0 ) ) ).to.be.false;
  389. } );
  390. } );
  391. describe( 'allowWhere cases', () => {
  392. it( 'passes $root>paragraph – paragraph inherits from $block', () => {
  393. schema.register( '$root' );
  394. schema.register( '$block', {
  395. allowIn: '$root'
  396. } );
  397. schema.register( 'paragraph', {
  398. allowWhere: '$block'
  399. } );
  400. expect( schema.checkChild( root1, r1p1 ) ).to.be.true;
  401. } );
  402. it( 'supports the array syntax', () => {
  403. schema.register( '$root' );
  404. schema.register( '$root2' );
  405. schema.register( '$block', {
  406. allowIn: '$root'
  407. } );
  408. schema.register( '$block2', {
  409. allowIn: '$root2'
  410. } );
  411. schema.register( 'paragraph', {
  412. allowWhere: [ '$block', '$block2' ]
  413. } );
  414. expect( schema.checkChild( root1, r1p1 ), '$root' ).to.be.true;
  415. expect( schema.checkChild( root2, r1p1 ), '$root2' ).to.be.true;
  416. } );
  417. // This checks if some inapropriate caching or preprocessing isn't applied by register().
  418. it( 'passes $root>paragraph – paragraph inherits from $block, order of rules does not matter', () => {
  419. schema.register( '$root' );
  420. schema.register( 'paragraph', {
  421. allowWhere: '$block'
  422. } );
  423. schema.register( '$block', {
  424. allowIn: '$root'
  425. } );
  426. expect( schema.checkChild( root1, r1p1 ) ).to.be.true;
  427. } );
  428. it( 'passes $root>paragraph – paragraph inherits from $specialBlock which inherits from $block', () => {
  429. schema.register( '$root' );
  430. schema.register( '$block', {
  431. allowIn: '$root'
  432. } );
  433. schema.register( '$specialBlock', {
  434. allowWhere: '$block'
  435. } );
  436. schema.register( 'paragraph', {
  437. allowWhere: '$specialBlock'
  438. } );
  439. expect( schema.checkChild( root1, r1p1 ) ).to.be.true;
  440. } );
  441. it( 'rejects $root>paragraph – paragraph inherits from $block but $block is not allowed in $root', () => {
  442. schema.register( '$root' );
  443. schema.register( '$block' );
  444. schema.register( 'paragraph', {
  445. allowWhere: '$block'
  446. } );
  447. expect( schema.checkChild( root1, r1p1 ) ).to.be.false;
  448. } );
  449. it( 'rejects $root>paragraph>$text – paragraph inherits from $block but $block is not allowed in $root', () => {
  450. schema.register( '$root' );
  451. schema.register( '$block' );
  452. schema.register( 'paragraph', {
  453. allowWhere: '$block'
  454. } );
  455. schema.register( '$text', {
  456. allowIn: 'paragraph'
  457. } );
  458. expect( schema.checkChild( root1, r1p1.getChild( 0 ) ) ).to.be.false;
  459. } );
  460. } );
  461. describe( 'allowContentOf cases', () => {
  462. it( 'passes $root2>paragraph – $root2 inherits from $root', () => {
  463. schema.register( '$root' );
  464. schema.register( 'paragraph', {
  465. allowIn: '$root'
  466. } );
  467. schema.register( '$root2', {
  468. allowContentOf: '$root'
  469. } );
  470. expect( schema.checkChild( root2, r1p1 ) ).to.be.true;
  471. } );
  472. it( 'supports the array syntax', () => {
  473. schema.register( '$root' );
  474. schema.register( '$root2' );
  475. schema.register( 'paragraph', {
  476. allowIn: '$root'
  477. } );
  478. schema.register( 'heading1', {
  479. allowIn: '$root2'
  480. } );
  481. schema.register( '$root3', {
  482. allowContentOf: [ '$root', '$root2' ]
  483. } );
  484. const root3 = new Element( '$root3' );
  485. const heading1 = new Element( 'heading1' );
  486. expect( schema.checkChild( root3, r1p1 ), 'paragraph' ).to.be.true;
  487. expect( schema.checkChild( root3, heading1 ), 'heading1' ).to.be.true;
  488. } );
  489. it( 'passes $root2>paragraph – $root2 inherits from $root, order of rules does not matter', () => {
  490. schema.register( '$root' );
  491. schema.register( '$root2', {
  492. allowContentOf: '$root'
  493. } );
  494. schema.register( 'paragraph', {
  495. allowIn: '$root'
  496. } );
  497. expect( schema.checkChild( root2, r1p1 ) ).to.be.true;
  498. } );
  499. it( 'passes $root>paragraph>$text – paragraph inherits content of $block', () => {
  500. schema.register( '$root' );
  501. schema.register( '$block' );
  502. schema.register( 'paragraph', {
  503. allowIn: '$root',
  504. allowContentOf: '$block'
  505. } );
  506. schema.register( '$text', {
  507. allowIn: '$block'
  508. } );
  509. expect( schema.checkChild( r1p1, r1p1.getChild( 0 ) ) ).to.be.true;
  510. } );
  511. // TODO we need to make it possible to disallow bQ in bQ.
  512. it( 'passes $root>blockQuote>paragraph – blockQuote inherits content of $root', () => {
  513. schema.register( '$root' );
  514. schema.register( 'blockQuote', {
  515. allowIn: '$root',
  516. allowContentOf: '$root'
  517. } );
  518. schema.register( 'paragraph', {
  519. allowIn: '$root'
  520. } );
  521. expect( schema.checkChild( r1bQ, r1bQp ) ).to.be.true;
  522. } );
  523. it( 'rejects $root2>paragraph – $root2 inherits from $root, but paragraph is not allowed there anyway', () => {
  524. schema.register( '$root' );
  525. schema.register( 'paragraph' );
  526. schema.register( '$root2', {
  527. allowContentOf: '$root'
  528. } );
  529. expect( schema.checkChild( root2, r1p1 ) ).to.be.false;
  530. } );
  531. } );
  532. describe( 'mix of allowContentOf and allowWhere', () => {
  533. it( 'passes $root>paragraph>$text – paragraph inherits all from $block', () => {
  534. schema.register( '$root' );
  535. schema.register( '$block', {
  536. allowIn: '$root'
  537. } );
  538. schema.register( 'paragraph', {
  539. allowContentOf: '$block',
  540. allowWhere: '$block'
  541. } );
  542. schema.register( '$text', {
  543. allowIn: '$block'
  544. } );
  545. expect( schema.checkChild( r1p1, r1p1.getChild( 0 ) ) ).to.be.true;
  546. } );
  547. it( 'passes $root>paragraph and $root2>paragraph – where $root2 inherits content of $root' +
  548. 'and paragraph inherits allowWhere from $block', () => {
  549. schema.register( '$root' );
  550. schema.register( '$root2', {
  551. allowContentOf: '$root'
  552. } );
  553. schema.register( '$block', {
  554. allowIn: '$root'
  555. } );
  556. schema.register( 'paragraph', {
  557. allowWhere: '$block'
  558. } );
  559. expect( schema.checkChild( root1, 'paragraph' ), 'root1' ).to.be.true;
  560. expect( schema.checkChild( root2, 'paragraph' ), 'root2' ).to.be.true;
  561. } );
  562. it( 'passes d>a where d inherits content of c which inherits content of b', () => {
  563. schema.register( 'b' );
  564. schema.register( 'a', { allowIn: 'b' } );
  565. schema.register( 'c', { allowContentOf: 'b' } );
  566. schema.register( 'd', { allowContentOf: 'c' } );
  567. const d = new Element( 'd' );
  568. expect( schema.checkChild( d, 'a' ) ).to.be.true;
  569. } );
  570. // This case won't pass becuase we compile the rules in a pretty naive way.
  571. // To make chains like this work we'd need to repeat compilation of allowContentOf rules
  572. // as long as the previous iteration found something to compile.
  573. // This way, even though we'd not compile d<-c in the first run, we'd still find b<-c
  574. // and since we've found something, we'd now try d<-c which would work.
  575. //
  576. // We ignore those situations for now as they are very unlikely to happen and would
  577. // significantly raised the complexity of rule compilation.
  578. //
  579. // it( 'passes d>a where d inherits content of c which inherits content of b', () => {
  580. // schema.register( 'b' );
  581. // schema.register( 'a', { allowIn: 'b' } );
  582. // schema.register( 'd', { allowContentOf: 'c' } );
  583. // schema.register( 'c', { allowContentOf: 'b' } );
  584. //
  585. // const d = new Element( 'd' );
  586. //
  587. // expect( schema.checkChild( d, 'a' ) ).to.be.true;
  588. // } );
  589. } );
  590. describe( 'inheritAllFrom', () => {
  591. it( 'passes $root>paragraph – paragraph inherits allowIn from $block', () => {
  592. schema.register( '$root' );
  593. schema.register( '$block', {
  594. allowIn: '$root'
  595. } );
  596. schema.register( 'paragraph', {
  597. inheritAllFrom: '$block'
  598. } );
  599. expect( schema.checkChild( root1, r1p1 ) ).to.be.true;
  600. } );
  601. it( 'passes $root>paragraph>$text – paragraph inherits allowed content of $block', () => {
  602. schema.register( '$root' );
  603. schema.register( '$block', {
  604. allowIn: '$root'
  605. } );
  606. schema.register( '$text', {
  607. allowIn: '$block'
  608. } );
  609. schema.register( 'paragraph', {
  610. inheritAllFrom: '$block'
  611. } );
  612. expect( schema.checkChild( r1p1, r1p1.getChild( 0 ) ) ).to.be.true;
  613. } );
  614. it( 'passes $root>paragraph>$text – paragraph inherits allowIn from $block through $block\'s allowWhere', () => {
  615. schema.register( '$root' );
  616. schema.register( '$blockProto', {
  617. allowIn: '$root'
  618. } );
  619. schema.register( '$block', {
  620. allowWhere: '$blockProto'
  621. } );
  622. schema.register( 'paragraph', {
  623. inheritAllFrom: '$block'
  624. } );
  625. expect( schema.checkChild( root1, r1p1 ) ).to.be.true;
  626. } );
  627. it( 'passes $root>paragraph>$text – paragraph inherits allowIn from $block through $block\'s allowWhere', () => {
  628. schema.register( '$root' );
  629. schema.register( '$blockProto' );
  630. schema.register( '$block', {
  631. allowContentOf: '$blockProto',
  632. allowIn: '$root'
  633. } );
  634. schema.register( '$text', {
  635. allowIn: '$blockProto'
  636. } );
  637. schema.register( 'paragraph', {
  638. inheritAllFrom: '$block'
  639. } );
  640. expect( schema.checkChild( r1p1, r1p1.getChild( 0 ) ) ).to.be.true;
  641. } );
  642. } );
  643. // We need to handle cases where some independent features registered rules which might use
  644. // optional elements (elements which might not have been registered).
  645. describe( 'missing structure rules', () => {
  646. it( 'does not break when trying to check a child which is not registered', () => {
  647. schema.register( '$root' );
  648. expect( schema.checkChild( root1, 'foo404' ) ).to.be.false;
  649. } );
  650. it( 'does not break when trying to check registered child in a context which contains unregistered elements', () => {
  651. const foo404 = new Element( 'foo404' );
  652. root1.appendChildren( foo404 );
  653. schema.register( '$root' );
  654. schema.register( '$text', {
  655. allowIn: '$root'
  656. } );
  657. expect( schema.checkChild( foo404, '$text' ) ).to.be.false;
  658. } );
  659. it( 'does not break when used allowedIn pointing to an unregistered element', () => {
  660. schema.register( '$root' );
  661. schema.register( '$text', {
  662. allowIn: 'foo404'
  663. } );
  664. expect( schema.checkChild( root1, '$text' ) ).to.be.false;
  665. } );
  666. it( 'does not break when used allowWhere pointing to an unregistered element', () => {
  667. schema.register( '$root' );
  668. schema.register( '$text', {
  669. allowWhere: 'foo404'
  670. } );
  671. expect( schema.checkChild( root1, '$text' ) ).to.be.false;
  672. } );
  673. it( 'does not break when used allowContentOf pointing to an unregistered element', () => {
  674. schema.register( '$root', {
  675. allowContentOf: 'foo404'
  676. } );
  677. schema.register( '$text', {
  678. allowIn: '$root'
  679. } );
  680. expect( schema.checkChild( root1, '$text' ) ).to.be.true;
  681. } );
  682. it( 'checks whether allowIn uses a registered element', () => {
  683. schema.register( 'paragraph', {
  684. allowIn: '$root'
  685. } );
  686. // $root isn't registered!
  687. expect( schema.checkChild( root1, 'paragraph' ) ).to.be.false;
  688. } );
  689. it( 'does not break when inheriting all from an unregistered element', () => {
  690. schema.register( 'paragraph', {
  691. inheritAllFrom: '$block'
  692. } );
  693. expect( schema.checkChild( root1, r1p1 ) ).to.be.false;
  694. } );
  695. } );
  696. describe( 'allowAttributes', () => {
  697. it( 'passes paragraph[align]', () => {
  698. schema.register( 'paragraph', {
  699. allowAttributes: 'align'
  700. } );
  701. expect( schema.checkAttribute( r1p1, 'align' ) ).to.be.true;
  702. } );
  703. it( 'passes paragraph[align] and paragraph[dir] – support for array values', () => {
  704. schema.register( 'paragraph', {
  705. allowAttributes: [ 'align', 'dir' ]
  706. } );
  707. expect( schema.checkAttribute( r1p1, 'align' ), 'align' ).to.be.true;
  708. expect( schema.checkAttribute( r1p1, 'dir' ), 'dir' ).to.be.true;
  709. } );
  710. it( 'passes paragraph>$text[bold]', () => {
  711. schema.register( 'paragraph' );
  712. schema.register( '$text', {
  713. allowIn: 'paragraph',
  714. allowAttributes: 'bold'
  715. } );
  716. expect( schema.checkAttribute( r1p1.getChild( 0 ), 'bold' ) ).to.be.true;
  717. } );
  718. } );
  719. describe( 'allowAttributesOf', () => {
  720. it( 'passes paragraph[align] – paragraph inherits from $block', () => {
  721. schema.register( '$block', {
  722. allowAttributes: 'align'
  723. } );
  724. schema.register( 'paragraph', {
  725. allowAttributesOf: '$block'
  726. } );
  727. expect( schema.checkAttribute( r1p1, 'align' ) ).to.be.true;
  728. } );
  729. it( 'passes paragraph[align] and paragraph[dir] – support for array values', () => {
  730. schema.register( '$block', {
  731. allowAttributes: 'align'
  732. } );
  733. schema.register( '$block2', {
  734. allowAttributes: 'dir'
  735. } );
  736. schema.register( 'paragraph', {
  737. allowAttributesOf: [ '$block', '$block2' ]
  738. } );
  739. expect( schema.checkAttribute( r1p1, 'align' ), 'align' ).to.be.true;
  740. expect( schema.checkAttribute( r1p1, 'dir' ), 'dir' ).to.be.true;
  741. } );
  742. it( 'passes paragraph[align] and paragraph[dir] – support for combined allowAttributes and allowAttributesOf', () => {
  743. schema.register( '$block', {
  744. allowAttributes: 'align'
  745. } );
  746. schema.register( 'paragraph', {
  747. allowAttributes: 'dir',
  748. allowAttributesOf: '$block'
  749. } );
  750. expect( schema.checkAttribute( r1p1, 'align' ), 'align' ).to.be.true;
  751. expect( schema.checkAttribute( r1p1, 'dir' ), 'dir' ).to.be.true;
  752. } );
  753. // The support for allowAttributesOf is broken in the similar way as for allowContentOf (see the comment above).
  754. // However, those situations are rather theoretical, so we're not going to waste time on them now.
  755. } );
  756. describe( 'inheritAllFrom', () => {
  757. it( 'passes paragraph[align] – paragraph inherits attributes of $block', () => {
  758. schema.register( '$block', {
  759. allowAttributes: 'align'
  760. } );
  761. schema.register( 'paragraph', {
  762. inheritAllFrom: '$block'
  763. } );
  764. expect( schema.checkAttribute( r1p1, 'align' ) ).to.be.true;
  765. } );
  766. it( 'passes paragraph[align] – paragraph inherits attributes of $block through allowAttributesOf', () => {
  767. schema.register( '$blockProto', {
  768. allowAttributes: 'align'
  769. } );
  770. schema.register( '$block', {
  771. allowAttributesOf: '$blockProto'
  772. } );
  773. schema.register( 'paragraph', {
  774. inheritAllFrom: '$block'
  775. } );
  776. expect( schema.checkAttribute( r1p1, 'align' ) ).to.be.true;
  777. } );
  778. } );
  779. describe( 'missing attribute rules', () => {
  780. it( 'does not crash when checking an attribute of a unregistered element', () => {
  781. expect( schema.checkAttribute( r1p1, 'align' ) ).to.be.false;
  782. } );
  783. it( 'does not crash when inheriting attributes of a unregistered element', () => {
  784. schema.register( 'paragraph', {
  785. allowAttributesOf: '$block'
  786. } );
  787. expect( schema.checkAttribute( r1p1, 'whatever' ) ).to.be.false;
  788. } );
  789. it( 'does not crash when inheriting all from a unregistered element', () => {
  790. schema.register( 'paragraph', {
  791. allowAttributesOf: '$block'
  792. } );
  793. expect( schema.checkAttribute( r1p1, 'whatever' ) ).to.be.false;
  794. } );
  795. } );
  796. } );
  797. describe( 'real scenarios', () => {
  798. let r1bQi, r1i, r1lI, r1h, r1bQlI;
  799. const rules = [
  800. () => {
  801. schema.register( 'paragraph', {
  802. allowWhere: '$block',
  803. allowContentOf: '$block',
  804. allowAttributesOf: '$block'
  805. } );
  806. },
  807. () => {
  808. schema.register( 'heading1', {
  809. allowWhere: '$block',
  810. allowContentOf: '$block',
  811. allowAttributesOf: '$block'
  812. } );
  813. },
  814. () => {
  815. schema.register( 'listItem', {
  816. allowWhere: '$block',
  817. allowContentOf: '$block',
  818. allowAttributes: [ 'indent', 'type' ],
  819. allowAttributesOf: '$block'
  820. } );
  821. },
  822. () => {
  823. schema.register( 'blockQuote', {
  824. allowWhere: '$block',
  825. allowContentOf: '$root'
  826. } );
  827. // Disallow blockQuote in blockQuote.
  828. schema.on( 'checkChild', ( evt, args ) => {
  829. const context = args[ 0 ];
  830. const child = args[ 1 ];
  831. const childRule = schema.getRule( child );
  832. if ( childRule.name == 'blockQuote' && context[ context.length - 1 ].name == 'blockQuote' ) {
  833. evt.stop();
  834. evt.return = false;
  835. }
  836. }, { priority: 'high' } );
  837. },
  838. () => {
  839. schema.register( 'image', {
  840. allowWhere: '$block',
  841. allowAttributes: [ 'src', 'alt' ]
  842. } );
  843. },
  844. () => {
  845. schema.register( 'caption', {
  846. allowIn: 'image',
  847. allowContentOf: '$block'
  848. } );
  849. },
  850. () => {
  851. schema.extend( '$text', {
  852. allowAttributes: [ 'bold', 'italic' ]
  853. } );
  854. // Disallow bold in heading1.
  855. schema.on( 'checkAttribute', ( evt, args ) => {
  856. const context = args[ 0 ];
  857. const contextLast = context[ context.length - 1 ];
  858. const contextSecondToLast = context[ context.length - 2 ];
  859. const attributeName = args[ 1 ];
  860. if ( contextLast.name == '$text' && contextSecondToLast.name == 'heading1' && attributeName == 'bold' ) {
  861. evt.stop();
  862. evt.return = false;
  863. }
  864. }, { priority: 'high' } );
  865. },
  866. () => {
  867. schema.extend( '$block', {
  868. allowAttributes: 'alignment'
  869. } );
  870. }
  871. ];
  872. beforeEach( () => {
  873. schema.register( '$root' );
  874. schema.register( '$block', {
  875. allowIn: '$root'
  876. } );
  877. schema.register( '$text', {
  878. allowIn: '$block'
  879. } );
  880. for ( const rule of rules ) {
  881. rule();
  882. }
  883. // or...
  884. //
  885. // Use the below code to shuffle the rules.
  886. // Don't look here, Szymon!
  887. //
  888. // const rulesCopy = rules.slice();
  889. //
  890. // while ( rulesCopy.length ) {
  891. // const r = Math.floor( Math.random() * rulesCopy.length );
  892. // rulesCopy.splice( r, 1 )[ 0 ]();
  893. // }
  894. root1 = new Element( '$root', null, [
  895. new Element( 'paragraph', null, 'foo' ),
  896. new Element( 'paragraph', { alignment: 'right' }, 'bar' ),
  897. new Element( 'listItem', { type: 'x', indent: 0 }, 'foo' ),
  898. new Element( 'heading1', null, 'foo' ),
  899. new Element( 'blockQuote', null, [
  900. new Element( 'paragraph', null, 'foo' ),
  901. new Element( 'listItem', { type: 'x', indent: 0 }, 'foo' ),
  902. new Element( 'image', null, [
  903. new Element( 'caption', null, 'foo' )
  904. ] )
  905. ] ),
  906. new Element( 'image', null, [
  907. new Element( 'caption', null, 'foo' )
  908. ] )
  909. ] );
  910. r1p1 = root1.getChild( 0 );
  911. r1p2 = root1.getChild( 1 );
  912. r1lI = root1.getChild( 2 );
  913. r1h = root1.getChild( 3 );
  914. r1bQ = root1.getChild( 4 );
  915. r1i = root1.getChild( 5 );
  916. r1bQp = r1bQ.getChild( 0 );
  917. r1bQlI = r1bQ.getChild( 1 );
  918. r1bQi = r1bQ.getChild( 2 );
  919. } );
  920. it( 'passes $root>paragraph', () => {
  921. expect( schema.checkChild( root1, 'paragraph' ) ).to.be.true;
  922. } );
  923. it( 'passes $root>paragraph>$text', () => {
  924. expect( schema.checkChild( r1p1, '$text' ), 'paragraph' ).to.be.true;
  925. expect( schema.checkChild( r1p2, '$text' ), 'paragraph[alignment]' ).to.be.true;
  926. } );
  927. it( 'passes $root>listItem', () => {
  928. expect( schema.checkChild( root1, 'listItem' ) ).to.be.true;
  929. } );
  930. it( 'passes $root>listItem>$text', () => {
  931. expect( schema.checkChild( r1lI, '$text' ) ).to.be.true;
  932. } );
  933. it( 'passes $root>blockQuote>paragraph', () => {
  934. expect( schema.checkChild( r1bQ, 'paragraph' ) ).to.be.true;
  935. } );
  936. it( 'passes $root>blockQuote>paragraph>$text', () => {
  937. expect( schema.checkChild( r1bQp, '$text' ) ).to.be.true;
  938. } );
  939. it( 'passes $root>blockQuote>listItem', () => {
  940. expect( schema.checkChild( r1bQ, 'listItem' ) ).to.be.true;
  941. } );
  942. it( 'passes $root>blockQuote>listItem>$text', () => {
  943. expect( schema.checkChild( r1bQlI, '$text' ) ).to.be.true;
  944. } );
  945. it( 'passes $root>blockQuote>image', () => {
  946. expect( schema.checkChild( r1bQ, 'image' ) ).to.be.true;
  947. } );
  948. it( 'passes $root>blockQuote>image>caption', () => {
  949. expect( schema.checkChild( r1bQi, 'caption' ) ).to.be.true;
  950. } );
  951. it( 'passes $root>blockQuote>image>caption>$text', () => {
  952. expect( schema.checkChild( r1bQi.getChild( 0 ), '$text' ) ).to.be.true;
  953. } );
  954. it( 'passes $root>image', () => {
  955. expect( schema.checkChild( root1, 'image' ) ).to.be.true;
  956. } );
  957. it( 'passes $root>image>caption', () => {
  958. expect( schema.checkChild( r1i, 'caption' ) ).to.be.true;
  959. } );
  960. it( 'passes $root>image>caption>$text', () => {
  961. expect( schema.checkChild( r1i.getChild( 0 ), '$text' ) ).to.be.true;
  962. } );
  963. it( 'rejects $root>$root', () => {
  964. expect( schema.checkChild( root1, '$root' ) ).to.be.false;
  965. } );
  966. it( 'rejects $root>$text', () => {
  967. expect( schema.checkChild( root1, '$text' ) ).to.be.false;
  968. } );
  969. it( 'rejects $root>caption', () => {
  970. expect( schema.checkChild( root1, 'caption' ) ).to.be.false;
  971. } );
  972. it( 'rejects $root>paragraph>paragraph', () => {
  973. expect( schema.checkChild( r1p1, 'paragraph' ) ).to.be.false;
  974. } );
  975. it( 'rejects $root>paragraph>paragraph>$text', () => {
  976. // Edge case because p>p should not exist in the first place.
  977. // But it's good to know that it blocks also this.
  978. const p = new Element( 'p' );
  979. r1p1.appendChildren( p );
  980. expect( schema.checkChild( p, '$text' ) ).to.be.false;
  981. } );
  982. it( 'rejects $root>paragraph>$block', () => {
  983. expect( schema.checkChild( r1p1, '$block' ) ).to.be.false;
  984. } );
  985. it( 'rejects $root>paragraph>blockQuote', () => {
  986. expect( schema.checkChild( r1p1, 'blockQuote' ) ).to.be.false;
  987. } );
  988. it( 'rejects $root>paragraph>image', () => {
  989. expect( schema.checkChild( r1p1, 'image' ) ).to.be.false;
  990. } );
  991. it( 'rejects $root>paragraph>caption', () => {
  992. expect( schema.checkChild( r1p1, 'caption' ) ).to.be.false;
  993. } );
  994. it( 'rejects $root>blockQuote>blockQuote', () => {
  995. expect( schema.checkChild( r1bQ, 'blockQuote' ) ).to.be.false;
  996. } );
  997. it( 'rejects $root>blockQuote>caption', () => {
  998. expect( schema.checkChild( r1p1, 'image' ) ).to.be.false;
  999. } );
  1000. it( 'rejects $root>blockQuote>$text', () => {
  1001. expect( schema.checkChild( r1bQ, '$text' ) ).to.be.false;
  1002. } );
  1003. it( 'rejects $root>image>$text', () => {
  1004. expect( schema.checkChild( r1i, '$text' ) ).to.be.false;
  1005. } );
  1006. it( 'rejects $root>image>paragraph', () => {
  1007. expect( schema.checkChild( r1i, 'paragraph' ) ).to.be.false;
  1008. } );
  1009. it( 'rejects $root>image>caption>paragraph', () => {
  1010. expect( schema.checkChild( r1i.getChild( 0 ), 'paragraph' ) ).to.be.false;
  1011. } );
  1012. it( 'rejects $root>image>caption>blockQuote', () => {
  1013. expect( schema.checkChild( r1i.getChild( 0 ), 'blockQuote' ) ).to.be.false;
  1014. } );
  1015. it( 'accepts attribute $root>paragraph[alignment]', () => {
  1016. expect( schema.checkAttribute( r1p1, 'alignment' ) ).to.be.true;
  1017. } );
  1018. it( 'accepts attribute $root>paragraph>$text[bold]', () => {
  1019. expect( schema.checkAttribute( r1p1.getChild( 0 ), 'bold' ) ).to.be.true;
  1020. } );
  1021. it( 'accepts attribute $root>heading1>$text[italic]', () => {
  1022. expect( schema.checkAttribute( r1h.getChild( 0 ), 'italic' ) ).to.be.true;
  1023. } );
  1024. it( 'accepts attribute $root>blockQuote>paragraph>$text[bold]', () => {
  1025. expect( schema.checkAttribute( r1bQp.getChild( 0 ), 'bold' ) ).to.be.true;
  1026. } );
  1027. it( 'accepts attribute $root>listItem[alignment]', () => {
  1028. expect( schema.checkAttribute( r1lI, 'alignment' ) ).to.be.true;
  1029. } );
  1030. it( 'accepts attribute $root>listItem[indent]', () => {
  1031. expect( schema.checkAttribute( r1lI, 'indent' ) ).to.be.true;
  1032. } );
  1033. it( 'accepts attribute $root>listItem[type]', () => {
  1034. expect( schema.checkAttribute( r1lI, 'type' ) ).to.be.true;
  1035. } );
  1036. it( 'accepts attribute $root>image[src]', () => {
  1037. expect( schema.checkAttribute( r1i, 'src' ) ).to.be.true;
  1038. } );
  1039. it( 'accepts attribute $root>image[alt]', () => {
  1040. expect( schema.checkAttribute( r1i, 'alt' ) ).to.be.true;
  1041. } );
  1042. it( 'accepts attribute $root>image>caption>$text[bold]', () => {
  1043. expect( schema.checkAttribute( r1i.getChild( 0 ).getChild( 0 ), 'bold' ) ).to.be.true;
  1044. } );
  1045. it( 'rejects attribute $root[indent]', () => {
  1046. expect( schema.checkAttribute( root1, 'indent' ) ).to.be.false;
  1047. } );
  1048. it( 'rejects attribute $root>paragraph[indent]', () => {
  1049. expect( schema.checkAttribute( r1p1, 'indent' ) ).to.be.false;
  1050. } );
  1051. it( 'accepts attribute $root>heading1>$text[bold]', () => {
  1052. expect( schema.checkAttribute( r1h.getChild( 0 ), 'bold' ) ).to.be.false;
  1053. } );
  1054. it( 'rejects attribute $root>paragraph>$text[alignment]', () => {
  1055. expect( schema.checkAttribute( r1p1.getChild( 0 ), 'alignment' ) ).to.be.false;
  1056. } );
  1057. it( 'rejects attribute $root>blockQuote[indent]', () => {
  1058. expect( schema.checkAttribute( r1bQ, 'indent' ) ).to.be.false;
  1059. } );
  1060. it( 'rejects attribute $root>blockQuote[alignment]', () => {
  1061. expect( schema.checkAttribute( r1bQ, 'alignment' ) ).to.be.false;
  1062. } );
  1063. it( 'rejects attribute $root>image[indent]', () => {
  1064. expect( schema.checkAttribute( r1i, 'indent' ) ).to.be.false;
  1065. } );
  1066. it( 'rejects attribute $root>image[alignment]', () => {
  1067. expect( schema.checkAttribute( r1i, 'alignment' ) ).to.be.false;
  1068. } );
  1069. } );
  1070. // TODO:
  1071. // * getValidRanges
  1072. // * checkAttributeInSelection
  1073. // * getLimitElement
  1074. // * removeDisallowedAttributes
  1075. // * test checkChild()'s both params normalization
  1076. // * and see insertContent's _checkIsObject()
  1077. // * add normalization to isObject(), isLimit(), isBlock(), isRegistered() and improve the existing code
  1078. // * inheritAllFrom should also inherit is* props (see tests documentselection getNearestSelectionRange())
  1079. // * test the default abstract entities (in model.js)
  1080. // * see clipboardHolder definition (and rename it to the pastebin)
  1081. // * review insertContent's _tryAutoparagraphing()
  1082. } );