예제 #1
0
파일: ContainerTest.php 프로젝트: reliv/rcm
 /**
  * Test Clone
  *
  * @return void
  *
  * @covers \Rcm\Entity\Container
  */
 public function testClone()
 {
     $site = new Site();
     $site->setSiteId(55);
     $container = ['containerId' => '200', 'name' => 'containerOne', 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('yesterday'), 'lastPublished' => new \DateTime('yesterday'), 'revisions' => [0 => ['revisionId' => 100, 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('yesterday'), 'publishedDate' => new \DateTime('yesterday'), 'published' => true, 'md5' => 'revisionMD5', 'instances' => [0 => ['pluginWrapperId' => 43, 'layoutContainer' => 'layoutOne', 'renderOrder' => 0, 'height' => 32, 'width' => 100, 'divFloat' => 'right', 'instance' => ['pluginInstanceId' => 44, 'plugin' => 'MockPlugin', 'siteWide' => false, 'displayName' => null, 'instanceConfig' => ['var1' => 1, 'var2' => 2], 'md5' => 'firstMd5']], 1 => ['pluginWrapperId' => 45, 'layoutContainer' => 'layoutTwo', 'renderOrder' => 1, 'height' => 33, 'width' => 101, 'divFloat' => 'none', 'instance' => ['pluginInstanceId' => 46, 'plugin' => 'MockPlugin2', 'siteWide' => true, 'displayName' => 'TestSiteWide', 'instanceConfig' => ['var3' => 3, 'var4' => 4], 'md5' => 'secondMd5']]]], 1 => ['revisionId' => 101, 'author' => 'Westin Shafer', 'createdDate' => new \DateTime('-1 month'), 'publishedDate' => new \DateTime('-1 month'), 'published' => false, 'md5' => 'revision2MD5', 'instances' => [0 => ['pluginWrapperId' => 47, 'layoutContainer' => 'layoutThree', 'renderOrder' => 2, 'height' => 33, 'width' => 102, 'divFloat' => 'right', 'instance' => ['pluginInstanceId' => 48, 'plugin' => 'MockPlugin3', 'siteWide' => false, 'displayName' => null, 'instanceConfig' => ['var1' => 1, 'var2' => 2], 'md5' => 'firstMd5']], 1 => ['pluginWrapperId' => 49, 'layoutContainer' => 'layoutFour', 'renderOrder' => 3, 'height' => 34, 'width' => 103, 'divFloat' => 'left', 'instance' => ['pluginInstanceId' => 50, 'plugin' => 'MockPlugin4', 'siteWide' => true, 'displayName' => 'TestSiteWide2', 'instanceConfig' => ['var3' => 3, 'var4' => 4], 'md5' => 'secondMd5']]]]]];
     $this->container->setContainerId($container['containerId']);
     $this->container->setName($container['name']);
     $this->container->setAuthor($container['author']);
     $this->container->setCreatedDate($container['createdDate']);
     $this->container->setLastPublished($container['lastPublished']);
     $this->container->setSite($site);
     foreach ($container['revisions'] as $index => $revisionData) {
         $revision = new Revision();
         $revision->setRevisionId($revisionData['revisionId']);
         $revision->setAuthor($revisionData['author']);
         $revision->setCreatedDate($revisionData['createdDate']);
         $revision->publishRevision();
         $revision->setPublishedDate($revisionData['publishedDate']);
         $revision->setMd5($revisionData['md5']);
         foreach ($revisionData['instances'] as $instance) {
             $plugin = new PluginInstance();
             $plugin->setInstanceId($instance['instance']['pluginInstanceId']);
             $plugin->setPlugin($instance['instance']['plugin']);
             if ($instance['instance']['siteWide']) {
                 $plugin->setSiteWide();
             }
             $plugin->setDisplayName($instance['instance']['displayName']);
             $plugin->setInstanceConfig($instance['instance']['instanceConfig']);
             $plugin->setMd5($instance['instance']['md5']);
             $wrapper = new PluginWrapper();
             $wrapper->setPluginWrapperId($instance['pluginWrapperId']);
             $wrapper->setLayoutContainer($instance['layoutContainer']);
             $wrapper->setRenderOrderNumber($instance['renderOrder']);
             $wrapper->setHeight($instance['height']);
             $wrapper->setWidth($instance['width']);
             $wrapper->setDivFloat($instance['divFloat']);
             $wrapper->setInstance($plugin);
             $revision->addPluginWrapper($wrapper);
         }
         if ($index === 0) {
             $this->container->setPublishedRevision($revision);
         } elseif ($index === 1) {
             $this->container->setStagedRevision($revision);
         }
         $this->container->addRevision($revision);
     }
     $this->assertCount(2, $this->container->getRevisions());
     $clonedContainer = clone $this->container;
     /* Test Container */
     $this->assertNotEquals($this->container->getContainerId(), $clonedContainer->getContainerId());
     $this->assertNull($clonedContainer->getContainerId());
     $this->assertNull($clonedContainer->getPublishedRevision());
     $this->assertCount(1, $clonedContainer->getRevisions());
     $currentRevision = $this->container->getPublishedRevision();
     $clonedCurrentRev = $clonedContainer->getStagedRevision();
     /* Test Revision */
     $this->assertNotEquals($currentRevision->getRevisionId(), $clonedCurrentRev->getRevisionId());
     $this->assertNull($clonedCurrentRev->getRevisionId());
     $this->assertEquals($currentRevision->getAuthor(), $clonedCurrentRev->getAuthor());
     $this->assertNotEquals($currentRevision->getCreatedDate(), $clonedCurrentRev->getCreatedDate());
     $this->assertFalse($clonedCurrentRev->wasPublished());
     $this->assertEquals($currentRevision->getMd5(), $clonedCurrentRev->getMd5());
     $revisionWrappers = $currentRevision->getPluginWrappers();
     $clonedWrappers = $clonedCurrentRev->getPluginWrappers();
     $this->assertNotEquals($revisionWrappers, $clonedWrappers);
     /** @var \Rcm\Entity\PluginWrapper $clonedWrapper */
     foreach ($clonedWrappers as $clonedWrapper) {
         if (!$clonedWrapper->getInstance()->isSiteWide()) {
             $this->assertNull($clonedWrapper->getInstance()->getInstanceId());
         } else {
             $this->assertNotNull($clonedWrapper->getInstance()->getInstanceId());
         }
     }
     $this->container->setContainerId(null);
     $noContainerClone = clone $this->container;
 }