<commit_before><?php
/**
 * @package     Mautic
 * @copyright   2014 Mautic, NP. All rights reserved.
 * @author      Mautic
 * @link        http://mautic.org
 * @license     MIT http://opensource.org/licenses/MIT
 */

namespace Mautic\Tests\Api;

class LeadsTest extends MauticApiTestCase
{
    protected $testPayload = array(
        'firstname' => 'test',
        'lastname'  => 'test'
    );

    protected $context = 'leads';

    protected $itemName = 'contact';

    public function testGetList()
    {
        $apiContext  = $this->getContext($this->context);
        $response = $apiContext->getList();
        $this->assertErrors($response);
    }

    public function testGetFieldList()
    {
        $apiContext  = $this->getContext($this->context);
        $response = $apiContext->getFieldList();
        $this->assertErrors($response);
    }

    public function testGetListList()
    {
        $apiContext  = $this->getContext($this->context);
        $response = $apiContext->getLists();
        $this->assertErrors($response);
    }

    public function testGetNotes()
    {
        $apiContext  = $this->getContext($this->context);
        $response = $apiContext->getLeadNotes(1);
        $this->assertErrors($response);
    }

    public function testGetLists()
    {
        $apiContext  = $this->getContext($this->context);
        $response = $apiContext->getLeadLists(1);
        $this->assertErrors($response);
    }

    public function testGetCampaigns()
    {
        $apiContext  = $this->getContext($this->context);
        $response = $apiContext->getLeadCampaigns(1);
        $this->assertErrors($response);
    }

    public function testCreateGetAndDelete()
    {
        $apiContext = $this->getContext($this->context);

        // Test Create
        $response = $apiContext->create($this->testPayload);
        $this->assertErrors($response);

        // Test Get
        $response = $apiContext->get($response[$this->itemName]['id']);
        $this->assertErrors($response);

        // Test Delete
        $response = $apiContext->delete($response[$this->itemName]['id']);
        $this->assertErrors($response);
    }

    public function testEditPatch()
    {
        $apiContext  = $this->getContext($this->context);
        $response = $apiContext->edit(10000, $this->testPayload);

        //there should be an error as the lead shouldn't exist
        $this->assertTrue(isset($response['error']), $response['error']['message']);

        $response = $apiContext->create($this->testPayload);
        $this->assertErrors($response);

        $response = $apiContext->edit(
            $response[$this->itemName]['id'],
            array(
                'firstname' => 'test2',
                'lastname'  => 'test2'
            )
        );

        $this->assertErrors($response);

        //now delete the lead
        $response = $apiContext->delete($response[$this->itemName]['id']);
        $this->assertErrors($response);
    }

    public function testEditPut()
    {
        $apiContext  = $this->getContext($this->context);
        $response = $apiContext->edit(10000, $this->testPayload, true);
        $this->assertErrors($response);

        //now delete the lead
        $response = $apiContext->delete($response[$this->itemName]['id']);
        $this->assertErrors($response);
    }
}<commit_msg>Use the same tests for legacy 'leads' as for 'contacts'<commit_after><?php
/**
 * @package     Mautic
 * @copyright   2014 Mautic, NP. All rights reserved.
 * @author      Mautic
 * @link        http://mautic.org
 * @license     MIT http://opensource.org/licenses/MIT
 */

namespace Mautic\Tests\Api;

class LeadsTest extends ContactsTest
{
    protected $context = 'leads';

    // Use the method from ContactsTest to test the 'leads' endpoint for BC
}
{'fraction_non_alphanumeric': 0.15414915966386555, 'fraction_numerical': 0.006039915966386555, 'mean_word_length': 2.6104265402843603, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 64, 'https://': 0, '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': '6779961', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1078, 'n_words': 207}