public function testParsedJson()
 {
     $fileContents = json_decode(file_get_contents(__DIR__ . '/../../../Tests/Resources/email_template.json'), true);
     $arrayConverter = new ArrayConverter(new ElementFactory());
     $result = $arrayConverter->createFromArray($fileContents);
     $emailTemplate = new EmailTemplate();
     $emailTemplate->setChildren($result);
     $validator = new Validator([new Validator\Rule\CantBeEmpty(), new Validator\Rule\CheckAllowedChildren()]);
     $this->assertFalse($validator->validate($emailTemplate)->hasErrors());
 }
 public function testCreateFromArray()
 {
     $data1 = ['type' => 'normalText', 'content' => 'someText'];
     $data2 = ['type' => 'paragraph', 'children' => []];
     $element1Mock = m::mock('TPN\\EmailTemplatesComponent\\Element\\ElementInterface');
     $element1Mock->shouldReceive('isLeaf')->once()->andReturn(true);
     $element1Mock->shouldReceive('setContent')->once();
     $element2Mock = m::mock('TPN\\EmailTemplatesComponent\\Element\\ElementInterface');
     $element2Mock->shouldReceive('isLeaf')->once()->andReturn(false);
     $element2Mock->shouldReceive('setChildren')->once();
     $elementFactoryMock = m::mock('TPN\\EmailTemplatesComponent\\Element\\ElementFactoryInterface');
     $elementFactoryMock->shouldReceive('createFromArray')->with($data1)->once()->andReturn($element1Mock);
     $elementFactoryMock->shouldReceive('createFromArray')->with($data2)->once()->andReturn($element2Mock);
     $converter = new ArrayConverter($elementFactoryMock);
     $result = $converter->createFromArray([$data1, $data2]);
     $this->assertCount(2, $result);
     $this->assertInstanceOf('TPN\\EmailTemplatesComponent\\Element\\ElementInterface', $result[0]);
     $this->assertInstanceOf('TPN\\EmailTemplatesComponent\\Element\\ElementInterface', $result[1]);
 }
 public function testCreateFromJsonFileArray()
 {
     $fileContents = file_get_contents(__DIR__ . '/../../../Tests/Resources/email_template.json');
     $jsonArray = json_decode($fileContents, true);
     $converter = new ArrayConverter(new ElementFactory());
     $result = $converter->createFromArray($jsonArray);
     $el = ArrayConverter::$elements;
     $this->assertCount(6, $result);
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_WHITEBLOCK], $result[0]);
     $this->assertCount(2, $result[0]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_HEADER], $result[0]->getChildren()[0]);
     $this->assertCount(1, $result[0]->getChildren()[0]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_NORMALTEXT], $result[0]->getChildren()[0]->getChildren()[0]);
     $this->assertEquals('Welcome to CurbanA, Shaquille!', $result[0]->getChildren()[0]->getChildren()[0]->getContent());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_PARAGRAPH], $result[0]->getChildren()[1]);
     $this->assertCount(1, $result[0]->getChildren()[1]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_NORMALTEXT], $result[0]->getChildren()[1]->getChildren()[0]);
     $this->assertEquals('The place to earn free tickets & VIP rewards for promoting your favourite music festivals', $result[0]->getChildren()[1]->getChildren()[0]->getContent());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_WHITEBLOCK], $result[1]);
     $this->assertCount(3, $result[1]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_HEADER], $result[1]->getChildren()[0]);
     $this->assertCount(1, $result[1]->getChildren()[0]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_NORMALTEXT], $result[1]->getChildren()[0]->getChildren()[0]);
     $this->assertEquals('1. Request tickets to promote your favourite music festivals', $result[1]->getChildren()[0]->getChildren()[0]->getContent());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_PARAGRAPH], $result[1]->getChildren()[1]);
     $this->assertCount(1, $result[1]->getChildren()[1]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_NORMALTEXT], $result[1]->getChildren()[1]->getChildren()[0]);
     $this->assertEquals("Click on the icon below to request tickets to the festival you'd like to promote.\nIf the campaign isn't live just yet, click I'm interested and you'll be the first to know when the tickets are available.", $result[1]->getChildren()[1]->getChildren()[0]->getContent());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_PARAGRAPH], $result[1]->getChildren()[2]);
     $this->assertCount(1, $result[1]->getChildren()[2]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_NORMALTEXT], $result[1]->getChildren()[2]->getChildren()[0]);
     $this->assertEquals('{{ requestTicketsButton }}', $result[1]->getChildren()[2]->getChildren()[0]->getContent());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_WHITEBLOCK], $result[2]);
     $this->assertCount(2, $result[2]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_HEADER], $result[2]->getChildren()[0]);
     $this->assertCount(1, $result[2]->getChildren()[0]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_NORMALTEXT], $result[2]->getChildren()[0]->getChildren()[0]);
     $this->assertEquals('2. Get tickets allocated and start promoting!', $result[2]->getChildren()[0]->getChildren()[0]->getContent());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_PARAGRAPH], $result[2]->getChildren()[1]);
     $this->assertCount(1, $result[2]->getChildren()[1]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_NORMALTEXT], $result[2]->getChildren()[1]->getChildren()[0]);
     $this->assertEquals("Don't worry, if you don't sell the allocated tickets, you don't owe us anything.", $result[2]->getChildren()[1]->getChildren()[0]->getContent());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_WHITEBLOCK], $result[3]);
     $this->assertCount(4, $result[3]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_HEADER], $result[3]->getChildren()[0]);
     $this->assertCount(1, $result[3]->getChildren()[0]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_NORMALTEXT], $result[3]->getChildren()[0]->getChildren()[0]);
     $this->assertEquals('3. Connect your social networks', $result[3]->getChildren()[0]->getChildren()[0]->getContent());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_PARAGRAPH], $result[3]->getChildren()[1]);
     $this->assertCount(1, $result[3]->getChildren()[1]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_NORMALTEXT], $result[3]->getChildren()[1]->getChildren()[0]);
     $this->assertEquals('Find out which festivals and bands your friends like and earn your FREE ticket faster!', $result[3]->getChildren()[1]->getChildren()[0]->getContent());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_PARAGRAPH], $result[3]->getChildren()[2]);
     $this->assertCount(1, $result[3]->getChildren()[2]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_NORMALTEXT], $result[3]->getChildren()[2]->getChildren()[0]);
     $this->assertEquals('{{ connectFacebookButton }}', $result[3]->getChildren()[2]->getChildren()[0]->getContent());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_PARAGRAPH], $result[3]->getChildren()[3]);
     $this->assertCount(1, $result[3]->getChildren()[2]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_NORMALTEXT], $result[3]->getChildren()[3]->getChildren()[0]);
     $this->assertEquals('{{ connectTwitterButton }}', $result[3]->getChildren()[3]->getChildren()[0]->getContent());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_WHITEBLOCK], $result[4]);
     $this->assertCount(2, $result[4]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_HEADER], $result[4]->getChildren()[0]);
     $this->assertCount(1, $result[4]->getChildren()[0]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_NORMALTEXT], $result[4]->getChildren()[0]->getChildren()[0]);
     $this->assertEquals('Questions?', $result[4]->getChildren()[0]->getChildren()[0]->getContent());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_PARAGRAPH], $result[4]->getChildren()[1]);
     $this->assertCount(1, $result[4]->getChildren()[1]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_NORMALTEXT], $result[4]->getChildren()[1]->getChildren()[0]);
     $this->assertEquals("Your Community Manager, Dean Attil is here to help, you can find their contact details in your {{ accountLink }}.\nor feel free to take our {{ ambassadorTourLink }}.", $result[4]->getChildren()[1]->getChildren()[0]->getContent());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_WHITEBLOCK], $result[5]);
     $this->assertCount(2, $result[5]->getChildren());
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_HEADER], $result[5]->getChildren()[0]);
     $this->assertInstanceOf($el[ArrayConverter::ELEMENT_READONLY], $result[5]->getChildren()[1]);
     $this->assertEquals($result[5]->getChildren()[1]->getContentId(), 'ticketConfirmationSummary');
     //        $this->assertEquals($result[5]->getChildren()[1]->dump(), '{{ contentId_file_ticketConfirmationSummary }}');
 }