<commit_before><?php

namespace Shopify\Api\Tests;

class ClientTest extends \PHPUnit_Framework_TestCase
{

    public function setUp()
    {

        $this->shopName = 'mycoolshop';
        $this->clientSecret = '<KEY>';
        $this->permanentAccessToken = '0987654321';
        $this->shopUri = "https://{$this->shopName}.myshopify.com";

        $this->httpClient = $this->getMock('Shopify\HttpClient');

        $this->api = new \Shopify\Api\Client($this->httpClient);
        $this->api->setShopName($this->shopName);
        $this->api->setClientSecret($this->clientSecret);
        $this->api->setAccessToken($this->permanentAccessToken);

    }

    public function testGetRequest()
    {

        $this->assertEquals($this->shopUri, $this->api->getShopUri());

        $productUri = '/admin/product/632910392.json';
        $productResponse = $this->getProductResponse();
        $product = json_decode($productResponse);

        $this->httpClient->expects($this->once())
                         ->method('get')
                         ->with($this->shopUri . $productUri)
                         ->will($this->returnValue($productResponse));

        // retrieve a single product
        // @see http://docs.shopify.com/api/product#show
        $this->assertEquals($product, $this->api->get($productUri));

    }

    public function testPostRequest()
    {

        $ordersUri = '/admin/orders.json';
        $ordersRequest = $this->getOrdersRequest();
        $ordersResponse = $this->getOrdersResponse();
        $order = json_decode($ordersResponse);

        $this->httpClient->expects($this->once())
                         ->method('post')
                         ->with(
                            $this->shopUri . $ordersUri,
                            json_encode($ordersRequest)
                         )
                         ->will($this->returnValue($ordersResponse));

        // create a new order
        // @see http://docs.shopify.com/api/order#create
        $this->assertEquals($order, $this->api->post(
            $ordersUri, $ordersRequest
        ));

    }

    public function testRequestValidation()
    {

        $this->api->setClientSecret('hush');

        $signature = "31b9fcfbd98a3650b8523bcc92f8c5d2";

        // Assume we have the query parameters in a hash
        $params = array(
            'shop' => "some-shop.myshopify.com",
            'code' => "a94a110d86d2452eb3e2af4cfb8a3828",
            'timestamp' => "1337178173", // 2012-05-16 14:22:53
        );

        $this->assertEquals($signature, $this->api->generateSignature($params));

        $paramsWithSignature = $params;<commit_msg>adjust test for signature validation<commit_after><?php

namespace Shopify\Api\Tests;

class ClientTest extends \PHPUnit_Framework_TestCase
{

    public function setUp()
    {

        $this->shopName = 'mycoolshop';
        $this->clientSecret = '<KEY>';
        $this->permanentAccessToken = '0<PASSWORD>';
        $this->shopUri = "https://{$this->shopName}.myshopify.com";

        $this->httpClient = $this->getMock('Shopify\HttpClient');

        $this->api = new \Shopify\Api\Client($this->httpClient);
        $this->api->setShopName($this->shopName);
        $this->api->setClientSecret($this->clientSecret);
        $this->api->setAccessToken($this->permanentAccessToken);

    }

    public function testGetRequest()
    {

        $this->assertEquals($this->shopUri, $this->api->getShopUri());

        $productUri = '/admin/product/632910392.json';
        $productResponse = $this->getProductResponse();
        $product = json_decode($productResponse);

        $this->httpClient->expects($this->once())
                         ->method('get')
                         ->with($this->shopUri . $productUri)
                         ->will($this->returnValue($productResponse));

        // retrieve a single product
        // @see http://docs.shopify.com/api/product#show
        $this->assertEquals($product, $this->api->get($productUri));

    }

    public function testPostRequest()
    {

        $ordersUri = '/admin/orders.json';
        $ordersRequest = $this->getOrdersRequest();
        $ordersResponse = $this->getOrdersResponse();
        $order = json_decode($ordersResponse);

        $this->httpClient->expects($this->once())
                         ->method('post')
                         ->with(
                            $this->shopUri . $ordersUri,
                            json_encode($ordersRequest)
                         )
                         ->will($this->returnValue($ordersResponse));

        // create a new order
        // @see http://docs.shopify.com/api/order#create
        $this->assertEquals($order, $this->api->post(
            $ordersUri, $ordersRequest
        ));

    }

    public function testRequestValidation()
    {

        $this->api->setClientSecret('hush');

        $signature = "31b9fcfbd98a3650b8523bcc92f8c5d2";

        // Assume we have the query parameters in a hash
        $params = array(
            'shop' => "some-shop.myshopify.com",
            'code' => "a94a110d86d2452eb3e2af4cfb8a3828",
            'timestamp' => "1337178173", // 2012-05-16 14:22:53
            'signature' => $signature,
            'admin' => 1,
        );

        $this->assertEquals($signature, $this->api->generateSignature($params));

        $paramsWithSignature = $params;
{'fraction_non_alphanumeric': 0.15246719645167253, 'fraction_numerical': 0.02809092589170209, 'mean_word_length': 2.0978820835718373, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 118, 'https://': 2, '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': '5310474', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1497, 'n_words': 221}