<commit_before><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace ZendTest\Validator;

use Zend\Config;
use Zend\Validator\CreditCard;

/**
 * @group      Zend_Validator
 */
class CreditCardTest extends \PHPUnit_Framework_TestCase
{
    public static function basicValues()
    {
        return array(
            array('4111111111111111', true),
            array('5404000000000001', true),
            array('374200000000004', true),
            array('4444555566667777', false),
            array('ABCDEF', false),
        );
    }

    /**
     * Ensures that the validator follows expected behavior
     *
     * @dataProvider basicValues
     */
    public function testBasic($input, $expected)
    {
        $validator      = new CreditCard();
        $this->assertEquals($expected, $validator->isValid($input));
    }

    /**
     * Ensures that getMessages() returns expected default value
     *
     * @return void
     */
    public function testGetMessages()
    {
        $validator = new CreditCard();
        $this->assertEquals(array(), $validator->getMessages());
    }

    /**
     * Ensures that get and setType works as expected
     *
     * @return void
     */
    public function testGetSetType()
    {
        $validator = new CreditCard();
        $this->assertEquals(11, count($validator->getType()));

        $validator->setType(CreditCard::MAESTRO);
        $this->assertEquals(array(CreditCard::MAESTRO), $validator->getType());

        $validator->setType(
            array(
                CreditCard::AMERICAN_EXPRESS,
                CreditCard::MAESTRO
            )
        );
        $this->assertEquals(
            array(
                CreditCard::AMERICAN_EXPRESS,
                CreditCard::MAESTRO
            ),
            $validator->getType()
        );

        $validator->addType(
            CreditCard::MASTERCARD
        );
        $this->assertEquals(
            array(
                CreditCard::AMERICAN_EXPRESS,
                CreditCard::MAESTRO,
                CreditCard::MASTERCARD
            ),
            $validator->getType()
        );
    }

    public static function visaValues()
    {
        return array(
            array('4111111111111111', true),
            array('5404000000000001', false),
            array('374200000000004', false),
            array('4444555566667777', false),
            array('ABCDEF', false),
        );
    }

    /**
     * Test specific provider
     *
     * @dataProvider visaValues
     */
    public function testProvider($input, $expected)
    {
        $validator      = new CreditCard(CreditCard::VISA);
        $this->assertEquals($expected, $validator->isValid($input));
    }

    /**
     * Test non string input
     *
     * @return void
     */
    public function testIsValidWithNonString()
    {
        $validator = new CreditCard(CreditCard::VISA);
        $this->assertFalse($validator->isValid(array('something')));
    }

    public static function serviceValues()
    {
        return array(
            array('4111111111111111', false),
            array('5404000000000001', false),
            array('374200000000004', false),
            array('4444555566667777', false),
            array('ABCDEF', false),
        );
    }

    /**
     * Test service class with invalid validation
     *
     * @dataProvider serviceValues
     */
    public function testServiceClass($input, $expected)
    {
        $validator = new CreditCard();
        $this->assertEquals(null, $validator->getService());
        $validator->setService(array('ZendTest\Validator\CreditCardTest', 'staticCallback'));
        $this->assertEquals($expected, $validator->isValid($input));
    }

    public static function optionsValues()
    {
        return array(
            array('4111111111111111', false),
            array('5404000000000001', false),
            array('374200000000004', false),
            array('4444555566667777', false),
            array('ABCDEF', false),
        );
    }

    /**
     * Test non string input
     *
     * @dataProvider optionsValues
     */
    public function testConstructionWithOptions($input, $expected)
    {
        $validator = new CreditCard(
            array(
                'type' => CreditCard::VISA,
                'service' => array('ZendTest\Validator\CreditCardTest', 'staticCallback')
            )
        );

        $this->assertEquals($expected, $validator->isValid($input));
    }

    public function jcbValues()
    {
        return array(
            array('3566003566003566', true),
            array('3528000000000007', true),
            array('3528000000000007', true),
            array('3528000000000007', true),
            array('3088185545477406', false),
            array('3158854390756173', false),
            array('3088936920428541', false),
            array('213193692042852', true),
            array('180012362524156', true),
        );
    }

