Code Duplication    Length = 48-51 lines in 4 locations

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

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