<commit_before><?php

namespace Dotdigitalgroup\Email\Helper;

use Magento\TestFramework\ObjectManager;

/**
 * Class ApiEndpointTest
 *
 * @package Dotdigitalgroup\Email\Helper
 * @magentoDBIsolation enabled
 */
class ApiEndpointTest extends \PHPUnit_Framework_TestCase
{
    public function setup()
    {
        $this->removeData();
    }

    public function tearDown()
    {
        $this->removeData();
    }

    public function removeData()
    {
        /** @var ObjectManager $objectManager */
        $objectManager = ObjectManager::getInstance();

        /** @var \Magento\Config\Model\ResourceModel\Config $config */
        $config = $objectManager->create('Magento\Config\Model\ResourceModel\Config');
        $data = $this->dataProvider();

        foreach ($data as $item) {
            $config->deleteConfig(Config::PATH_FOR_API_ENDPOINT, $item[2], $item[0]);
        }
    }

    /**
     * @param $website
     * @param $endPoint
     *
     * @dataProvider dataProvider
     */
    public function test_fetching_api_endpoint_successful($website, $endPoint)
    {
        /** @var ObjectManager $objectManager */
        $objectManager = ObjectManager::getInstance();

        $property = new \stdClass();
        $property->name = 'ApiEndpoint';
        $property->value = $endPoint;

        $accountInfo = new \stdClass();
        $accountInfo->properties = [$property];

        $mockClient = $this->getMock(\Dotdigitalgroup\Email\Model\Apiconnector\Client::class, [], [], '', false);
        $mockClient->method('getAccountInfo')
            ->willReturn($accountInfo);

        $mockClientFactory = $this->getMock(\Dotdigitalgroup\Email\Model\Apiconnector\ClientFactory::class, [], [], '', false);
        $mockClientFactory->method('create')
            ->willReturn($mockClient);

        /** @var \Dotdigitalgroup\Email\Helper\Data $helper */
        $helper = new \Dotdigitalgroup\Email\Helper\Data(
            $objectManager->create('\Magento\Framework\App\ProductMetadata'),
            $objectManager->create('\Dotdigitalgroup\Email\Model\ContactFactory'),
            $objectManager->create('\Dotdigitalgroup\Email\Helper\File'),
            $objectManager->create('\Magento\Config\Model\ResourceModel\Config'),
            $objectManager->create('\Magento\Framework\App\ResourceConnection'),
            $objectManager->create('\Magento\Framework\App\Helper\Context'),
            $objectManager->create('\Magento\Store\Model\StoreManagerInterface'),
            $objectManager->create('\Magento\Customer\Model\CustomerFactory'),
            $objectManager->create('\Magento\Framework\Module\ModuleListInterface'),
            $objectManager->create('\Magento\Store\Model\Store'),
            $objectManager->create('\Magento\Framework\App\Config\Storage\Writer'),
            $mockClientFactory,
            $objectManager->create('\Dotdigitalgroup\Email\Helper\ConfigFactory'),
            $objectManager->create('\Dotdigitalgroup\Email\Model\Config\Json'),
            $objectManager->create('\Magento\Framework\Stdlib\DateTime\DateTime')
        );
        $apiEndpoint = $helper->getApiEndpoint($website, $mockClient);
        $this->assertEquals(
            $endPoint,
            $apiEndpoint
        );
    }

    /**
     *
     * @return array
     */
    public function dataProvider()
    {
        return [
            [
                0,
                'https://r1.dummy.com',
                'default'
            ],
            [
                1,
                'https://r1.dummy.com',
                'website'
            ]<commit_msg>fix failing test<commit_after><?php

namespace Dotdigitalgroup\Email\Helper;

use Magento\TestFramework\ObjectManager;

/**
 * Class ApiEndpointTest
 *
 * @package Dotdigitalgroup\Email\Helper
 * @magentoDBIsolation enabled
 */
class ApiEndpointTest extends \PHPUnit_Framework_TestCase
{
    public function setup()
    {
        $this->removeData();
    }

    public function tearDown()
    {
        $this->removeData();
    }

    public function removeData()
    {
        /** @var ObjectManager $objectManager */
        $objectManager = ObjectManager::getInstance();

        /** @var \Magento\Config\Model\ResourceModel\Config $config */
        $config = $objectManager->create('Magento\Config\Model\ResourceModel\Config');
        $data = $this->dataProvider();

        foreach ($data as $item) {
            $config->deleteConfig(Config::PATH_FOR_API_ENDPOINT, $item[2], $item[0]);
        }
    }

    /**
     * @param $website
     * @param $endPoint
     *
     * @dataProvider dataProvider
     */
    public function test_fetching_api_endpoint_successful($website, $endPoint)
    {
        /** @var ObjectManager $objectManager */
        $objectManager = ObjectManager::getInstance();

        $property = new \stdClass();
        $property->name = 'ApiEndpoint';
        $property->value = $endPoint;

        $accountInfo = new \stdClass();
        $accountInfo->properties = [$property];

        $mockClient = $this->getMock(\Dotdigitalgroup\Email\Model\Apiconnector\Client::class, [], [], '', false);
        $mockClient->method('getAccountInfo')
            ->willReturn($accountInfo);

        $mockClientFactory = $this->getMock(\Dotdigitalgroup\Email\Model\Apiconnector\ClientFactory::class, [], [], '', false);
        $mockClientFactory->method('create')
            ->willReturn($mockClient);

        /** @var \Dotdigitalgroup\Email\Helper\Data $helper */
        $helper = new \Dotdigitalgroup\Email\Helper\Data(
            $objectManager->create('\Magento\Framework\App\ProductMetadata'),
            $objectManager->create('\Dotdigitalgroup\Email\Model\ContactFactory'),
            $objectManager->create('\Dotdigitalgroup\Email\Helper\File'),
            $objectManager->create('\Magento\Config\Model\ResourceModel\Config'),
            $objectManager->create('\Magento\Framework\App\ResourceConnection'),
            $objectManager->create('\Magento\Framework\App\Helper\Context'),
            $objectManager->create('\Magento\Store\Model\StoreManagerInterface'),
            $objectManager->create('\Magento\Customer\Model\CustomerFactory'),
            $objectManager->create('\Magento\Framework\Module\ModuleListInterface'),
            $objectManager->create('\Magento\Store\Model\Store'),
            $objectManager->create('\Magento\Framework\App\Config\Storage\Writer'),
            $mockClientFactory,
            $objectManager->create('\Dotdigitalgroup\Email\Helper\ConfigFactory'),
            $objectManager->create('\Dotdigitalgroup\Email\Model\Config\Json'),
            $objectManager->create('\Magento\Framework\Stdlib\DateTime\DateTime'),
            $objectManager->create('\Magento\Quote\Model\QuoteFactory')
        );
        $apiEndpoint = $helper->getApiEndpoint($website, $mockClient);
        $this->assertEquals(
            $endPoint,
            $apiEndpoint
        );
    }

    /**
     *
     * @return array
     */
    public function dataProvider()
    {
        return [
            [
                0,
                'https://r1.dummy.com',
                'default'
            ],
            [
                1,
                'https://r1.dummy.com',
                'website'
            ]
{'fraction_non_alphanumeric': 0.1441937259218492, 'fraction_numerical': 0.001651073197578426, 'mean_word_length': 2.411074612857813, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 64, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4218432', 'n_tokens_mistral': 1949, 'n_tokens_neox': 1947, 'n_words': 245}