Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like SearchBaseIntegrationTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SearchBaseIntegrationTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 103 | abstract class SearchBaseIntegrationTest extends BaseIntegrationTest |
||
| 104 | { |
||
| 105 | /** |
||
| 106 | * Get search field value One. |
||
| 107 | * |
||
| 108 | * The value must be valid for Content creation. |
||
| 109 | * |
||
| 110 | * When Field sort clause with ascending order is used on the tested field, |
||
| 111 | * Content containing the field with this value must come before the Content |
||
| 112 | * with value One. |
||
| 113 | * |
||
| 114 | * Opposite should be the case when using descending order. |
||
| 115 | * |
||
| 116 | * @return mixed |
||
| 117 | */ |
||
| 118 | abstract protected function getValidSearchValueOne(); |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Get search target field value One. |
||
| 122 | * |
||
| 123 | * Returns the Field criterion target value for the field value One. |
||
| 124 | * Default implementation falls back on {@link getValidSearchValueOne}. |
||
| 125 | * |
||
| 126 | * @return mixed |
||
| 127 | */ |
||
| 128 | protected function getSearchTargetValueOne() |
||
| 129 | { |
||
| 130 | return $this->getValidSearchValueOne(); |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Get search field value Two. |
||
| 135 | * |
||
| 136 | * The value must be valid for Content creation. |
||
| 137 | * |
||
| 138 | * When Field sort clause with ascending order is used on the tested field, |
||
| 139 | * Content containing the field with this value must come after the Content |
||
| 140 | * with value One. |
||
| 141 | * |
||
| 142 | * Opposite should be the case when using descending order. |
||
| 143 | * |
||
| 144 | * @return mixed |
||
| 145 | */ |
||
| 146 | abstract protected function getValidSearchValueTwo(); |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Get search target field value Two. |
||
| 150 | * |
||
| 151 | * Returns the Field criterion target value for the field value Two. |
||
| 152 | * Default implementation falls back on {@link getValidSearchValueTwo}. |
||
| 153 | * |
||
| 154 | * @return mixed |
||
| 155 | */ |
||
| 156 | protected function getSearchTargetValueTwo() |
||
| 157 | { |
||
| 158 | return $this->getValidSearchValueTwo(); |
||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Returns test data for field type's additionally indexed fields. |
||
| 163 | * |
||
| 164 | * An array of field data is returned for each additionally indexed field, |
||
| 165 | * consisting of field's name, as defined in field type's Indexable |
||
| 166 | * definition, value One, and value Two, corresponding to the data indexed |
||
| 167 | * by {@link getValidSearchValueOne()} and {@link getValidSearchValueTwo()} |
||
| 168 | * methods. For example: |
||
| 169 | * |
||
| 170 | * <code> |
||
| 171 | * array( |
||
| 172 | * array( |
||
| 173 | * 'file_size', |
||
| 174 | * 1024, |
||
| 175 | * 4096 |
||
| 176 | * ), |
||
| 177 | * ... |
||
| 178 | * ) |
||
| 179 | * </code> |
||
| 180 | * |
||
| 181 | * @return array |
||
| 182 | */ |
||
| 183 | protected function getAdditionallyIndexedFieldData() |
||
| 184 | { |
||
| 185 | return []; |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Returns tests data for full text search. |
||
| 190 | * |
||
| 191 | * An array of search values is returned, consisting of search strings for |
||
| 192 | * value One and value Two, corresponding to the data the field type indexes |
||
| 193 | * for full text search from what is provided by {@link getValidSearchValueOne()} |
||
| 194 | * and {@link getValidSearchValueTwo()}. By default the tests are skipped here, |
||
| 195 | * override in the concrete test case as required by the field type. |
||
| 196 | * For example: |
||
| 197 | * |
||
| 198 | * <code> |
||
| 199 | * array( |
||
| 200 | * array( |
||
| 201 | * 'one', |
||
| 202 | * 'two' |
||
| 203 | * ), |
||
| 204 | * ... |
||
| 205 | * ) |
||
| 206 | * </code> |
||
| 207 | * |
||
| 208 | * @return array |
||
| 209 | */ |
||
| 210 | protected function getFullTextIndexedFieldData() |
||
| 211 | { |
||
| 212 | $this->markTestSkipped( |
||
| 213 | 'Skipped by default, override in the concrete test case as required by the field type.' |
||
| 214 | ); |
||
| 215 | } |
||
| 216 | |||
| 217 | public function checkFullTextSupport() |
||
| 218 | { |
||
| 219 | // Does nothing by default, override in a concrete test case as needed |
||
| 220 | } |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Overload for field types that does not support wildcards in LIKE Field criteria. |
||
| 224 | * |
||
| 225 | * E.g. Any field type that needs to be matched as a whole: Email, bool, date/time, (singular) relation, integer. |
||
| 226 | * |
||
| 227 | * @param mixed $value |
||
| 228 | * |
||
| 229 | * @return bool |
||
| 230 | */ |
||
| 231 | protected function supportsLikeWildcard($value) |
||
| 232 | { |
||
| 233 | return !is_numeric($value) && !is_bool($value); |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Used to control test execution by search engine. |
||
| 238 | * |
||
| 239 | * WARNING: Using this will block testing on a given search engine for FieldType, if partial limited on LegacySE use: |
||
| 240 | * checkCustomFieldsSupport(), checkFullTextSupport(), supportsLikeWildcard(), $legacyUnsupportedOperators, (...). |
||
| 241 | */ |
||
| 242 | protected function checkSearchEngineSupport() |
||
| 243 | { |
||
| 244 | // Does nothing by default, override in a concrete test case as needed |
||
| 245 | } |
||
| 246 | |||
| 247 | protected function checkCustomFieldsSupport() |
||
| 248 | { |
||
| 249 | if (get_class($this->getSetupFactory()) === Legacy::class) { |
||
| 250 | $this->markTestSkipped('Legacy Search Engine does not support custom fields'); |
||
| 251 | } |
||
| 252 | } |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Creates and returns content with given $fieldData. |
||
| 256 | * |
||
| 257 | * @param mixed $fieldData |
||
| 258 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 259 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 260 | * |
||
| 261 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 262 | */ |
||
| 263 | protected function createTestSearchContent($fieldData, Repository $repository, $contentType) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Creates test Content and Locations and returns the context for subsequent testing. |
||
| 289 | * |
||
| 290 | * Context consists of repository instance and created Content IDs. |
||
| 291 | * |
||
| 292 | * @return \eZ\Publish\API\Repository\Repository |
||
| 293 | */ |
||
| 294 | View Code Duplication | public function testCreateTestContent() |
|
| 326 | |||
| 327 | /** |
||
| 328 | * Provider method for testFind* methods. |
||
| 329 | * |
||
| 330 | * Do not use directly, use getAdditionallyIndexedFieldData() instead. |
||
| 331 | * |
||
| 332 | * @return array |
||
| 333 | */ |
||
| 334 | View Code Duplication | public function findProvider() |
|
| 363 | |||
| 364 | /** |
||
| 365 | * Tests search with EQ operator. |
||
| 366 | * |
||
| 367 | * Simplified representation: |
||
| 368 | * |
||
| 369 | * value EQ One |
||
| 370 | * |
||
| 371 | * The result should contain Content One. |
||
| 372 | * |
||
| 373 | * @dataProvider findProvider |
||
| 374 | * @depends testCreateTestContent |
||
| 375 | */ |
||
| 376 | public function testFindEqualsOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Tests search with EQ operator. |
||
| 385 | * |
||
| 386 | * Simplified representation: |
||
| 387 | * |
||
| 388 | * NOT( value EQ One ) |
||
| 389 | * |
||
| 390 | * The result should contain Content Two. |
||
| 391 | * |
||
| 392 | * @dataProvider findProvider |
||
| 393 | * @depends testCreateTestContent |
||
| 394 | */ |
||
| 395 | public function testFindNotEqualsOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Tests search with EQ operator. |
||
| 404 | * |
||
| 405 | * Simplified representation: |
||
| 406 | * |
||
| 407 | * value EQ Two |
||
| 408 | * |
||
| 409 | * The result should contain Content Two. |
||
| 410 | * |
||
| 411 | * @dataProvider findProvider |
||
| 412 | * @depends testCreateTestContent |
||
| 413 | */ |
||
| 414 | public function testFindEqualsTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * Tests search with EQ operator. |
||
| 423 | * |
||
| 424 | * Simplified representation: |
||
| 425 | * |
||
| 426 | * NOT( value EQ Two ) |
||
| 427 | * |
||
| 428 | * The result should contain Content One. |
||
| 429 | * |
||
| 430 | * @dataProvider findProvider |
||
| 431 | * @depends testCreateTestContent |
||
| 432 | */ |
||
| 433 | public function testFindNotEqualsTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Tests search with IN operator. |
||
| 442 | * |
||
| 443 | * Simplified representation: |
||
| 444 | * |
||
| 445 | * value IN [One] |
||
| 446 | * |
||
| 447 | * The result should contain Content One. |
||
| 448 | * |
||
| 449 | * @dataProvider findProvider |
||
| 450 | * @depends testCreateTestContent |
||
| 451 | */ |
||
| 452 | public function testFindInOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 458 | |||
| 459 | /** |
||
| 460 | * Tests search with IN operator. |
||
| 461 | * |
||
| 462 | * Simplified representation: |
||
| 463 | * |
||
| 464 | * NOT( value IN [One] ) |
||
| 465 | * |
||
| 466 | * The result should contain Content Two. |
||
| 467 | * |
||
| 468 | * @dataProvider findProvider |
||
| 469 | * @depends testCreateTestContent |
||
| 470 | */ |
||
| 471 | public function testFindNotInOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Tests search with IN operator. |
||
| 482 | * |
||
| 483 | * Simplified representation: |
||
| 484 | * |
||
| 485 | * value IN [Two] |
||
| 486 | * |
||
| 487 | * The result should contain Content Two. |
||
| 488 | * |
||
| 489 | * @dataProvider findProvider |
||
| 490 | * @depends testCreateTestContent |
||
| 491 | */ |
||
| 492 | public function testFindInTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Tests search with IN operator. |
||
| 501 | * |
||
| 502 | * Simplified representation: |
||
| 503 | * |
||
| 504 | * NOT( value IN [Two] ) |
||
| 505 | * |
||
| 506 | * The result should contain Content One. |
||
| 507 | * |
||
| 508 | * @dataProvider findProvider |
||
| 509 | * @depends testCreateTestContent |
||
| 510 | */ |
||
| 511 | public function testFindNotInTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Tests search with IN operator. |
||
| 522 | * |
||
| 523 | * Simplified representation: |
||
| 524 | * |
||
| 525 | * value IN [One,Two] |
||
| 526 | * |
||
| 527 | * The result should contain both Content One and Content Two. |
||
| 528 | * |
||
| 529 | * @dataProvider findProvider |
||
| 530 | * @depends testCreateTestContent |
||
| 531 | */ |
||
| 532 | public function testFindInOneTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Tests search with IN operator. |
||
| 548 | * |
||
| 549 | * Simplified representation: |
||
| 550 | * |
||
| 551 | * NOT( value IN [One,Two] ) |
||
| 552 | * |
||
| 553 | * The result should be empty. |
||
| 554 | * |
||
| 555 | * @dataProvider findProvider |
||
| 556 | * @depends testCreateTestContent |
||
| 557 | */ |
||
| 558 | public function testFindNotInOneTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Tests search with GT operator. |
||
| 576 | * |
||
| 577 | * Simplified representation: |
||
| 578 | * |
||
| 579 | * value GT One |
||
| 580 | * |
||
| 581 | * The result should contain Content Two. |
||
| 582 | * |
||
| 583 | * @dataProvider findProvider |
||
| 584 | * @depends testCreateTestContent |
||
| 585 | */ |
||
| 586 | public function testFindGreaterThanOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 592 | |||
| 593 | /** |
||
| 594 | * Tests search with GT operator. |
||
| 595 | * |
||
| 596 | * Simplified representation: |
||
| 597 | * |
||
| 598 | * NOT( value GT One ) |
||
| 599 | * |
||
| 600 | * The result should contain Content One. |
||
| 601 | * |
||
| 602 | * @dataProvider findProvider |
||
| 603 | * @depends testCreateTestContent |
||
| 604 | */ |
||
| 605 | public function testFindNotGreaterThanOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Tests search with GT operator. |
||
| 614 | * |
||
| 615 | * Simplified representation: |
||
| 616 | * |
||
| 617 | * value GT Two |
||
| 618 | * |
||
| 619 | * The result should be empty. |
||
| 620 | * |
||
| 621 | * @dataProvider findProvider |
||
| 622 | * @depends testCreateTestContent |
||
| 623 | */ |
||
| 624 | public function testFindGreaterThanTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 630 | |||
| 631 | /** |
||
| 632 | * Tests search with GT operator. |
||
| 633 | * |
||
| 634 | * Simplified representation: |
||
| 635 | * |
||
| 636 | * NOT( value GT Two ) |
||
| 637 | * |
||
| 638 | * The result should contain both Content One and Content Two. |
||
| 639 | * |
||
| 640 | * @dataProvider findProvider |
||
| 641 | * @depends testCreateTestContent |
||
| 642 | */ |
||
| 643 | public function testFindNotGreaterThanTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 649 | |||
| 650 | /** |
||
| 651 | * Tests search with GTE operator. |
||
| 652 | * |
||
| 653 | * Simplified representation: |
||
| 654 | * |
||
| 655 | * value GTE One |
||
| 656 | * |
||
| 657 | * The result should contain both Content One and Content Two. |
||
| 658 | * |
||
| 659 | * @dataProvider findProvider |
||
| 660 | * @depends testCreateTestContent |
||
| 661 | */ |
||
| 662 | public function testFindGreaterThanOrEqualOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Tests search with GTE operator. |
||
| 671 | * |
||
| 672 | * Simplified representation: |
||
| 673 | * |
||
| 674 | * NOT( value GTE One ) |
||
| 675 | * |
||
| 676 | * The result should be empty. |
||
| 677 | * |
||
| 678 | * @dataProvider findProvider |
||
| 679 | * @depends testCreateTestContent |
||
| 680 | */ |
||
| 681 | public function testFindNotGreaterThanOrEqual($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 687 | |||
| 688 | /** |
||
| 689 | * Tests search with GTE operator. |
||
| 690 | * |
||
| 691 | * Simplified representation: |
||
| 692 | * |
||
| 693 | * value GTE Two |
||
| 694 | * |
||
| 695 | * The result should contain Content Two. |
||
| 696 | * |
||
| 697 | * @dataProvider findProvider |
||
| 698 | * @depends testCreateTestContent |
||
| 699 | */ |
||
| 700 | public function testFindGreaterThanOrEqualTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 706 | |||
| 707 | /** |
||
| 708 | * Tests search with GTE operator. |
||
| 709 | * |
||
| 710 | * Simplified representation: |
||
| 711 | * |
||
| 712 | * NOT( value GTE Two ) |
||
| 713 | * |
||
| 714 | * The result should contain Content One. |
||
| 715 | * |
||
| 716 | * @dataProvider findProvider |
||
| 717 | * @depends testCreateTestContent |
||
| 718 | */ |
||
| 719 | public function testFindNotGreaterThanOrEqualTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 725 | |||
| 726 | /** |
||
| 727 | * Tests search with LT operator. |
||
| 728 | * |
||
| 729 | * Simplified representation: |
||
| 730 | * |
||
| 731 | * value LT One |
||
| 732 | * |
||
| 733 | * The result should be empty. |
||
| 734 | * |
||
| 735 | * @dataProvider findProvider |
||
| 736 | * @depends testCreateTestContent |
||
| 737 | */ |
||
| 738 | public function testFindLowerThanOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 744 | |||
| 745 | /** |
||
| 746 | * Tests search with LT operator. |
||
| 747 | * |
||
| 748 | * Simplified representation: |
||
| 749 | * |
||
| 750 | * NOT( value LT One ) |
||
| 751 | * |
||
| 752 | * The result should contain both Content One and Content Two. |
||
| 753 | * |
||
| 754 | * @dataProvider findProvider |
||
| 755 | * @depends testCreateTestContent |
||
| 756 | */ |
||
| 757 | public function testFindNotLowerThanOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 763 | |||
| 764 | /** |
||
| 765 | * Tests search with LT operator. |
||
| 766 | * |
||
| 767 | * Simplified representation: |
||
| 768 | * |
||
| 769 | * value LT Two |
||
| 770 | * |
||
| 771 | * The result should contain Content One. |
||
| 772 | * |
||
| 773 | * @dataProvider findProvider |
||
| 774 | * @depends testCreateTestContent |
||
| 775 | */ |
||
| 776 | public function testFindLowerThanTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 782 | |||
| 783 | /** |
||
| 784 | * Tests search with LT operator. |
||
| 785 | * |
||
| 786 | * Simplified representation: |
||
| 787 | * |
||
| 788 | * NOT( value LT Two ) |
||
| 789 | * |
||
| 790 | * The result should contain Content Two. |
||
| 791 | * |
||
| 792 | * @dataProvider findProvider |
||
| 793 | * @depends testCreateTestContent |
||
| 794 | */ |
||
| 795 | public function testFindNotLowerThanTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Tests search with LTE operator. |
||
| 804 | * |
||
| 805 | * Simplified representation: |
||
| 806 | * |
||
| 807 | * value LTE One |
||
| 808 | * |
||
| 809 | * The result should contain Content One. |
||
| 810 | * |
||
| 811 | * @dataProvider findProvider |
||
| 812 | * @depends testCreateTestContent |
||
| 813 | */ |
||
| 814 | public function testFindLowerThanOrEqualOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 820 | |||
| 821 | /** |
||
| 822 | * Tests search with LTE operator. |
||
| 823 | * |
||
| 824 | * Simplified representation: |
||
| 825 | * |
||
| 826 | * NOT( value LTE One ) |
||
| 827 | * |
||
| 828 | * The result should contain Content Two. |
||
| 829 | * |
||
| 830 | * @dataProvider findProvider |
||
| 831 | * @depends testCreateTestContent |
||
| 832 | */ |
||
| 833 | public function testFindNotLowerThanOrEqualOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 839 | |||
| 840 | /** |
||
| 841 | * Tests search with LTE operator. |
||
| 842 | * |
||
| 843 | * Simplified representation: |
||
| 844 | * |
||
| 845 | * value LTE Two |
||
| 846 | * |
||
| 847 | * The result should contain both Content One and Content Two. |
||
| 848 | * |
||
| 849 | * @dataProvider findProvider |
||
| 850 | * @depends testCreateTestContent |
||
| 851 | */ |
||
| 852 | public function testFindLowerThanOrEqualTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 858 | |||
| 859 | /** |
||
| 860 | * Tests search with LTE operator. |
||
| 861 | * |
||
| 862 | * Simplified representation: |
||
| 863 | * |
||
| 864 | * NOT( value LTE Two ) |
||
| 865 | * |
||
| 866 | * The result should be empty. |
||
| 867 | * |
||
| 868 | * @dataProvider findProvider |
||
| 869 | * @depends testCreateTestContent |
||
| 870 | */ |
||
| 871 | public function testFindNotLowerThanOrEqualTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 877 | |||
| 878 | /** |
||
| 879 | * Tests search with BETWEEN operator. |
||
| 880 | * |
||
| 881 | * Simplified representation: |
||
| 882 | * |
||
| 883 | * value BETWEEN [One,Two] |
||
| 884 | * |
||
| 885 | * The result should contain both Content One and Content Two. |
||
| 886 | * |
||
| 887 | * @dataProvider findProvider |
||
| 888 | * @depends testCreateTestContent |
||
| 889 | */ |
||
| 890 | public function testFindBetweenOneTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 903 | |||
| 904 | /** |
||
| 905 | * Tests search with BETWEEN operator. |
||
| 906 | * |
||
| 907 | * Simplified representation: |
||
| 908 | * |
||
| 909 | * NOT( value BETWEEN [One,Two] ) |
||
| 910 | * |
||
| 911 | * The result should contain both Content One and Content Two. |
||
| 912 | * |
||
| 913 | * @dataProvider findProvider |
||
| 914 | * @depends testCreateTestContent |
||
| 915 | */ |
||
| 916 | public function testFindNotBetweenOneTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 931 | |||
| 932 | /** |
||
| 933 | * Tests search with BETWEEN operator. |
||
| 934 | * |
||
| 935 | * Simplified representation: |
||
| 936 | * |
||
| 937 | * value BETWEEN [Two,One] |
||
| 938 | * |
||
| 939 | * The result should be empty. |
||
| 940 | * |
||
| 941 | * @dataProvider findProvider |
||
| 942 | * @depends testCreateTestContent |
||
| 943 | */ |
||
| 944 | public function testFindBetweenTwoOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 957 | |||
| 958 | /** |
||
| 959 | * Tests search with BETWEEN operator. |
||
| 960 | * |
||
| 961 | * Simplified representation: |
||
| 962 | * |
||
| 963 | * NOT( value BETWEEN [Two,One] ) |
||
| 964 | * |
||
| 965 | * The result should contain both Content One and Content Two. |
||
| 966 | * |
||
| 967 | * @dataProvider findProvider |
||
| 968 | * @depends testCreateTestContent |
||
| 969 | */ |
||
| 970 | public function testFindNotBetweenTwoOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 985 | |||
| 986 | /** |
||
| 987 | * Tests search with CONTAINS operator. |
||
| 988 | * |
||
| 989 | * Simplified representation: |
||
| 990 | * |
||
| 991 | * value CONTAINS One |
||
| 992 | * |
||
| 993 | * The result should contain Content One. |
||
| 994 | * |
||
| 995 | * @dataProvider findProvider |
||
| 996 | * @depends testCreateTestContent |
||
| 997 | */ |
||
| 998 | public function testFindContainsOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 1004 | |||
| 1005 | /** |
||
| 1006 | * Tests search with CONTAINS operator. |
||
| 1007 | * |
||
| 1008 | * Simplified representation: |
||
| 1009 | * |
||
| 1010 | * NOT( value CONTAINS One ) |
||
| 1011 | * |
||
| 1012 | * The result should contain Content Two. |
||
| 1013 | * |
||
| 1014 | * @dataProvider findProvider |
||
| 1015 | * @depends testCreateTestContent |
||
| 1016 | */ |
||
| 1017 | public function testFindNotContainsOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 1023 | |||
| 1024 | /** |
||
| 1025 | * Tests search with CONTAINS operator. |
||
| 1026 | * |
||
| 1027 | * Simplified representation: |
||
| 1028 | * |
||
| 1029 | * value CONTAINS Two |
||
| 1030 | * |
||
| 1031 | * The result should contain Content Two. |
||
| 1032 | * |
||
| 1033 | * @dataProvider findProvider |
||
| 1034 | * @depends testCreateTestContent |
||
| 1035 | */ |
||
| 1036 | public function testFindContainsTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 1042 | |||
| 1043 | /** |
||
| 1044 | * Tests search with CONTAINS operator. |
||
| 1045 | * |
||
| 1046 | * Simplified representation: |
||
| 1047 | * |
||
| 1048 | * NOT( value CONTAINS Two ) |
||
| 1049 | * |
||
| 1050 | * The result should contain Content One. |
||
| 1051 | * |
||
| 1052 | * @dataProvider findProvider |
||
| 1053 | * @depends testCreateTestContent |
||
| 1054 | */ |
||
| 1055 | View Code Duplication | public function testFindNotContainsTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
|
| 1063 | |||
| 1064 | /** |
||
| 1065 | * Tests search with LIKE operator, with NO wildcard. |
||
| 1066 | * |
||
| 1067 | * @dataProvider findProvider |
||
| 1068 | * @depends testCreateTestContent |
||
| 1069 | */ |
||
| 1070 | View Code Duplication | public function testFindLikeOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
|
| 1071 | { |
||
| 1072 | // (in case test is skipped for current search engine) |
||
| 1073 | $this->supportsLikeWildcard($valueOne); |
||
| 1074 | |||
| 1075 | $criteria = new Field('data', Operator::LIKE, $valueOne); |
||
| 1076 | |||
| 1077 | $this->assertFindResult($context, $criteria, true, false, $filter, $content, $modifyField); |
||
| 1078 | } |
||
| 1079 | |||
| 1080 | /** |
||
| 1081 | * Tests search with LIKE operator, with wildcard at the end (on strings). |
||
| 1082 | * |
||
| 1083 | * @dataProvider findProvider |
||
| 1084 | * @depends testCreateTestContent |
||
| 1085 | */ |
||
| 1086 | View Code Duplication | public function testFindNotLikeOne($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
|
| 1087 | { |
||
| 1088 | if ($this->supportsLikeWildcard($valueOne)) { |
||
| 1089 | $valueOne = substr_replace($valueOne, '*', -1, 1); |
||
| 1090 | } |
||
| 1091 | |||
| 1092 | $criteria = new LogicalNot( |
||
| 1093 | new Field('data', Operator::LIKE, $valueOne) |
||
| 1094 | ); |
||
| 1095 | |||
| 1096 | $this->assertFindResult($context, $criteria, false, true, $filter, $content, $modifyField); |
||
| 1097 | } |
||
| 1098 | |||
| 1099 | /** |
||
| 1100 | * Tests search with LIKE operator, with wildcard at the start (on strings). |
||
| 1101 | * |
||
| 1102 | * @dataProvider findProvider |
||
| 1103 | * @depends testCreateTestContent |
||
| 1104 | */ |
||
| 1105 | public function testFindLikeTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
||
| 1106 | { |
||
| 1107 | if ($this->supportsLikeWildcard($valueTwo)) { |
||
| 1108 | $valueTwo = substr_replace($valueTwo, '*', 1, 1); |
||
| 1109 | } |
||
| 1110 | |||
| 1111 | $criteria = new Field('data', Operator::LIKE, $valueTwo); |
||
| 1112 | |||
| 1113 | $this->assertFindResult($context, $criteria, false, true, $filter, $content, $modifyField); |
||
| 1114 | |||
| 1115 | // BC support for "%" for Legacy Storage engine only |
||
| 1116 | // @deprecated In 6.13.x/7.3.x and higher, to be removed in 8.0 |
||
| 1117 | if (!$this->supportsLikeWildcard($valueTwo) || get_class($this->getSetupFactory()) !== Legacy::class) { |
||
| 1118 | return; |
||
| 1119 | } |
||
| 1120 | |||
| 1121 | $criteria = new Field('data', Operator::LIKE, substr_replace($valueTwo, '%', 1, 1)); |
||
| 1122 | |||
| 1123 | $this->assertFindResult($context, $criteria, false, true, $filter, $content, $modifyField); |
||
| 1124 | } |
||
| 1125 | |||
| 1126 | /** |
||
| 1127 | * Tests search with LIKE operator, with wildcard in the middle (on strings). |
||
| 1128 | * |
||
| 1129 | * @dataProvider findProvider |
||
| 1130 | * @depends testCreateTestContent |
||
| 1131 | */ |
||
| 1132 | View Code Duplication | public function testFindNotLikeTwo($valueOne, $valueTwo, $filter, $content, $modifyField, array $context) |
|
| 1144 | |||
| 1145 | /** |
||
| 1146 | * Sets given custom field $fieldName on a Field criteria. |
||
| 1147 | * |
||
| 1148 | * $fieldName refers to additional field (to the default field) defined in Indexable definition, |
||
| 1149 | * and is resolved using FieldNameResolver. |
||
| 1150 | * |
||
| 1151 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
| 1152 | * @param string $fieldName |
||
| 1153 | */ |
||
| 1154 | View Code Duplication | protected function modifyFieldCriterion(Criterion $criterion, $fieldName) |
|
| 1173 | |||
| 1174 | /** |
||
| 1175 | * Sets given custom field $fieldName on a Field sort clause. |
||
| 1176 | * |
||
| 1177 | * $fieldName refers to additional field (to the default field) defined in Indexable definition, |
||
| 1178 | * and is resolved using FieldNameResolver. |
||
| 1179 | * |
||
| 1180 | * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause |
||
| 1181 | * @param string $fieldName |
||
| 1182 | */ |
||
| 1183 | View Code Duplication | protected function modifyFieldSortClause(SortClause $sortClause, $fieldName) |
|
| 1201 | |||
| 1202 | /** |
||
| 1203 | * Sets given custom field $fieldName on a Field criteria or sort clauses. |
||
| 1204 | * |
||
| 1205 | * Implemented separately to utilize recursion. |
||
| 1206 | * |
||
| 1207 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion[]|\eZ\Publish\API\Repository\Values\Content\Query\SortClause[] $criteriaOrSortClauses |
||
| 1208 | * @param string $fieldName |
||
| 1209 | */ |
||
| 1210 | protected function doModifyField(array $criteriaOrSortClauses, $fieldName) |
||
| 1224 | |||
| 1225 | public function sortProvider() |
||
| 1247 | |||
| 1248 | /** |
||
| 1249 | * Tests Content Search sort with Field sort clause on a field of specific field type. |
||
| 1250 | * |
||
| 1251 | * @dataProvider sortProvider |
||
| 1252 | * @depends testCreateTestContent |
||
| 1253 | */ |
||
| 1254 | public function testSort($ascending, $content, $modifyField, array $context) |
||
| 1276 | |||
| 1277 | public function fullTextFindProvider() |
||
| 1299 | |||
| 1300 | /** |
||
| 1301 | * @dataProvider fullTextFindProvider |
||
| 1302 | * @depends testCreateTestContent |
||
| 1303 | */ |
||
| 1304 | View Code Duplication | public function testFullTextFindOne($valueOne, $valueTwo, $filter, $content, array $context) |
|
| 1312 | |||
| 1313 | /** |
||
| 1314 | * @dataProvider fullTextFindProvider |
||
| 1315 | * @depends testCreateTestContent |
||
| 1316 | */ |
||
| 1317 | View Code Duplication | public function testFullTextFindTwo($valueOne, $valueTwo, $filter, $content, array $context) |
|
| 1325 | |||
| 1326 | /** |
||
| 1327 | * Returns SearchResult of the tested Content for the given $criterion. |
||
| 1328 | * |
||
| 1329 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 1330 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
| 1331 | * @param bool $filter Denotes search by filtering if true, search by querying if false |
||
| 1332 | * |
||
| 1333 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
| 1334 | */ |
||
| 1335 | View Code Duplication | protected function findContent(Repository $repository, Criterion $criterion, $filter) |
|
| 1358 | |||
| 1359 | /** |
||
| 1360 | * Returns SearchResult of the tested Content for the given $sortClause. |
||
| 1361 | * |
||
| 1362 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 1363 | * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause |
||
| 1364 | * |
||
| 1365 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
| 1366 | */ |
||
| 1367 | View Code Duplication | protected function sortContent(Repository $repository, SortClause $sortClause) |
|
| 1382 | |||
| 1383 | /** |
||
| 1384 | * Returns SearchResult of the tested Locations for the given $criterion. |
||
| 1385 | * |
||
| 1386 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 1387 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
| 1388 | * @param bool $filter Denotes search by filtering if true, search by querying if false |
||
| 1389 | * |
||
| 1390 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
| 1391 | */ |
||
| 1392 | View Code Duplication | protected function findLocations(Repository $repository, Criterion $criterion, $filter) |
|
| 1393 | { |
||
| 1394 | $searchService = $repository->getSearchService(); |
||
| 1395 | |||
| 1415 | |||
| 1416 | /** |
||
| 1417 | * Returns SearchResult of the tested Locations for the given $sortClause. |
||
| 1418 | * |
||
| 1419 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 1420 | * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause $sortClause |
||
| 1421 | * |
||
| 1422 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
| 1423 | */ |
||
| 1424 | View Code Duplication | protected function sortLocations(Repository $repository, SortClause $sortClause) |
|
| 1439 | |||
| 1440 | /** |
||
| 1441 | * Returns a list of Content IDs from given $searchResult, with order preserved. |
||
| 1442 | * |
||
| 1443 | * @param \eZ\Publish\API\Repository\Values\Content\Search\SearchResult $searchResult |
||
| 1444 | * |
||
| 1445 | * @return array |
||
| 1446 | */ |
||
| 1447 | protected function getResultContentIdList(SearchResult $searchResult) |
||
| 1472 | |||
| 1473 | /** |
||
| 1474 | * Asserts expected result, deliberately ignoring order. |
||
| 1475 | * |
||
| 1476 | * Search result can be empty, contain both Content One and Content Two or only one of them. |
||
| 1477 | * |
||
| 1478 | * @param array $context |
||
| 1479 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
| 1480 | * @param bool $includesOne |
||
| 1481 | * @param bool $includesTwo |
||
| 1482 | * @param bool $filter |
||
| 1483 | * @param bool $content |
||
| 1484 | * @param string|null $modifyField |
||
| 1485 | */ |
||
| 1486 | protected function assertFindResult( |
||
| 1537 | |||
| 1538 | /** |
||
| 1539 | * Asserts order of the given $searchResult, both Content One and Two are always expected. |
||
| 1540 | * |
||
| 1541 | * @param \eZ\Publish\API\Repository\Values\Content\Search\SearchResult $searchResult |
||
| 1542 | * @param bool $ascending Denotes ascending order if true, descending order if false |
||
| 1543 | * @param string|int $contentOneId |
||
| 1544 | * @param string|int $contentTwoId |
||
| 1545 | */ |
||
| 1546 | protected function assertSortResult( |
||
| 1566 | } |
||
| 1567 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.