    /**<commit_msg>zendframework/zf2#6927 zendframework/zf2#6278 - adding missing docblock<commit_after><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.<EMAIL>)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace ZendTest\Validator;

use Zend\Config;
use Zend\Validator\CreditCard;

/**
 * @group      Zend_Validator
 */
class CreditCardTest extends \PHPUnit_Framework_TestCase
{
    public static function basicValues()
    {
        return array(
            array('4111111111111111', true),
            array('5404000000000001', true),
            array('374200000000004', true),
            array('4444555566667777', false),
            array('ABCDEF', false),
        );
    }

    /**
     * Ensures that the validator follows expected behavior
     *
     * @dataProvider basicValues
     */
    public function testBasic($input, $expected)
    {
        $validator      = new CreditCard();
        $this->assertEquals($expected, $validator->isValid($input));
    }

    /**
     * Ensures that getMessages() returns expected default value
     *
     * @return void
     */
    public function testGetMessages()
    {
        $validator = new CreditCard();
        $this->assertEquals(array(), $validator->getMessages());
    }

    /**
     * Ensures that get and setType works as expected
     *
     * @return void
     */
    public function testGetSetType()
    {
        $validator = new CreditCard();
        $this->assertEquals(11, count($validator->getType()));

        $validator->setType(CreditCard::MAESTRO);
        $this->assertEquals(array(CreditCard::MAESTRO), $validator->getType());

        $validator->setType(
            array(
                CreditCard::AMERICAN_EXPRESS,
                CreditCard::MAESTRO
            )
        );
        $this->assertEquals(
            array(
                CreditCard::AMERICAN_EXPRESS,
                CreditCard::MAESTRO
            ),
            $validator->getType()
        );

        $validator->addType(
            CreditCard::MASTERCARD
        );
        $this->assertEquals(
            array(
                CreditCard::AMERICAN_EXPRESS,
                CreditCard::MAESTRO,
                CreditCard::MASTERCARD
            ),
            $validator->getType()
        );
    }

    public static function visaValues()
    {
        return array(
            array('4111111111111111', true),
            array('5404000000000001', false),
            array('374200000000004', false),
            array('4444555566667777', false),
            array('ABCDEF', false),
        );
    }

    /**
     * Test specific provider
     *
     * @dataProvider visaValues
     */
    public function testProvider($input, $expected)
    {
        $validator      = new CreditCard(CreditCard::VISA);
        $this->assertEquals($expected, $validator->isValid($input));
    }

    /**
     * Test non string input
     *
     * @return void
     */
    public function testIsValidWithNonString()
    {
        $validator = new CreditCard(CreditCard::VISA);
        $this->assertFalse($validator->isValid(array('something')));
    }

    public static function serviceValues()
    {
        return array(
            array('4111111111111111', false),
            array('5404000000000001', false),
            array('374200000000004', false),
            array('4444555566667777', false),
            array('ABCDEF', false),
        );
    }

    /**
     * Test service class with invalid validation
     *
     * @dataProvider serviceValues
     */
    public function testServiceClass($input, $expected)
    {
        $validator = new CreditCard();
        $this->assertEquals(null, $validator->getService());
        $validator->setService(array('ZendTest\Validator\CreditCardTest', 'staticCallback'));
        $this->assertEquals($expected, $validator->isValid($input));
    }

    public static function optionsValues()
    {
        return array(
            array('4111111111111111', false),
            array('5404000000000001', false),
            array('374200000000004', false),
            array('4444555566667777', false),
            array('ABCDEF', false),
        );
    }

    /**
     * Test non string input
     *
     * @dataProvider optionsValues
     */
    public function testConstructionWithOptions($input, $expected)
    {
        $validator = new CreditCard(
            array(
                'type' => CreditCard::VISA,
                'service' => array('ZendTest\Validator\CreditCardTest', 'staticCallback')
            )
        );

        $this->assertEquals($expected, $validator->isValid($input));
    }

    /**
     * Data provider
     *
     * @return string[][]|bool[][]
     */
    public function jcbValues()
    {
        return array(
            array('3566003566003566', true),
            array('3528000000000007', true),
            array('3528000000000007', true),
            array('3528000000000007', true),
            array('3088185545477406', false),
            array('3158854390756173', false),
            array('3088936920428541', false),
            array('213193692042852', true),
            array('180012362524156', true),
        );
    }

    /**
{'fraction_non_alphanumeric': 0.12601243171972124, 'fraction_numerical': 0.0772273497833867, 'mean_word_length': 2.0470588235294116, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 30, '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': '4477136', 'n_tokens_mistral': 3441, 'n_tokens_neox': 2846, 'n_words': 540}