cvexa/finder

search in files by content or filename for Laravel

dev-master 2019-03-27 15:46 UTC

This package is auto-updated.

Last update: 2024-03-28 03:20:01 UTC


README

Search task
Searching in application root folder/folders in all files filtered by a page inputs, radio buttons and select

Getting Started

These instructions will get you a copy of the package on your machine for development and testing purposes.

Prerequisites

Laravel ^5.6*
orchestra/testbench-dusk ~3.4

Installing

download and install the package via composer

composer require cvexa/finder

if 'stability errors' run

composer require "cvexa/finder:dev-master"

if 'links are not supported error' run

php artisan storage:link

package will install orchestra/testbench-dusk package if not presented
if package its not installed previously run the following comand in order to run the tests later

php artisan dusk:install

publish package Tests

php artisan vendor:publish \\select Provider: cvexa\finder\FinderServiceProvider

searchTest.php will be copied to Tests\Browser;

Package routes

GET /cvexa/find

Description

Input for keyword/sentence validation for max:500 characters, this field is CASE SENSITIVE, and the search is CASE SENSITIVE
File extensions section validation for max:500 characters
extenstions can be listed with dot, or without (.pdf, pdf) are both valid,
more than one can be listed in the input separeted by a comma, for example:
pdf, .php, .txt, css ,etc.
extensions who are skipped on CONTENT search in files:
Microsoft Office files (for example ):

*.doc
*.docx
*.xls
*.ppt
*....

valid content searchable CONTENT files:

*.php
*.txt
*.js
*.css
*.xml
*.env
*.pdf
*.scss

file extension filed can be empty, in that case all files extensions will be included in the search (except, for content search skipped extensions)
NO restriction on files to search by file NAME;

Places 3 options
every option eliminate the other 2, and all options can be empty (except the select - default is all) if no option is changed(or left empty), the public folder select 'all' will be used to search in
1.Custom path application

denied permission for '/' and '/vendor', 'vendor' paths, this field is for searching in the root/ folders
of the laravel application
, for example '/app' will search in Laravel/app folder, /routes will search in Laravel/routes

2.Public Folder browser
with select can choose between all folders in the Laravel/public folder they will be listed, if all value is selected
will search in the whole public folder

3.Custom path outside the application folder (one level above)
search in all files and folders outside the application folder for example:
server/
  /folder1
   /folder1.1
   etc..
  /folder2
  /folder3
  /Laravel(with the package)
  /folder5
  file.txt
  etc..

Search Filter
determinate to search by a file Name or file Content (by default by Name)

Priority:
filter
extensions input
one of the 3 search path methods

Result box
will appear after every search to show time consumed doing the search, and listing the results if any
with the path to file where match is found

Searching will be performed also on all subfolders, provided by custom paths

Running the tests

note the application must be running while starting the tests ! dusk testing url is configured in .env file for example:

APP_URL=http://localhost:8000

more about Laravel Dusk

php artisan dusk

This command will run all dusk tests, of the application including now the package tests
if you want to see the tests in browser open : tests/DuskTestCase.php
and find this method

protected function driver()
    {
        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--window-size=1920,1080',
        ]);

        return RemoteWebDriver::create(
            'http://localhost:9515',
            DesiredCapabilities::chrome()->setCapability(
                ChromeOptions::CAPABILITY,
                $options
            )
        );
    }

comment '--headless', to open browser and see realtime browser test

protected function driver()
    {
        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            <!-- '--headless', -->
            '--window-size=1920,1080',
        ]);

        return RemoteWebDriver::create(
            'http://localhost:9515',
            DesiredCapabilities::chrome()->setCapability(
                ChromeOptions::CAPABILITY,
                $options
            )
        );
    }

Testing

first test will visit the package url :/cvexa/find and will wait for elements

$this->assertNotNull($browser->waitForText('Search in files'));
$this->assertNotNull($browser->element('#search'));
$this->assertNotNull($browser->element('#extensions'));
$this->assertNotNull($browser->element('#path'));
$this->assertNotNull($browser->element('#location'));
$this->assertNotNull($browser->element('#name'));
$this->assertNotNull($browser->element('#content'));

after that will click search button, and wait for validation errors

$this->assertNotNull($browser->element('.alert-danger'));

next thing is to search for 'Controller' in the public folder by file NAME, and wait for no result

$this->assertNotNull($browser->waitForText('No Results'));

next thing is to search for 'index' in the public folder by file NAME, and extension .php, waiting in result to present index.php

$this->assertNotNull($browser->waitForText('index.php'));

next search by content '$request = Illuminate\Http\Request::capture()'

$browser->type('#search', '$request = Illuminate\Http\Request::capture()');
$browser->radio('#content', '0');
$browser->click('#search-btn')
    ->pause(500);
$this->assertNotNull($browser->waitForText('index.php'));

after that are some tests for searching in:
web.php
api.php
app.css
app.js
and searching for 'Controller' by content and by filename in
/app/Http/Controllers/
and ending with validation tests for path to search for '/' and '/vendor' and 'vendor'
and waiting for error
assertions are 22 that must be successfull to pass the test.

Authors

  • Svetoslav Vasilev - GIT