Unverified Commit 49c9e214 authored by Pieter Frenssen's avatar Pieter Frenssen Committed by GitHub
Browse files

Merge pull request #51 from pfrenssen/support-d8-theme-info-files

Project names calculated incorrectly for themes
parents 0c76f8e9 ac9b3a8a
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ class Project
        $pathParts = pathinfo($phpcsFile->getFilename());
        // Module and install files are easy: they contain the project name in the
        // file name.
        if (isset($pathParts['extension']) === true && ($pathParts['extension'] === 'module' || $pathParts['extension'] === 'install')) {
        if (isset($pathParts['extension']) === true && in_array($pathParts['extension'], ['install', 'module', 'profile', 'theme']) === true) {
            $cache[$phpcsFile->getFilename()] = $pathParts['filename'];
            return $pathParts['filename'];
        }
@@ -56,8 +56,13 @@ class Project
        }

        $pathParts = pathinfo($infoFile);
        $cache[$phpcsFile->getFilename()] = $pathParts['filename'];
        return $pathParts['filename'];

        // Info files end in *.info.yml on Drupal 8 and *.info on Drupal 7.
        $filename = $pathParts['filename'];
        $filename = preg_replace('/\.info$/', '', $filename);

        $cache[$phpcsFile->getFilename()] = $filename;
        return $filename;

    }//end getName()

+65 −0
Original line number Diff line number Diff line
@@ -115,4 +115,69 @@ class ProjectUnitTest extends \PHPUnit_Framework_TestCase
    }//end coreVersionProvider()


    /**
     * Tests the extending classes Sniff class.
     *
     * @param string $filename    Name of the file that will be checked.
     * @param string $projectname Expected project name for the file.
     *
     * @dataProvider projectNameDetectionProvider
     *
     * @return void
     */
    public function testProjectNameDetection($filename, $projectname)
    {
        $this->phpcsFile->expects($this->any())
            ->method('getFilename')
            ->will($this->returnValue($filename));

        $this->assertEquals(Project::getName($this->phpcsFile), $projectname);

    }//end testProjectNameDetection()


    /**
     * Data provider for testProjectNameDetection().
     *
     * @return array
     *   An array of test cases, each test case an array with two elements:
     *   - The filename to check.
     *   - The expected project name.
     */
    public function projectNameDetectionProvider()
    {
        return [
            [
                __DIR__.'/drupal6/testmodule.info',
                'testmodule',
            ],
            [
                __DIR__.'/drupal6/nested/test.php',
                'testmodule',
            ],
            [
                __DIR__.'/drupal7/testmodule.info',
                'testmodule',
            ],
            [
                __DIR__.'/drupal8/testmodule.info.yml',
                'testmodule',
            ],
            [
                __DIR__.'/drupal8/testtheme/testtheme.info.yml',
                'testtheme',
            ],
            [
                __DIR__.'/drupal8/testtheme/testtheme.theme',
                'testtheme',
            ],
            [
                'invalid',
                false,
            ],
        ];

    }//end projectNameDetectionProvider()


}//end class
+5 −0
Original line number Diff line number Diff line
name: Test Theme
description: A test theme for the DrupalPractice standard.
package: Coder
type: theme
core: 8.x
+5 −0
Original line number Diff line number Diff line
<?php

/**
 * Main functions and hook implementations of the test theme.
 */