<?php
/**
 * Plumrocket Inc.
 * NOTICE OF LICENSE
 * This source file is subject to the End-user License Agreement
 * that is available through the world-wide-web at this URL:
 * http://wiki.plumrocket.net/wiki/EULA
 * If you are unable to obtain it through the world-wide-web, please
 * send an email to support@plumrocket.com so we can send you a copy immediately.
 *
 * @package     Plumrocket Product Filter
 * @copyright   Copyright (c) 2018 Plumrocket Inc. (http://www.plumrocket.com)
 * @license     http://wiki.plumrocket.net/wiki/EULA  End-user License Agreement
 */

namespace Plumrocket\ProductFilter\Test\Unit\Model\Config\Source;

use PHPUnit\Framework\TestCase;
use Plumrocket\ProductFilter\Model\Config\Source\Inputs;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

class InputsTest extends TestCase
{
    /**
     * @var Inputs
     */
    private $model;

    protected function setUp()
    {
        $filterList = $this->createMock(\Plumrocket\ProductFilter\Model\FilterList::class);

        $this->model = (new ObjectManager($this))->getObject(
            Inputs::class,
            [
                'filterList' => $filterList
            ]
        );
    }

    /**
     * @dataProvider getAttributeListForComplexTest()
     * @param $source
     * @param $result
     */
    public function testToOptionArray($source, $result)
    {
        $filterList = $this->createMock(\Plumrocket\ProductFilter\Model\FilterList::class);
        $filterList->method('getAttributeList')->willReturn($source);

        /**
         * @var Inputs $model
         */
        $model = (new ObjectManager($this))->getObject(
            Inputs::class,
            [
                'filterList' => $filterList
            ]
        );

        $this->assertEquals($result, $model->toOptionArray(), 'Complex test failed');
    }

    /**
     * @dataProvider getAttributeListForFilter()
     * @param $source
     * @param $result
     */

    public function testFilterAttributeList($source, $result)
    {
        $this->assertEquals($result, $this->model->filterAttributeList($source));
    }

    /**
     * @dataProvider getAttributeListForFormat()
     * @param $source
     * @param $result
     */
    public function testFormatAttributes($source, $result)
    {
        $this->assertEquals($result, $this->model->formatAttributeList($source));
    }

    /**
     * @return array[]
     */
    public function getAttributeListForFilter()
    {
        return [
            [
                'source' => [
                    'activity'        => 'Activity',
                    'category_gear'   => 'Category Gear',
                    'erin_recommends' => 'Erin Recommends',
                    'color'           => 'Green',
                    'gender'          => 'Gender',
                ],
                'result' => [
                    'activity'        => 'Activity',
                    'category_gear'   => 'Category Gear',
                    'erin_recommends' => 'Erin Recommends',
                    'gender'          => 'Gender',
                ],
            ],
            [
                'source' => [
                    'color'           => 'Color',
                    'eco_collection'  => 'Eco Collection',
                    'erin_recommends' => 'Erin Recommends',
                    'strap_bags'      => 'Strap/Handle',
                ],
                'result' => [
                    'eco_collection'  => 'Eco Collection',
                    'erin_recommends' => 'Erin Recommends',
                    'strap_bags'      => 'Strap/Handle',
                ],
            ],
        ];
    }

    /**
     * @return array[]
     */
    public function getAttributeListForFormat()
    {
        return [
            [
                'source' => [
                    'activity'        => 'Activity',
                    'category_gear'   => 'Category Gear',
                    'erin_recommends' => 'Erin Recommends',
                    'format'          => 'Format',
                    'gender'          => 'Gender',
                ],
                'result'    => [
                    ['value' => 'activity', 'label' => 'Activity'],
                    ['value' => 'category_gear', 'label' => 'Category Gear'],
                    ['value' => 'erin_recommends', 'label' => 'Erin Recommends'],
                    ['value' => 'format', 'label' => 'Format'],
                    ['value' => 'gender', 'label' => 'Gender'],
                ],
            ],
            [
                'source' => [
                    'eco_collection'  => 'Eco Collection',
                    'erin_recommends' => 'Erin Recommends',
                    'strap_bags'      => 'Strap/Handle',

                ],
                'result'    => [
                    ['value' => 'eco_collection', 'label' => 'Eco Collection'],
                    ['value' => 'erin_recommends', 'label' => 'Erin Recommends'],
                    ['value' => 'strap_bags', 'label' => 'Strap/Handle'],
                ],
            ],
        ];
    }

    /**
     * @return array[]
     */
    public function getAttributeListForComplexTest()
    {
        return [
            [
                'source' => [
                    'activity'        => 'Activity',
                    'category_gear'   => 'Category Gear',
                    'erin_recommends' => 'Erin Recommends',
                    'color'           => 'Green',
                    'gender'          => 'Gender',
                ],
                'result' => [
                    ['value' => 'activity', 'label' => 'Activity'],
                    ['value' => 'category_gear', 'label' => 'Category Gear'],
                    ['value' => 'erin_recommends', 'label' => 'Erin Recommends'],
                    ['value' => 'gender', 'label' => 'Gender'],
                ],
            ],
            [
                'source' => [
                    'eco_collection'  => 'Eco Collection',
                    'price'           => 'Price',
                    'erin_recommends' => 'Erin Recommends',
                    'strap_bags'      => 'Strap/Handle',
                ],
                'result' => [
                    ['value' => 'eco_collection', 'label' => 'Eco Collection'],
                    ['value' => 'erin_recommends', 'label' => 'Erin Recommends'],
                    ['value' => 'strap_bags', 'label' => 'Strap/Handle'],
                ],
            ],
            [
                'source' => [],
                'result' => [],
            ],
        ];
    }
}
