<commit_before><?php
namespace Salesforce\Tests\Api\Bulk;

use Salesforce\Api\Bulk\Job;

class JobTest extends \PHPUnit_Framework_TestCase
{

    public function testShouldBeXmlEntity()
    {
        $job = new Job('Account');

        $this->assertInstanceOf('Salesforce\Api\Bulk\XmlEntity', $job);
        $this->assertInstanceOf('Salesforce\Api\Bulk\XmlSerializable', $job);
    }

    public function testShouldHaveToSetObjectOnConstructor()
    {
        $object = 'Account';
        $job = new Job($object);

        $this->assertEquals($object, $job->getObject());
    }

    /**
     * @dataProvider operationDataProvider
     */
    public function testShouldSetValidOperation($operation)
    {
        $job = new Job('Account');
        $job->setOperation($operation);

        $this->assertEquals($operation, $job->getOperation());
    }

    public function operationDataProvider()
    {
        return [
            [Job::OPERATION_INSERT],
            [Job::OPERATION_UPSERT],
        ];
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testShouldThrowsExceptionWithInvalidOperation()
    {
        $job = new Job('Account');
        $job->setOperation('foooooooo');
    }

    /**
     * @dataProvider jobStatesDataProvider
     */
    public function testShoulBeAbleToSetState($state)
    {
        $job = new Job('Account');
        $job->setState($state);

        $this->assertEquals($state, $job->getState());
    }

    public function jobStatesDataProvider()
    {
        return [
            ['Open'],
            ['Close'],
            ['Aborted'],
            ['Failed'],
        ];
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testShouldThrowsExceptionWithInvalidState()
    {
        $job = new Job('Account');
        $job->setState('SomeInvalidState');
    }

    /**
     * @dataProvider jobConcurrencyModeDataProvider
     */
    public function testShouldBeAbleToSetConcurrencyMode($concurrencyMode)
    {
        $job = new Job('Account');
        $job->setConcurrencyMode($concurrencyMode);

        $this->assertEquals($concurrencyMode, $job->getConcurrencyMode());
    }

    public function jobConcurrencyModeDataProvider()
    {
        return [
            [Job::CONCURRENCY_MODE_PARALLEL],
            [Job::CONCURRENCY_MODE_SERIAL],
        ];
    }

    public function testShouldHaveADefaultConcurrencyMode()
    {
        $job = new Job('Account');

        $this->assertNotEmpty($job->getConcurrencyMode());
    }

    public function testShoulBeAbleToSetContentType()
    {
        $job = new Job('Account');
        $job->setContentType(Job::CONTENT_TYPE_XML);

        $this->assertEquals(Job::CONTENT_TYPE_XML, $job->getContentType());
    }

    public function testShouldHaveADefaultContentType()
    {
        $job = new Job('Account');

        $this->assertNotEmpty($job->getContentType());
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testShouldThrowsExceptionWithInvalidContentType()
    {
        $job = new Job('Account');
        $job->setContentType('SomeInvalidContentType');
    }

    public function testBatchesShouldBeEmptyOnCreateAJob()
    {
        $job = new Job('Account');

        $this->assertEmpty($job->getBatches());
    }

    public function testShouldBeAbleToAddObject()
    {
        $account = $this->getObjectMock();
        $account->expects($this->once())
            ->method('getObjectType')
            ->willReturn('Account');

        $job = new Job('Account');
        $job->addObject($account);
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testShouldThrowsExceptionOnAddWrongObjectType()
    {
        $account = $this->getObjectMock();
        $account->expects($this->exactly(2))
            ->method('getObjectType')
            ->willReturn('Foo');

        $job = new Job('Account');
        $job->addObject($account);
    }

    public function testShouldHaveBatch()
    {
        $account = $this->getObjectMock();
        $account->expects($this->once())
            ->method('getObjectType')
            ->willReturn('Account');

        $job = new Job('Account');
        $job->addObject($account);

        $this->assertNotEmpty($job->getBatches());
    }

    public function testShouldGetAXMLString()
    {
        $job = new Job('Account');
        $xml = $job->asXML();

        $this->assertTrue(is_string($xml));
    }

    public function testShouldClearEmptyXMLAttributes()
    {
        $job = new Job('Account');
        $xml = $job->asXML();

        $expectedXml = '<?xml version="1.0"?>
                <jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload">
                    <operation>insert</operation>
                    <object>Account</object>
                    <concurrencyMode>Parallel</concurrencyMode>
                    <contentType>XML</contentType>
                </jobInfo>
        ';

        $this->assertXmlStringEqualsXmlString($expectedXml, $xml);
    }

    public function testShouldLoadDataFromXml()
    {
        $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><commit_msg>Update Bulk JobTest<commit_after><?php
namespace Salesforce\Tests\Api\Bulk;

use Salesforce\Api\Bulk\Job;

class JobTest extends \PHPUnit_Framework_TestCase
{

    public function testShouldBeXmlEntity()
    {
        $job = new Job('Account');

        $this->assertInstanceOf('Salesforce\Api\Bulk\XmlEntity', $job);
        $this->assertInstanceOf('Salesforce\Api\Bulk\XmlSerializable', $job);
    }

    public function testShouldHaveToSetObjectOnConstructor()
    {
        $object = 'Account';
        $job = new Job($object);

        $this->assertEquals($object, $job->getObject());
    }

    /**
     * @dataProvider operationDataProvider
     */
    public function testShouldSetValidOperation($operation)
    {
        $job = new Job('Account');
        $job->setOperation($operation);

        $this->assertEquals($operation, $job->getOperation());
    }

    public function operationDataProvider()
    {
        return [
            [Job::OPERATION_INSERT],
            [Job::OPERATION_UPSERT],
        ];
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testShouldThrowsExceptionWithInvalidOperation()
    {
        $job = new Job('Account');
        $job->setOperation('foooooooo');
    }

    /**
     * @dataProvider jobStatesDataProvider
     */
    public function testShoulBeAbleToSetState($state)
    {
        $job = new Job('Account');
        $job->setState($state);

        $this->assertEquals($state, $job->getState());
    }

    public function jobStatesDataProvider()
    {
        return [
            ['Open'],
            ['Close'],
            ['Aborted'],
            ['Failed'],
        ];
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testShouldThrowsExceptionWithInvalidState()
    {
        $job = new Job('Account');
        $job->setState('SomeInvalidState');
    }

    /**
     * @dataProvider jobConcurrencyModeDataProvider
     */
    public function testShouldBeAbleToSetConcurrencyMode($concurrencyMode)
    {
        $job = new Job('Account');
        $job->setConcurrencyMode($concurrencyMode);

        $this->assertEquals($concurrencyMode, $job->getConcurrencyMode());
    }

    public function jobConcurrencyModeDataProvider()
    {
        return [
            [Job::CONCURRENCY_MODE_PARALLEL],
            [Job::CONCURRENCY_MODE_SERIAL],
        ];
    }

    public function testShouldHaventADefaultConcurrencyMode()
    {
        $job = new Job('Account');

        $this->assertEmpty($job->getConcurrencyMode());
    }

    public function testShoulBeAbleToSetContentType()
    {
        $job = new Job('Account');
        $job->setContentType(Job::CONTENT_TYPE_XML);

        $this->assertEquals(Job::CONTENT_TYPE_XML, $job->getContentType());
    }

    public function testShouldHaveADefaultContentType()
    {
        $job = new Job('Account');

        $this->assertNotEmpty($job->getContentType());
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testShouldThrowsExceptionWithInvalidContentType()
    {
        $job = new Job('Account');
        $job->setContentType('SomeInvalidContentType');
    }

    public function testBatchesShouldBeEmptyOnCreateAJob()
    {
        $job = new Job('Account');

        $this->assertEmpty($job->getBatches());
    }

    public function testShouldBeAbleToAddObject()
    {
        $account = $this->getObjectMock();
        $account->expects($this->once())
            ->method('getObjectType')
            ->willReturn('Account');

        $job = new Job('Account');
        $job->addObject($account);
    }

    /**
     * @expectedException \InvalidArgumentException
     */
    public function testShouldThrowsExceptionOnAddWrongObjectType()
    {
        $account = $this->getObjectMock();
        $account->expects($this->exactly(2))
            ->method('getObjectType')
            ->willReturn('Foo');

        $job = new Job('Account');
        $job->addObject($account);
    }

    public function testShouldHaveBatch()
    {
        $account = $this->getObjectMock();
        $account->expects($this->once())
            ->method('getObjectType')
            ->willReturn('Account');

        $job = new Job('Account');
        $job->addObject($account);

        $this->assertNotEmpty($job->getBatches());
    }

    public function testShouldGetAXMLString()
    {
        $job = new Job('Account');
        $xml = $job->asXML();

        $this->assertTrue(is_string($xml));
    }

    public function testShouldClearEmptyXMLAttributes()
    {
        $job = new Job('Account');
        $xml = $job->asXML();

        $expectedXml = '<?xml version="1.0"?>
                <jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload">
                    <operation>insert</operation>
                    <object>Account</object>
                    <contentType>XML</contentType>
                </jobInfo>
        ';

        $this->assertXmlStringEqualsXmlString($expectedXml, $xml);
    }

    public function testShouldLoadDataFromXml()
    {
        $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>
{'fraction_non_alphanumeric': 0.13948806442335346, 'fraction_numerical': 0.0023008340523439745, 'mean_word_length': 2.419206817436906, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 4, '>': 123, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 2, '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': '7028524', 'n_tokens_mistral': 2979, 'n_tokens_neox': 2869, 'n_words': 430}