| @@ 507-544 (lines=38) @@ | ||
| 504 | * @see \eZ\Publish\API\Repository\LanguageService::createLanguage() |
|
| 505 | * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testCreateLanguage |
|
| 506 | */ |
|
| 507 | public function testCreateLanguageInTransactionWithRollback() |
|
| 508 | { |
|
| 509 | $repository = $this->getRepository(); |
|
| 510 | ||
| 511 | /* BEGIN: Use Case */ |
|
| 512 | $languageService = $repository->getContentLanguageService(); |
|
| 513 | ||
| 514 | // Start a new transaction |
|
| 515 | $repository->beginTransaction(); |
|
| 516 | ||
| 517 | try { |
|
| 518 | // Get create struct and set properties |
|
| 519 | $languageCreate = $languageService->newLanguageCreateStruct(); |
|
| 520 | $languageCreate->enabled = true; |
|
| 521 | $languageCreate->name = 'English (New Zealand)'; |
|
| 522 | $languageCreate->languageCode = 'eng-NZ'; |
|
| 523 | ||
| 524 | // Create new language |
|
| 525 | $languageService->createLanguage($languageCreate); |
|
| 526 | } catch (Exception $e) { |
|
| 527 | // Cleanup hanging transaction on error |
|
| 528 | $repository->rollback(); |
|
| 529 | throw $e; |
|
| 530 | } |
|
| 531 | ||
| 532 | // Rollback all changes |
|
| 533 | $repository->rollback(); |
|
| 534 | ||
| 535 | try { |
|
| 536 | // This call will fail with a "NotFoundException" |
|
| 537 | $languageService->loadLanguage('eng-NZ'); |
|
| 538 | } catch (NotFoundException $e) { |
|
| 539 | // Expected execution path |
|
| 540 | } |
|
| 541 | /* END: Use Case */ |
|
| 542 | ||
| 543 | $this->assertTrue(isset($e), 'Can still load language after rollback'); |
|
| 544 | } |
|
| 545 | ||
| 546 | /** |
|
| 547 | * Test for the createLanguage() method. |
|
| @@ 552-585 (lines=34) @@ | ||
| 549 | * @see \eZ\Publish\API\Repository\LanguageService::createLanguage() |
|
| 550 | * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testCreateLanguage |
|
| 551 | */ |
|
| 552 | public function testCreateLanguageInTransactionWithCommit() |
|
| 553 | { |
|
| 554 | $repository = $this->getRepository(); |
|
| 555 | ||
| 556 | /* BEGIN: Use Case */ |
|
| 557 | $languageService = $repository->getContentLanguageService(); |
|
| 558 | ||
| 559 | // Start a new transaction |
|
| 560 | $repository->beginTransaction(); |
|
| 561 | ||
| 562 | try { |
|
| 563 | // Get create struct and set properties |
|
| 564 | $languageCreate = $languageService->newLanguageCreateStruct(); |
|
| 565 | $languageCreate->enabled = true; |
|
| 566 | $languageCreate->name = 'English (New Zealand)'; |
|
| 567 | $languageCreate->languageCode = 'eng-NZ'; |
|
| 568 | ||
| 569 | // Create new language |
|
| 570 | $languageService->createLanguage($languageCreate); |
|
| 571 | ||
| 572 | // Commit all changes |
|
| 573 | $repository->commit(); |
|
| 574 | } catch (Exception $e) { |
|
| 575 | // Cleanup hanging transaction on error |
|
| 576 | $repository->rollback(); |
|
| 577 | throw $e; |
|
| 578 | } |
|
| 579 | ||
| 580 | // Load new language |
|
| 581 | $language = $languageService->loadLanguage('eng-NZ'); |
|
| 582 | /* END: Use Case */ |
|
| 583 | ||
| 584 | $this->assertEquals('eng-NZ', $language->languageCode); |
|
| 585 | } |
|
| 586 | ||
| 587 | /** |
|
| 588 | * Test for the updateLanguageName() method. |
|
| @@ 740-776 (lines=37) @@ | ||
| 737 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection |
|
| 738 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSectionByIdentifier |
|
| 739 | */ |
|
| 740 | public function testCreateSectionInTransactionWithRollback() |
|
| 741 | { |
|
| 742 | $repository = $this->getRepository(); |
|
| 743 | ||
| 744 | /* BEGIN: Use Case */ |
|
| 745 | $sectionService = $repository->getSectionService(); |
|
| 746 | ||
| 747 | // Start a new transaction |
|
| 748 | $repository->beginTransaction(); |
|
| 749 | ||
| 750 | try { |
|
| 751 | // Get a create struct and set some properties |
|
| 752 | $sectionCreate = $sectionService->newSectionCreateStruct(); |
|
| 753 | $sectionCreate->name = 'Test Section'; |
|
| 754 | $sectionCreate->identifier = 'uniqueKey'; |
|
| 755 | ||
| 756 | // Create a new section |
|
| 757 | $sectionService->createSection($sectionCreate); |
|
| 758 | } catch (Exception $e) { |
|
| 759 | // Cleanup hanging transaction on error |
|
| 760 | $repository->rollback(); |
|
| 761 | throw $e; |
|
| 762 | } |
|
| 763 | ||
| 764 | // Rollback all changes |
|
| 765 | $repository->rollback(); |
|
| 766 | ||
| 767 | try { |
|
| 768 | // This call will fail with a not found exception |
|
| 769 | $sectionService->loadSectionByIdentifier('uniqueKey'); |
|
| 770 | } catch (NotFoundException $e) { |
|
| 771 | // Expected execution path |
|
| 772 | } |
|
| 773 | /* END: Use Case */ |
|
| 774 | ||
| 775 | $this->assertTrue(isset($e), 'Can still load section after rollback.'); |
|
| 776 | } |
|
| 777 | ||
| 778 | /** |
|
| 779 | * Test for the createSection() method. |
|
| @@ 785-817 (lines=33) @@ | ||
| 782 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection |
|
| 783 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSectionByIdentifier |
|
| 784 | */ |
|
| 785 | public function testCreateSectionInTransactionWithCommit() |
|
| 786 | { |
|
| 787 | $repository = $this->getRepository(); |
|
| 788 | ||
| 789 | /* BEGIN: Use Case */ |
|
| 790 | $sectionService = $repository->getSectionService(); |
|
| 791 | ||
| 792 | // Start a new transaction |
|
| 793 | $repository->beginTransaction(); |
|
| 794 | ||
| 795 | try { |
|
| 796 | // Get a create struct and set some properties |
|
| 797 | $sectionCreate = $sectionService->newSectionCreateStruct(); |
|
| 798 | $sectionCreate->name = 'Test Section'; |
|
| 799 | $sectionCreate->identifier = 'uniqueKey'; |
|
| 800 | ||
| 801 | // Create a new section |
|
| 802 | $sectionService->createSection($sectionCreate); |
|
| 803 | ||
| 804 | // Commit all changes |
|
| 805 | $repository->commit(); |
|
| 806 | } catch (Exception $e) { |
|
| 807 | // Cleanup hanging transaction on error |
|
| 808 | $repository->rollback(); |
|
| 809 | throw $e; |
|
| 810 | } |
|
| 811 | ||
| 812 | // Load new section |
|
| 813 | $section = $sectionService->loadSectionByIdentifier('uniqueKey'); |
|
| 814 | /* END: Use Case */ |
|
| 815 | ||
| 816 | $this->assertEquals('uniqueKey', $section->identifier); |
|
| 817 | } |
|
| 818 | ||
| 819 | /** |
|
| 820 | * Test for the createSection() method. |
|
| @@ 826-860 (lines=35) @@ | ||
| 823 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection |
|
| 824 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSectionByIdentifier |
|
| 825 | */ |
|
| 826 | public function testUpdateSectionInTransactionWithRollback() |
|
| 827 | { |
|
| 828 | $repository = $this->getRepository(); |
|
| 829 | ||
| 830 | /* BEGIN: Use Case */ |
|
| 831 | $sectionService = $repository->getSectionService(); |
|
| 832 | ||
| 833 | // Start a new transaction |
|
| 834 | $repository->beginTransaction(); |
|
| 835 | ||
| 836 | try { |
|
| 837 | // Load standard section |
|
| 838 | $section = $sectionService->loadSectionByIdentifier('standard'); |
|
| 839 | ||
| 840 | // Get an update struct and change section name |
|
| 841 | $sectionUpdate = $sectionService->newSectionUpdateStruct(); |
|
| 842 | $sectionUpdate->name = 'My Standard'; |
|
| 843 | ||
| 844 | // Update section |
|
| 845 | $sectionService->updateSection($section, $sectionUpdate); |
|
| 846 | } catch (Exception $e) { |
|
| 847 | // Cleanup hanging transaction on error |
|
| 848 | $repository->rollback(); |
|
| 849 | throw $e; |
|
| 850 | } |
|
| 851 | ||
| 852 | // Rollback all changes |
|
| 853 | $repository->rollback(); |
|
| 854 | ||
| 855 | // Load updated section, name will still be "Standard" |
|
| 856 | $updatedStandard = $sectionService->loadSectionByIdentifier('standard'); |
|
| 857 | /* END: Use Case */ |
|
| 858 | ||
| 859 | $this->assertEquals('Standard', $updatedStandard->name); |
|
| 860 | } |
|
| 861 | ||
| 862 | /** |
|
| 863 | * Test for the createSection() method. |
|
| @@ 869-903 (lines=35) @@ | ||
| 866 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection |
|
| 867 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSectionByIdentifier |
|
| 868 | */ |
|
| 869 | public function testUpdateSectionInTransactionWithCommit() |
|
| 870 | { |
|
| 871 | $repository = $this->getRepository(); |
|
| 872 | ||
| 873 | /* BEGIN: Use Case */ |
|
| 874 | $sectionService = $repository->getSectionService(); |
|
| 875 | ||
| 876 | // Start a new transaction |
|
| 877 | $repository->beginTransaction(); |
|
| 878 | ||
| 879 | try { |
|
| 880 | // Load standard section |
|
| 881 | $section = $sectionService->loadSectionByIdentifier('standard'); |
|
| 882 | ||
| 883 | // Get an update struct and change section name |
|
| 884 | $sectionUpdate = $sectionService->newSectionUpdateStruct(); |
|
| 885 | $sectionUpdate->name = 'My Standard'; |
|
| 886 | ||
| 887 | // Update section |
|
| 888 | $sectionService->updateSection($section, $sectionUpdate); |
|
| 889 | ||
| 890 | // Commit all changes |
|
| 891 | $repository->commit(); |
|
| 892 | } catch (Exception $e) { |
|
| 893 | // Cleanup hanging transaction on error |
|
| 894 | $repository->rollback(); |
|
| 895 | throw $e; |
|
| 896 | } |
|
| 897 | ||
| 898 | // Load updated section, name will now be "My Standard" |
|
| 899 | $updatedStandard = $sectionService->loadSectionByIdentifier('standard'); |
|
| 900 | /* END: Use Case */ |
|
| 901 | ||
| 902 | $this->assertEquals('My Standard', $updatedStandard->name); |
|
| 903 | } |
|
| 904 | } |
|
| 905 | ||