<commit_before><?php

namespace Brera\PoC\Tests\Integration;

require __DIR__ . '/stubs/SkuStub.php';

use Brera\PoC\Integration\stubs\SkuStub,
    Brera\Poc\Product\ProductId,
    Brera\PoC\PoCMasterFactory,
    Brera\PoC\IntegrationTestFactory,
    Brera\PoC\ProductCreatedDomainEvent,
    Brera\PoC\Http\HttpUrl,
    Brera\PoC\Http\HttpRequest,
    Brera\Poc\FrontendFactory,
    Brera\PoC\PoCShop;

/**
 * Class EdgeToEdgeTest
 * @package Brera\PoC
 */
class EdgeToEdgeTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @test
     */
    public function createProductDomainEventShouldRenderAProduct()
    {
        $sku = new SkuStub('test');
        $productId = ProductId::fromSku($sku);
        $productName = 'test product name';

        
        // TODO refactor and create application for backend
        $factory = new PoCMasterFactory();
        $factory->register(new IntegrationTestFactory());

        $repository = $factory->getProductRepository();
        $repository->createProduct($productId, $productName);

        $queue = $factory->getEventQueue();
        $queue->add(new ProductCreatedDomainEvent($productId));

        $consumer = $factory->createDomainEventConsumer();
        $consumer->process(1);

        $reader = $factory->createDataPoolReader();
        $html = $reader->getPoCProductHtml($productId);

        $this->assertContains((string)$sku, $html);
        $this->assertContains($productName, $html);
    }

    /**
     * @test
     */
    public function pageRequestShouldDisplayAProduct()
    {
        $html = '<p>some html</p>';

        $httpUrl = HttpUrl::fromString('http://example.com/seo-url');
        $request = HttpRequest::fromParameters('GET', $httpUrl);

        $sku = new SkuStub('test');
        $productId = ProductId::fromSku($sku);

        $factory = new PoCMasterFactory();
        $factory->register(new FrontendFactory());
        $factory->register(new IntegrationTestFactory());

        $dataPoolWriter = $factory->createDataPoolWriter();
        $dataPoolWriter->setProductIdBySeoUrl($productId, $httpUrl);
        $dataPoolWriter->setPoCProductHtml($productId, $html);

        $website = new PoCShop($request, $factory);
        $response = $website->run(false);
        
        $this->assertContains($html, $response->getBody());
    }
}<commit_msg>Issue #3: Add sketch of import process as EdgeToEdge test<commit_after><?php

namespace Brera\PoC\Tests\Integration;

require __DIR__ . '/stubs/SkuStub.php';

use Brera\PoC\Integration\stubs\SkuStub,
    Brera\Poc\Product\ProductId,
    Brera\PoC\PoCMasterFactory,
    Brera\PoC\IntegrationTestFactory,
    Brera\PoC\ProductCreatedDomainEvent,
    Brera\PoC\Http\HttpUrl,
    Brera\PoC\Http\HttpRequest,
    Brera\Poc\FrontendFactory,
    Brera\PoC\PoCShop;

/**
 * Class EdgeToEdgeTest
 * @package Brera\PoC
 */
class EdgeToEdgeTest extends \PHPUnit_Framework_TestCase
{
    public function importProductDomainEventShouldRenderAProduct()
    {
        $factory = new PoCMasterFactory();
        $factory->register(new IntegrationTestFactory());


        $sku = new SkuStub('118235-251');
        $productId = ProductId::fromSku($sku);
        $productName = 'LED Armflasher';
        
        $xml = '<product>
  <sku>118235-251</sku>
  <_type>simple</_type>
  <_category>Laufshop/Shop,Laufshop/Herren/Laufzubeh&ouml;r,Laufshop/Damen/Laufzubeh&ouml;r</_category>
  <description>Pro Touch LED Armflasher&lt;br /&gt;&#13;
&lt;br /&gt;&#13;
LED Armflasher mit elastischem Band und Flasher mit variabler Blinkfolge,&#13;
Flasher abnehmbar.&#13;</description>
  <name>LED Armflasher</name>
  <short_description>Pro Touch LED Armflasher Laufzubeh&ouml;r Leuchten Damen,Herren</short_description>
  <price>12.95</price>
  <tax_class_id>5</tax_class_id>
  <status>1</status>
  <weight>1.000</weight>
  <qty>5.00</qty>
  <is_in_stock>1</is_in_stock>
  <backorders>0</backorders>
  <image/>
  <image_label/>
  <small_image/>
  <small_image_label/>
  <thumbnail/>
  <thumbnail_label/>
  <_super_attribute_code/>
  <_super_attribute_option/>
  <_super_attribute_price_corr/>
  <brand>Pro Touch</brand>
  <series>LED Armflasher</series>
  <gender>Damen</gender>
  <product_group>Laufzubeh&ouml;r</product_group>
  <style>Leuchten</style>
  <size/>
  <base_price_amount/>
  <base_price_base_amount/>
  <base_price_base_unit/>
  <base_price_unit/>
  <price_retail>12.95</price_retail>
  <product_360/>
  <size_eu/>
  <yt_link/>
</product>';

        $queue = $factory->getEventQueue();
        $queue->add(new ProductImportDomainEvent($xml));

        $consumer = $factory->createDomainEventConsumer();
        $consumer->process(1);

        $reader = $factory->createDataPoolReader();
        $html = $reader->getPoCProductHtml($productId);

        $this->assertContains((string)$sku, $html);
        $this->assertContains($productName, $html);
    }

    /**
     * @test
     */
    public function createProductDomainEventShouldRenderAProduct()
    {
        $sku = new SkuStub('test');
        $productId = ProductId::fromSku($sku);
        $productName = 'test product name';


        // TODO refactor and create application for backend
        $factory = new PoCMasterFactory();
        $factory->register(new IntegrationTestFactory());

        $repository = $factory->getProductRepository();
        $repository->createProduct($productId, $productName);

        $queue = $factory->getEventQueue();
        $queue->add(new ProductCreatedDomainEvent($productId));

        $consumer = $factory->createDomainEventConsumer();
        $consumer->process(1);

        $reader = $factory->createDataPoolReader();
        $html = $reader->getPoCProductHtml($productId);

        $this->assertContains((string)$sku, $html);
        $this->assertContains($productName, $html);
    }

    /**
     * @test
     */
    public function pageRequestShouldDisplayAProduct()
    {
        $html = '<p>some html</p>';

        $httpUrl = HttpUrl::fromString('http://example.com/seo-url');
        $request = HttpRequest::fromParameters('GET', $httpUrl);

        $sku = new SkuStub('test');
        $productId = ProductId::fromSku($sku);

        $factory = new PoCMasterFactory();
        $factory->register(new FrontendFactory());
        $factory->register(new IntegrationTestFactory());

        $dataPoolWriter = $factory->createDataPoolWriter();
        $dataPoolWriter->setProductIdBySeoUrl($productId, $httpUrl);
        $dataPoolWriter->setPoCProductHtml($productId, $html);

        $website = new PoCShop($request, $factory);
        $response = $website->run(false);

        $this->assertContains($html, $response->getBody());
    }
}
{'fraction_non_alphanumeric': 0.1451951951951952, 'fraction_numerical': 0.007807807807807808, 'mean_word_length': 3.4171087533156497, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1542053', 'n_tokens_mistral': 2188, 'n_tokens_neox': 2114, 'n_words': 318}