Code Duplication    Length = 48-51 lines in 4 locations

www/src/AdminBundle/Tests/Model/ImportTwineTest.php 4 locations

@@ 568-618 (lines=51) @@
565
     * tests a hitch to another textnode
566
     * @throws \Exception
567
     */
568
    public function testRunWithLinkToAnotherTextnode()
569
    {
570
        $importfile = $this->getDummyImportfile();
571
572
        $this->fileExtractorMock->expects(self::any())
573
            ->method('extract')
574
            ->willReturn('readable.extracted');
575
576
        self::$freadStack = [
577
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
578
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
579
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId1" position="104,30">lorem ipsum',
580
            'lorem ipsum</tw-passagedata>',
581
            '</tw-storydata>',
582
        ];
583
584
        $textnode1 = new Textnode();
585
        $textnode1->setText('lorem ipsum [[Linkdata->someNodeName2]]');
586
        $textnode1->setId('someId0');
587
588
        $textnode2 = new Textnode();
589
        $textnode2->setId('someId1');
590
591
        $this->hitchParserMock->expects(self::once())
592
            ->method('parseSingleArrowRight')
593
            ->with('Linkdata->someNodeName2')
594
            ->willReturn(
595
                [
596
                    'description' => 'some description',
597
                    'textnodeId' => 'someTextnodeId',
598
                    'status' => Textnode::HITCH_STATUS_ACTIVE,
599
                ]
600
            );
601
602
        $this->textnodeRepository->expects($this->any())
603
            ->method('find')
604
            ->will($this->returnValue($textnode1));
605
606
        $this->textnodeRepository->expects($this->any())
607
            ->method('save')
608
            ->willReturnCallback(function ($textnode) {
609
                static $counter = 0;
610
                $textnode->setId('someTextnode'.$counter++);
611
            });
612
613
        $returnValue = $this->importTwine->run($importfile);
614
615
        self::assertTrue($returnValue);
616
        self::assertEquals('<p>lorem ipsum</p>', $textnode1->getText());
617
        self::assertEquals(1, $textnode1->getHitchCount());
618
    }
619
620
    /**
621
     * tests a hitch to another textnode
@@ 624-671 (lines=48) @@
621
     * tests a hitch to another textnode
622
     * @throws \Exception
623
     */
624
    public function testRunWithLinkToAnotherTextnodeDoubleArrowRight()
625
    {
626
        $importfile = $this->getDummyImportfile();
627
628
        $this->fileExtractorMock->expects(self::any())
629
            ->method('extract')
630
            ->willReturn('readable.extracted');
631
632
        self::$freadStack = [
633
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
634
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
635
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId1" position="104,30">lorem ipsum',
636
            'lorem ipsum</tw-passagedata>',
637
            '</tw-storydata>',
638
        ];
639
640
        $textnode1 = new Textnode();
641
        $textnode1->setText('lorem ipsum [[description1-->textnodeId1]]');
642
        $textnode1->setId('someId0');
643
644
        $this->hitchParserMock->expects(self::once())
645
            ->method('parseDoubleArrowRight')
646
            ->with('description1-->textnodeId1')
647
            ->willReturn(
648
                [
649
                    'description' => 'description1',
650
                    'textnodeId' => 'textnodeId1',
651
                    'status' => Textnode::HITCH_STATUS_ACTIVE,
652
                ]
653
            );
654
655
        $this->textnodeRepository->expects($this->any())
656
            ->method('find')
657
            ->will($this->returnValue($textnode1));
658
659
        $this->textnodeRepository->expects($this->any())
660
            ->method('save')
661
            ->willReturnCallback(function ($textnode) {
662
                static $counter = 0;
663
                $textnode->setId('someTextnode'.$counter++);
664
            });
665
666
        $returnValue = $this->importTwine->run($importfile);
667
668
        self::assertTrue($returnValue);
669
        self::assertEquals('<p>lorem ipsum</p>', $textnode1->getText());
670
        self::assertEquals(1, $textnode1->getHitchCount());
671
    }
672
673
    /**
674
     * tests a hitch to another textnode
@@ 677-724 (lines=48) @@
674
     * tests a hitch to another textnode
675
     * @throws \Exception
676
     */
