"Fossies" - the Fresh Open Source Software Archive

Member "neos-development-collection-7.0.1/Neos.ContentRepository/Tests/Functional/Domain/CopyNodeAcrossDimensionsBug3265Test.php" (23 Feb 2021, 7365 Bytes) of package /linux/www/neos-development-collection-7.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 namespace Neos\ContentRepository\Tests\Functional\Domain;
    3 
    4 /*
    5  * This file is part of the Neos.ContentRepository package.
    6  *
    7  * (c) Contributors of the Neos Project - www.neos.io
    8  *
    9  * This package is Open Source Software. For the full copyright and license
   10  * information, please view the LICENSE file which was distributed with this
   11  * source code.
   12  */
   13 
   14 use Neos\Flow\Configuration\ConfigurationManager;
   15 use Neos\Flow\Tests\FunctionalTestCase;
   16 use Neos\ContentRepository\Domain\Factory\NodeFactory;
   17 use Neos\ContentRepository\Domain\Model\Workspace;
   18 use Neos\ContentRepository\Domain\Repository\ContentDimensionRepository;
   19 use Neos\ContentRepository\Domain\Repository\NodeDataRepository;
   20 use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
   21 use Neos\ContentRepository\Domain\Service\Context;
   22 use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
   23 use Neos\ContentRepository\Domain\Service\NodeTypeManager;
   24 
   25 /**
   26  * Functional test case which covers https://github.com/neos/neos-development-collection/issues/3265
   27  */
   28 class CopyNodeAcrossDimensionsBug3265Test extends FunctionalTestCase
   29 {
   30     /**
   31      * @var Context
   32      */
   33     protected $liveContextDe;
   34 
   35     /**
   36      * @var Context
   37      */
   38     protected $liveContextEn;
   39 
   40     /**
   41      * @var Context
   42      */
   43     protected $userWorkspaceContextDe;
   44 
   45     /**
   46      * @var Context
   47      */
   48     protected $userWorkspaceContextEn;
   49 
   50     /**
   51      * @var boolean
   52      */
   53     protected static $testablePersistenceEnabled = true;
   54 
   55     /**
   56      * @var NodeDataRepository
   57      */
   58     protected $nodeDataRepository;
   59 
   60     /**
   61      * @var WorkspaceRepository
   62      */
   63     protected $workspaceRepository;
   64 
   65     /**
   66      * @var Workspace
   67      */
   68     protected $liveWorkspace;
   69 
   70     /**
   71      * @var ContextFactoryInterface
   72      */
   73     protected $contextFactory;
   74 
   75     /**
   76      * @var NodeTypeManager
   77      */
   78     protected $nodeTypeManager;
   79 
   80     /**
   81      * @var ContentDimensionRepository
   82      */
   83     protected $contentDimensionRepository;
   84 
   85     /**
   86      * @return void
   87      */
   88     public function setUp(): void
   89     {
   90         parent::setUp();
   91         $this->persistAndResetStateCompletely();
   92     }
   93 
   94     /**
   95      * @return void
   96      */
   97     public function tearDown(): void
   98     {
   99         parent::tearDown();
  100         $this->inject($this->contextFactory, 'contextInstances', []);
  101         $configuredDimensions = $this->objectManager->get(ConfigurationManager::class)->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.ContentRepository.contentDimensions');
  102         $this->contentDimensionRepository->setDimensionsConfiguration($configuredDimensions);
  103     }
  104 
  105     /**
  106      * @test
  107      */
  108     public function testForBug3265()
  109     {
  110         // FIXTURE SETUP
  111         // node1 in DE and EN (live)
  112         // node2 in DE and EN (live)
  113         $this->liveContextDe->getRootNode()->createNode('node1', null, 'node1-identifier');
  114         $this->liveContextDe->getRootNode()->createNode('node2', null, 'node2-identifier');
  115         $this->liveContextEn->getRootNode()->createNode('node1', null, 'node1-identifier');
  116         $this->liveContextEn->getRootNode()->createNode('node2', null, 'node2-identifier');
  117         $this->persistAndResetStateCompletely();
  118 
  119         // REPRODUCING THE PROBLEM
  120         // 1) we remove the node1 in DE (in user workspace)
  121         $this->userWorkspaceContextDe->getRootNode()->getNode('node1')->remove();
  122         $this->persistAndResetStateCompletely();
  123 
  124         // 2) we copy the node1 from EN to DE after node2 (in user workspace)
  125         $enNode1 = $this->userWorkspaceContextEn->getRootNode()->getNode('node1');
  126         $deNode2 = $this->userWorkspaceContextDe->getRootNode()->getNode('node2');
  127         $this->assertNotNull($enNode1, 'enNode1 must not be null');
  128         $this->assertNotNull($deNode2, 'deNode2 must not be null');
  129         $enNode1->copyAfter($deNode2, 'node-1-pasted');
  130         $this->persistAndResetStateCompletely();
  131 
  132         // EXPECTATION / ASSERTION
  133         // the copied node must appear underneath the root
  134         $childNodes = $this->userWorkspaceContextDe->getRootNode()->getChildNodes();
  135         $childNodePaths = [];
  136         foreach ($childNodes as $node) {
  137             $childNodePaths[] = $node->getPath();
  138         }
  139         $expected = ['/node2', '/node-1-pasted'];
  140         $this->assertEquals($expected, $childNodePaths, 'We copied node-1-pasted, but it does not appear');
  141     }
  142 
  143     protected function persistAndResetStateCompletely()
  144     {
  145         if ($this->nodeDataRepository !== null) {
  146             $this->nodeDataRepository->flushNodeRegistry();
  147         }
  148         /** @var NodeFactory $nodeFactory */
  149         $nodeFactory = $this->objectManager->get(NodeFactory::class);
  150         $nodeFactory->reset();
  151         $this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
  152         $this->contextFactory->reset();
  153         $this->persistenceManager->persistAll();
  154         $this->persistenceManager->clearState();
  155         $this->nodeDataRepository = null;
  156         $this->rootNode = null;
  157 
  158         $this->nodeDataRepository = new NodeDataRepository();
  159 
  160         if ($this->liveWorkspace === null) {
  161             $this->liveWorkspace = new Workspace('live');
  162             $this->objectManager->get(WorkspaceRepository::class);
  163             $this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class);
  164             $this->workspaceRepository->add($this->liveWorkspace);
  165             $this->workspaceRepository->add(new Workspace('user-admin', $this->liveWorkspace));
  166             $this->persistenceManager->persistAll();
  167         }
  168 
  169 
  170         $this->liveContextDe = $this->contextFactory->create([
  171             'workspaceName' => 'live',
  172             'dimensions' => [
  173                 'language' => ['de']
  174             ],
  175             'targetDimensions' => [
  176                 'language' => 'de'
  177             ]
  178         ]);
  179         $this->liveContextEn = $this->contextFactory->create([
  180             'workspaceName' => 'live',
  181             'dimensions' => [
  182                 'language' => ['en']
  183             ],
  184             'targetDimensions' => [
  185                 'language' => 'en'
  186             ]
  187         ]);
  188         $this->userWorkspaceContextDe = $this->contextFactory->create([
  189             'workspaceName' => 'user-admin',
  190             'dimensions' => [
  191                 'language' => ['de']
  192             ],
  193             'targetDimensions' => [
  194                 'language' => 'de'
  195             ]
  196         ]);
  197         $this->userWorkspaceContextEn = $this->contextFactory->create([
  198             'workspaceName' => 'user-admin',
  199             'dimensions' => [
  200                 'language' => ['en']
  201             ],
  202             'targetDimensions' => [
  203                 'language' => 'en'
  204             ]
  205         ]);
  206         $this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class);
  207         $this->contentDimensionRepository = $this->objectManager->get(ContentDimensionRepository::class);
  208 
  209         $this->contentDimensionRepository->setDimensionsConfiguration([
  210             'language' => [
  211                 'default' => 'en',
  212                 'presets' => [
  213                     'enPreset' => [
  214                         'values' => ['en']
  215                     ],
  216                     'dePreset' => [
  217                         'values' => ['de']
  218                     ]
  219                 ]
  220             ]
  221         ]);
  222     }
  223 }