Skip to content
Snippets Groups Projects
Select Git revision
  • 7c13969056d1f5899f25e68107f8cd5278d89d21
  • master default protected
  • bugfix/wordpress-review
  • bugfix/prevent-error-notice
  • remove-arrow
  • feature/update-message
  • feature/minimum-plugin-version-check-demo1
  • feature/plugin-name
  • 3.7.1
  • 3.7.0
  • 3.6.3
  • 3.6.2
  • 3.6.1
  • 3.6.0
  • 3.6.0-beta3
  • 3.6.0-beta2
  • 3.6.0-beta1
  • 3.5.2
  • 3.5.1
  • 3.5.0
  • 3.4.0
  • 3.3.0
  • 3.2.8
  • 3.2.7
  • 3.2.6
  • 3.2.5
  • 3.2.4
  • 3.2.3
28 results

Basic_Requirement_Checker_With_Update_Disable.php

Blame
  • Shopify.php 3.55 KiB
    <?php
    
    namespace Octolize\Shopify\Codeception;
    
    use Codeception\Module\WebDriver;
    use Codeception\Util\Locator;
    use Exception;
    
    class Shopify extends WebDriver
    {
    
        public function loginAsAdmin(): void
        {
            $i    = $this;
            if ($i->loadSessionSnapshot('admin')) {
                $i->amOnUrl($this->config['admin_url']);
                return;
            }
            $i->amOnUrl($this->config['admin_url']);
            try {
                $this->amLoggedInAsAdmin($i);
            } catch (Exception $e) {
                try {
                    $i->wait(rand(1, 2));
                    $i->see('Choose an account');
                    $i->click($this->config['admin_username']);
                } catch (Exception $e) {
                    $this->loginWithGoogle($i);
                }
            }
            $i->wait(rand(1, 5));
            $i->saveSessionSnapshot('admin');
        }
    
        public function amOnPage($page): void
        {
            parent::amOnPage($page);
            $this->loginOnFront();
        }
    
        public function loginOnFront(): void
        {
            $i = $this;
            try {
                $i->seeInCurrentUrl('password');
                $i->fillField('password', $this->config['store_password']);
                $i->click('button[type=submit]');
            } catch (Exception $e) {
                // do nothing
            }
        }
    
        /**
         * @param Shopify $i
         *
         * @return void
         */
        private function amLoggedInAsAdmin(Shopify $i): void
        {
            $i->moveMouseOver('body', rand(1, 100), rand(1, 100));
            $i->seeInCurrentUrl(parse_url($this->config['admin_url'], PHP_URL_PATH));
        }
    
        /**
         * @param Shopify $i
         *
         * @return void
         * @throws Exception
         */
        private function loginWithGoogle(Shopify $i): void
        {
            $isPl = false;
            try {
                $i->waitForText('Continue with Google', 5);
            } catch (Exception $e) {
                $i->waitForText('Kontynuuj z Google', 5);
                $isPl = true;
            }
            $i->click($isPl ? 'Kontynuuj z Google' : 'Continue with Google');
            try {
                $i->seeInCurrentUrl(parse_url($this->config['admin_url'], PHP_URL_PATH));
                $i->dontSeeInCurrentUrl('google.com');
            } catch (Exception $e) {
                try {
                    $i->waitForText($this->config['admin_username']);
                    $i->clickWithLeftButton(Locator::find('div',
                        ['data-email' => $this->config['admin_username']]));
                    $i->seeInCurrentUrl(parse_url($this->config['admin_url'], PHP_URL_PATH));
                    $i->dontSeeInCurrentUrl('google.com');
                } catch (Exception $e) {
                    $this->loginToGoogle($i, $isPl);
                }
            }
        }
    
        /**
         * @param Shopify $i
         * @param bool $isPl
         *
         * @return void
         */
        private function loginToGoogle(Shopify $i, bool $isPl): void
        {
            $i->wait(rand(1, 5));
            $i->moveMouseOver('body', rand(1, 100), rand(1, 100));
            try {
                $i->seeElement('input[name="identifier"]');
                $i->fillField('identifier', $this->config['admin_username']);
                $i->click($isPl ? 'Dalej' : 'Next');
                $i->wait(rand(1, 5));
                $i->moveMouseOver('input[name=Passwd]', rand(1, 100), rand(1, 100));
                $i->fillField('Passwd', $this->config['google_password']);
                $i->click($isPl ? 'Dalej' : 'Next');
            } catch (Exception $e) {
                $i->wait(rand(1, 5));
                $i->moveMouseOver('body', rand(1, 100), rand(1, 100));
                $i->fillField('password', $this->config['google_password']);
                $i->click($isPl ? 'Dalej' : 'Next');
            }
        }
    
    }