677
    public function testRunWithLinkToAnotherTextnodeSingleArrowLeft()
678
    {
679
        $importfile = $this->getDummyImportfile();
680
681
        $this->fileExtractorMock->expects(self::any())
682
            ->method('extract')
683
            ->willReturn('readable.extracted');
684
685
        self::$freadStack = [
686
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
687
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
688
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId1" position="104,30">lorem ipsum',
689
            'lorem ipsum</tw-passagedata>',
690
            '</tw-storydata>',
691
        ];
692
693
        $textnode1 = new Textnode();
694
        $textnode1->setText('lorem ipsum [[description1<-textnodeId1]]');
695
        $textnode1->setId('someId0');
696
697
        $this->hitchParserMock->expects(self::once())
698
            ->method('parseSingleArrowLeft')
699
            ->with('description1<-textnodeId1')
700
            ->willReturn(
701
                [
702
                    'description' => 'description1',
703
                    'textnodeId' => 'textnodeId1',
704
                    'status' => Textnode::HITCH_STATUS_ACTIVE,
705
                ]
706
            );
707
708
        $this->textnodeRepository->expects($this->any())
709
            ->method('find')
710
            ->will($this->returnValue($textnode1));
711
712
        $this->textnodeRepository->expects($this->any())
713
            ->method('save')
714
            ->willReturnCallback(function ($textnode) {
715
                static $counter = 0;
716
                $textnode->setId('someTextnode'.$counter++);
717
            });
718
719
        $returnValue = $this->importTwine->run($importfile);
720
721
        self::assertTrue($returnValue);
722
        self::assertEquals('<p>lorem ipsum</p>', $textnode1->getText());
723
        self::assertEquals(1, $textnode1->getHitchCount());
724
    }
725
726
    /**
727
     * tests a hitch to another textnode
@@ 730-777 (lines=48) @@
727
     * tests a hitch to another textnode
728
     * @throws \Exception
729
     */
730
    public function testRunWithLinkToAnotherTextnodeSimpleHitch()
731
    {
732
        $importfile = $this->getDummyImportfile();
733
734
        $this->fileExtractorMock->expects(self::any())
735
            ->method('extract')
736
            ->willReturn('readable.extracted');
737
738
        self::$freadStack = [
739
            '<tw-storydata name="someStoryName" startnode="1" creator="Twine" creator-version="2.0.8" ifid="8E30D51C-4980-4161-B57F-B11C752E879A" format="Harlowe" options=""><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style>'."\n",
740
            '<script role="script" id="twine-user-script" type="text/twine-javascript"></script>'."\n",
741
            '<tw-passagedata pid="1" name="someNodeName1" tags="ID:someTwineId1" position="104,30">lorem ipsum',
742
            'lorem ipsum</tw-passagedata>',
743
            '</tw-storydata>',
744
        ];
745
746
        $textnode1 = new Textnode();
747
        $textnode1->setText('lorem ipsum [[description1]]');
748
        $textnode1->setId('someId0');
749
750
        $this->hitchParserMock->expects(self::once())
751
            ->method('parseSimpleHitch')
752
            ->with('description1')
753
            ->willReturn(
754
                [
755
                    'description' => 'description1',
756
                    'textnodeId' => 'textnodeId1',
757
                    'status' => Textnode::HITCH_STATUS_ACTIVE,
758
                ]
759
            );
760
761
        $this->textnodeRepository->expects($this->any())
762
            ->method('find')
763
            ->will($this->returnValue($textnode1));
764
765
        $this->textnodeRepository->expects($this->any())
766
            ->method('save')
767
            ->willReturnCallback(function ($textnode) {
768
                static $counter = 0;
769
                $textnode->setId('someTextnode'.$counter++);
770
            });
771
772
        $returnValue = $this->importTwine->run($importfile);
773
774
        self::assertTrue($returnValue);
775
        self::assertEquals('<p>lorem ipsum</p>', $textnode1->getText());
776
        self::assertEquals(1, $textnode1->getHitchCount());
777
    }
778
779
    /**
780
     * tests a hitch to another textnode