Merge pull request #3925 from beganovich/v2-2207-pdfmaker-changes

Moving PdfMaker out of tests folder
This commit is contained in:
David Bomba 2020-07-23 07:41:11 +10:00 committed by GitHub
commit 3f1d877273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 263 additions and 145 deletions

View File

@ -0,0 +1,23 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\PdfMaker\Designs;
class Bold
{
public function html()
{
return file_get_contents(
base_path('resources/views/pdf-designs//bold.html')
);
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\PdfMaker\Designs;
class Business
{
public function html()
{
return file_get_contents(
base_path('resources/views/pdf-designs//business.html')
);
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\PdfMaker\Designs;
class Clean
{
public function html()
{
return file_get_contents(
base_path('resources/views/pdf-designs//clean.html')
);
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\PdfMaker\Designs;
class Creative
{
public function html()
{
return file_get_contents(
base_path('resources/views/pdf-designs//creative.html')
);
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\PdfMaker\Designs;
class Elegant
{
public function html()
{
return file_get_contents(
base_path('resources/views/pdf-designs//elegant.html')
);
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\PdfMaker\Designs;
class Hipster
{
public function html()
{
return file_get_contents(
base_path('resources/views/pdf-designs//hipster.html')
);
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\PdfMaker\Designs;
class Modern
{
public function html()
{
return file_get_contents(
base_path('resources/views/pdf-designs//modern.html')
);
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\PdfMaker\Designs;
class Plain
{
public function html()
{
return file_get_contents(
base_path('resources/views/pdf-designs//plain.html')
);
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\PdfMaker\Designs;
class Playful
{
public function html()
{
return file_get_contents(
base_path('resources/views/pdf-designs//playful.html')
);
}
}

View File

@ -1,6 +1,16 @@
<?php <?php
namespace Tests\Feature\PdfMaker; /**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\PdfMaker;
class PdfMaker class PdfMaker
{ {

View File

@ -1,6 +1,16 @@
<?php <?php
namespace Tests\Feature\PdfMaker; /**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\PdfMaker;
use DOMDocument; use DOMDocument;
use DOMXPath; use DOMXPath;

View File

@ -1,13 +0,0 @@
<?php
namespace Tests\Feature\PdfMaker;
class Bold
{
public function html()
{
return file_get_contents(
base_path('tests/Feature/PdfMaker/designs/bold.html')
);
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace Tests\Feature\PdfMaker;
class Business
{
public function html()
{
return file_get_contents(
base_path('tests/Feature/PdfMaker/designs/business.html')
);
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace Tests\Feature\PdfMaker;
class Clean
{
public function html()
{
return file_get_contents(
base_path('tests/Feature/PdfMaker/designs/clean.html')
);
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace Tests\Feature\PdfMaker;
class Creative
{
public function html()
{
return file_get_contents(
base_path('tests/Feature/PdfMaker/designs/creative.html')
);
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace Tests\Feature\PdfMaker;
class Elegant
{
public function html()
{
return file_get_contents(
base_path('tests/Feature/PdfMaker/designs/elegant.html')
);
}
}

View File

@ -2,12 +2,12 @@
namespace Tests\Feature\PdfMaker; namespace Tests\Feature\PdfMaker;
class Modern class ExampleDesign
{ {
public function html() public function html()
{ {
return file_get_contents( return file_get_contents(
base_path('tests/Feature/PdfMaker/designs/modern.html') base_path('tests/Feature/PdfMaker/example-design.html')
); );
} }
} }

View File

@ -1,13 +0,0 @@
<?php
namespace Tests\Feature\PdfMaker;
class Hipster
{
public function html()
{
return file_get_contents(
base_path('tests/Feature/PdfMaker/designs/hipster.html')
);
}
}

View File

@ -2,6 +2,16 @@
namespace Tests\Feature\PdfMaker; namespace Tests\Feature\PdfMaker;
use App\Services\PdfMaker\Designs\Bold;
use App\Services\PdfMaker\Designs\Business;
use App\Services\PdfMaker\Designs\Clean;
use App\Services\PdfMaker\Designs\Creative;
use App\Services\PdfMaker\Designs\Elegant;
use App\Services\PdfMaker\Designs\Hipster;
use App\Services\PdfMaker\Designs\Modern;
use App\Services\PdfMaker\Designs\Plain;
use App\Services\PdfMaker\Designs\Playful;
use App\Services\PdfMaker\PdfMaker;
use Tests\TestCase; use Tests\TestCase;
class PdfMakerDesignsTest extends TestCase class PdfMakerDesignsTest extends TestCase
@ -245,8 +255,7 @@ class PdfMakerDesignsTest extends TestCase
info($maker->getCompiledHTML(true)); info($maker->getCompiledHTML(true));
$this->assertTrue(true); $this->assertTrue(true);
} }
public function testModern() public function testModern()
@ -361,8 +370,7 @@ class PdfMakerDesignsTest extends TestCase
info($maker->getCompiledHTML(true)); info($maker->getCompiledHTML(true));
$this->assertTrue(true); $this->assertTrue(true);
} }
@ -478,8 +486,7 @@ class PdfMakerDesignsTest extends TestCase
info($maker->getCompiledHTML(true)); info($maker->getCompiledHTML(true));
$this->assertTrue(true); $this->assertTrue(true);
} }
public function testPlain() public function testPlain()
@ -586,8 +593,7 @@ class PdfMakerDesignsTest extends TestCase
info($maker->getCompiledHTML(true)); info($maker->getCompiledHTML(true));
$this->assertTrue(true); $this->assertTrue(true);
} }
public function testHipster() public function testHipster()
@ -698,8 +704,7 @@ class PdfMakerDesignsTest extends TestCase
info($maker->getCompiledHTML(true)); info($maker->getCompiledHTML(true));
$this->assertTrue(true); $this->assertTrue(true);
} }
public function testElegant() public function testElegant()
@ -814,8 +819,7 @@ class PdfMakerDesignsTest extends TestCase
info($maker->getCompiledHTML(true)); info($maker->getCompiledHTML(true));
$this->assertTrue(true); $this->assertTrue(true);
} }
public function testCreative() public function testCreative()
@ -930,8 +934,7 @@ class PdfMakerDesignsTest extends TestCase
info($maker->getCompiledHTML(true)); info($maker->getCompiledHTML(true));
$this->assertTrue(true); $this->assertTrue(true);
} }
public function testPlayful() public function testPlayful()
@ -1039,8 +1042,6 @@ class PdfMakerDesignsTest extends TestCase
info($maker->getCompiledHTML(true)); info($maker->getCompiledHTML(true));
$this->assertTrue(true);
$this->assertTrue(true);
} }
} }

View File

@ -2,6 +2,7 @@
namespace Tests\Feature\PdfMaker; namespace Tests\Feature\PdfMaker;
use App\Services\PdfMaker\PdfMaker;
use Spatie\Browsershot\Browsershot; use Spatie\Browsershot\Browsershot;
use Tests\TestCase; use Tests\TestCase;
@ -12,18 +13,13 @@ class PdfMakerTest extends TestCase
'variables' => [], 'variables' => [],
]; ];
public function setUp() :void
{
$this->markTestSkipped();
}
public function testDesignLoadsCorrectly() public function testDesignLoadsCorrectly()
{ {
$maker = new PdfMaker($this->state); $maker = new PdfMaker($this->state);
$maker->design(Business::class); $maker->design(ExampleDesign::class);
$this->assertInstanceOf(Business::class, $maker->design); $this->assertInstanceOf(ExampleDesign::class, $maker->design);
} }
public function testHtmlDesignLoadsCorrectly() public function testHtmlDesignLoadsCorrectly()
@ -31,7 +27,7 @@ class PdfMakerTest extends TestCase
$maker = new PdfMaker($this->state); $maker = new PdfMaker($this->state);
$maker $maker
->design(Business::class) ->design(ExampleDesign::class)
->build(); ->build();
$this->assertStringContainsString('<!-- Business -->', $maker->getCompiledHTML()); $this->assertStringContainsString('<!-- Business -->', $maker->getCompiledHTML());
@ -42,7 +38,7 @@ class PdfMakerTest extends TestCase
$maker = new PdfMaker($this->state); $maker = new PdfMaker($this->state);
$maker $maker
->design(Business::class) ->design(ExampleDesign::class)
->build(); ->build();
$this->assertEquals('table', $maker->getSectionNode('product-table')->nodeName); $this->assertEquals('table', $maker->getSectionNode('product-table')->nodeName);
@ -73,7 +69,7 @@ class PdfMakerTest extends TestCase
$maker = new PdfMaker($state); $maker = new PdfMaker($state);
$maker $maker
->design(Business::class) ->design(ExampleDesign::class)
->build(); ->build();
$this->assertStringContainsString('my-awesome-class', $maker->getSection('product-table', 'class')); $this->assertStringContainsString('my-awesome-class', $maker->getSection('product-table', 'class'));
@ -108,7 +104,7 @@ class PdfMakerTest extends TestCase
$maker = new PdfMaker($state); $maker = new PdfMaker($state);
$maker $maker
->design(Business::class) ->design(ExampleDesign::class)
->build(); ->build();
$this->assertStringContainsString('Invoice Ninja', $maker->getCompiledHTML()); $this->assertStringContainsString('Invoice Ninja', $maker->getCompiledHTML());
@ -152,7 +148,7 @@ class PdfMakerTest extends TestCase
$maker = new PdfMaker($state); $maker = new PdfMaker($state);
$maker $maker
->design(Business::class) ->design(ExampleDesign::class)
->build(); ->build();
$compiled = 'contact@invoiceninja.com'; $compiled = 'contact@invoiceninja.com';
@ -172,7 +168,7 @@ class PdfMakerTest extends TestCase
]); ]);
$maker1 $maker1
->design(Business::class) ->design(ExampleDesign::class)
->build(); ->build();
$output1 = $maker1->getCompiledHTML(); $output1 = $maker1->getCompiledHTML();
@ -189,7 +185,7 @@ class PdfMakerTest extends TestCase
]); ]);
$maker2 $maker2
->design(Business::class) ->design(ExampleDesign::class)
->build(); ->build();
$output2 = $maker2->getCompiledHTML(); $output2 = $maker2->getCompiledHTML();
@ -215,7 +211,7 @@ class PdfMakerTest extends TestCase
]); ]);
$maker $maker
->design(Business::class) ->design(ExampleDesign::class)
->build(); ->build();
$node = $maker->getSectionNode('header'); $node = $maker->getSectionNode('header');
@ -242,7 +238,7 @@ class PdfMakerTest extends TestCase
]); ]);
$maker $maker
->design(Business::class) ->design(ExampleDesign::class)
->build(); ->build();
$node = $maker->getSectionNode('header'); $node = $maker->getSectionNode('header');
@ -306,11 +302,9 @@ class PdfMakerTest extends TestCase
$maker = new PdfMaker($state); $maker = new PdfMaker($state);
$maker $maker
->design(Business::class) ->design(ExampleDesign::class)
->build(); ->build();
info($maker->getCompiledHTML());
$this->assertTrue(true); $this->assertTrue(true);
} }
} }

View File

@ -1,13 +0,0 @@
<?php
namespace Tests\Feature\PdfMaker;
class Plain
{
public function html()
{
return file_get_contents(
base_path('tests/Feature/PdfMaker/designs/plain.html')
);
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace Tests\Feature\PdfMaker;
class Playful
{
public function html()
{
return file_get_contents(
base_path('tests/Feature/PdfMaker/designs/playful.html')
);
}
}